Created
February 27, 2018 03:09
-
-
Save dsomel21/5ac97a4a0194a57a22ffb342bf5bda89 to your computer and use it in GitHub Desktop.
Having trouble getting up and running with GraphQL... Hmmm...
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 graphql = require('graphql') | |
const _ = require('lodash') | |
// I don't really know what this does tho | |
const { | |
GraphQLObjectType, | |
GraphQLString, | |
GraphQLInt, | |
GraphQLSchema | |
} = graphql | |
const users = [ | |
{ id: '24', firstName: 'Kanye', age: 40 }, | |
{ id: '224', firstName: 'Dilraj', age: 20 } | |
] | |
const UserType = new GraphQLObjectType({ | |
name: 'User', | |
fields: { | |
id: { type: GraphQLString }, | |
firstName: { type: GraphQLString }, | |
age: { type: GraphQLInt } | |
} | |
}) | |
const RootQuery = new GraphQLObjectType({ | |
name: 'RootQueryType', | |
fields: { | |
user: { | |
type: UserType, args: { id: { type: GraphQLString } }, resolve(parentValue, args){ | |
return _.find(users, {id: args.id }) | |
} | |
} | |
} | |
}) | |
module.exports = new GraphQLSchema ({ | |
query: RootQuery, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment