From 97a80db21e2416a304decece439422e5625b5ad0 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Thu, 6 Sep 2018 08:52:41 +0200 Subject: [PATCH] Update User Mutation Implemented and working --- client/src/queries/Test-Queries.js | 36 ++++++++++++++++++++++++++++++ server/schema/schema.js | 31 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 client/src/queries/Test-Queries.js diff --git a/client/src/queries/Test-Queries.js b/client/src/queries/Test-Queries.js new file mode 100644 index 000000000..98a0cfeb4 --- /dev/null +++ b/client/src/queries/Test-Queries.js @@ -0,0 +1,36 @@ +mutation { + addUser (alias: "aaa", firstName:"fff", lastName: "lll", roleId: "1", isTrader: 1, isDeveloper: 0) { + alias + isTrader + isDeveloper + } +} + + +mutation { + updateUser ( + id: "5b8d152f6f4d5b3db44ee103" , + alias: "luis", + firstName:"Luis", + lastName: "Molina", + isDeveloper: 1, + isTrader: 1, + isDataAnalyst: 1, + roleId: "2" + ) { + alias + } +} + +query { + + users{ + alias + firstName + isDeveloper + role{ + id + name + } + } +} diff --git a/server/schema/schema.js b/server/schema/schema.js index a1c7b5069..2e28453ca 100644 --- a/server/schema/schema.js +++ b/server/schema/schema.js @@ -119,6 +119,37 @@ const Mutation = new GraphQLObjectType({ }); return user.save(); } + }, + updateUser:{ + type: UserType, + args: { + id: {type: new GraphQLNonNull(GraphQLID)}, + alias: {type: new GraphQLNonNull(GraphQLString)}, + firstName: {type: GraphQLString}, + lastName: {type: GraphQLString}, + isDeveloper: {type: GraphQLInt}, + isTrader: {type: GraphQLInt}, + isDataAnalyst: {type: GraphQLInt}, + roleId: {type: new GraphQLNonNull(GraphQLString)} + }, + resolve(parent, args) { + + let key = { + _id: args.id + }; + + let updatedUser = { + alias: args.alias, + firstName: args.firstName, + lastName: args.lastName, + isDeveloper: args.isDeveloper, + isTrader: args.isTrader, + isDataAnalyst: args.isDataAnalyst, + roleId: args.roleId + }; + + return User.update(key, updatedUser); + } } } })