From cbf91f53e6c97cdb76c293c46813fbc9a74f47e5 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Mon, 12 Feb 2018 17:53:49 -0800 Subject: create user mutation --- mutations.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 mutations.js (limited to 'mutations.js') diff --git a/mutations.js b/mutations.js new file mode 100644 index 00000000..795c885a --- /dev/null +++ b/mutations.js @@ -0,0 +1,38 @@ +import { resolver, defaultArgs, defaultListArgs, attributeFields } from 'graphql-sequelize' +import { + graphql, + GraphQLSchema, + GraphQLObjectType, + GraphQLInputObjectType, + GraphQLString, + GraphQLInt, + GraphQLNonNull, + GraphQLList +} from 'graphql' + +module.exports = (db, gqltypes) => { + const UserInputType = new GraphQLInputObjectType({ + name: 'UserInput', + desc: 'UserInput', + fields: { + ...attributeFields(db['User'], { exclude: ['id'] }), + } + }) + + return new GraphQLObjectType({ + name: 'mutation', + fields: { + createUser: { + type: gqltypes['users'], + args: { + user: { + type: UserInputType + } + }, + resolve: async (root, { user }) => { + return db['User'].create(user) + } + }, + } + }) +} -- cgit v1.2.3