-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.js
38 lines (33 loc) · 979 Bytes
/
schema.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const graphql = require('graphql');
const _ = require('lodash');
const { GraphQLObjectType, GraphQLString, GraphQLSchema } = graphql;
// dummy data
var books = [
{ name: 'Name of the Wind', genre: 'Fantasy', id: '1' },
{ name: 'The Final Empire', genre: 'Fantasy', id: '2' },
{ name: 'The Long Earth', genre: 'Sci-Fi', id: '3' },
];
const BookType = new GraphQLObjectType({
name: 'Book',
fields: () => ({
id: { type: GraphQLString },
name: { type: GraphQLString },
genre: { type: GraphQLString }
})
});
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
book: {
type: BookType,
args: { id: { type: GraphQLString } },
resolve(parent, args) {
// code to get data from db / other source
return _.find(books, { id: args.id });
}
}
}
});
module.exports = new GraphQLSchema({
query: RootQuery
});