Last active
September 10, 2022 02:16
-
-
Save jonirrings/512613b1350bbd97974d7421d3b1b83e to your computer and use it in GitHub Desktop.
GraphQL Thunk example
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 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