Skip to content

Instantly share code, notes, and snippets.

Created January 15, 2018 13:36
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 anonymous/621c895799a7967b8e8f4567e1f625ea to your computer and use it in GitHub Desktop.
Save anonymous/621c895799a7967b8e8f4567e1f625ea to your computer and use it in GitHub Desktop.
const graphql = require('graphql')
const fruits = require('./fruits.json')
let vitaminsType = new graphql.GraphQLObjectType({
name: 'Vitamins',
fields: {
name: {
type: graphql.GraphQLString
},
}
})
let fruitType = new graphql.GraphQLObjectType({
name: 'Fruit',
fields: {
id: {
type: new graphql.GraphQLNonNull(graphql.GraphQLInt)
},
name: {
type: new graphql.GraphQLNonNull(graphql.GraphQLString)
},
color: {
type: graphql.GraphQLString
},
vitamins: {
type: new graphql.GraphQLList(vitaminsType)
}
}
})
let schema = new graphql.GraphQLSchema({
query: new graphql.GraphQLObjectType({
name: 'Query',
fields: {
fruit: {
type: fruitType,
args: {
id: {
type: graphql.GraphQLInt
}
},
resolve: function(_, args) {
let response = fruits.find(function(user) {
return (user.id === args.id)
})
return response
}
}
}
})
})
module.exports = schema
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment