[#10500] update_users_me to graphql; added documentation for users/me update for both REST and graphql api (#10622)

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Wryn (yage) Wagner
2021-12-30 18:11:48 -07:00
committed by GitHub
parent 517c70b838
commit b9636e3243
3 changed files with 226 additions and 441 deletions

View File

@@ -1593,6 +1593,7 @@ export class GraphQLService {
{
CreateCollectionTypes,
ReadCollectionTypes,
UpdateCollectionTypes,
DeleteCollectionTypes,
}: {
CreateCollectionTypes: Record<string, ObjectTypeComposer<any, any>>;
@@ -2457,6 +2458,37 @@ export class GraphQLService {
});
}
if ('directus_users' in schema.update.collections) {
schemaComposer.Mutation.addFields({
update_users_me: {
type: ReadCollectionTypes['directus_users'],
args: {
data: toInputObjectType(UpdateCollectionTypes['directus_users']),
},
resolve: async (_, args, __, info) => {
if (!this.accountability?.user) return null;
const service = new UsersService({
schema: this.schema,
accountability: this.accountability,
});
await service.updateOne(this.accountability.user, args.data);
if ('directus_users' in ReadCollectionTypes) {
const selections = this.replaceFragmentsInSelections(
info.fieldNodes[0]?.selectionSet?.selections,
info.fragments
);
const query = this.getQuery(args, selections || [], info.variableValues);
return await service.readOne(this.accountability.user, query);
}
return true;
},
},
});
}
if ('directus_activity' in schema.create.collections) {
schemaComposer.Mutation.addFields({
create_comment: {