Skip to content

Instantly share code, notes, and snippets.

@kandros
Last active March 17, 2019 23:52
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 kandros/4528fa21d589f443620a1c1834616872 to your computer and use it in GitHub Desktop.
Save kandros/4528fa21d589f443620a1c1834616872 to your computer and use it in GitHub Desktop.
# somewhere in schema definition
type User {
name: String!
lastname: String!
fullname: String!
}
// somewhere in server code
const resolvers = {
Query: {
getUsers() {
return users
}
},
User: {
fullname: {
/**
* without this you are force to set in the query name and lastname everytime you request
* fullname, or it will not receive the value here and get undefined insted
*/
fragment: `... on User { name, lastname }`,
resolve: (parent, args, context, info ) {
return parent.name + return parent.lastname
}
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment