Created
May 10, 2018 09:23
-
-
Save gc-codesnippets/d696e122c578af0acaebbf64a58eef21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const userBinding = require('graphql-binding-users') | |
const generateName = require('sillyname') | |
const resolvers = { | |
Query: { | |
user: async (parent, args, context, info) => { | |
const users = await userBinding.query.users({}, info) | |
return users.find(user => user.id === args.id) | |
}, | |
}, | |
Mutation: { | |
createUserWithRandomName: (parent, args, context, info) => { | |
const sillyName = generateName() | |
return userBinding.mutation.createUser( | |
{ | |
name: sillyname, | |
}, | |
info, | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment