Skip to content

Instantly share code, notes, and snippets.

@dsomel21
Created February 27, 2018 03:09
Show Gist options
  • Save dsomel21/5ac97a4a0194a57a22ffb342bf5bda89 to your computer and use it in GitHub Desktop.
Save dsomel21/5ac97a4a0194a57a22ffb342bf5bda89 to your computer and use it in GitHub Desktop.
Having trouble getting up and running with GraphQL... Hmmm...
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