Created
January 15, 2018 13:36
-
-
Save anonymous/621c895799a7967b8e8f4567e1f625ea to your computer and use it in GitHub Desktop.
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 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