Skip to content

Instantly share code, notes, and snippets.

@gc-codesnippets
Created May 10, 2018 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gc-codesnippets/d696e122c578af0acaebbf64a58eef21 to your computer and use it in GitHub Desktop.
Save gc-codesnippets/d696e122c578af0acaebbf64a58eef21 to your computer and use it in GitHub Desktop.
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