Skip to content

Instantly share code, notes, and snippets.

@jonirrings
Last active September 10, 2022 02:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonirrings/512613b1350bbd97974d7421d3b1b83e to your computer and use it in GitHub Desktop.
Save jonirrings/512613b1350bbd97974d7421d3b1b83e to your computer and use it in GitHub Desktop.
GraphQL Thunk example
const UserType = new GraphQLObjectType({
name: 'User',
description: 'a user',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLID),
description: 'user id',
},
name: {
type: new GraphQLNonNull(GraphQLString),
description: 'user name',
},
votes: {
type: new GraphQLList(VoteType),
description: 'user votes',
resolve: (user) => getVotesByUserId(user.id),
},
})
});
const VoteType = new GraphQLObjectType({
name: 'Vote',
description: 'a vote',
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLID),
description: 'vote id',
},
user: {
type: new GraphQLNonNull(UserType),
description: 'the voted user',
resolve: (vote) => getUserByVoteId(vote.id)
},
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment