-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathschema.js
43 lines (38 loc) · 938 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
39
40
41
42
43
const graphql = require( 'graphql' );
const {
GraphQLObjectType,
GraphQLString,
GraphQLSchema
} = graphql;
// Dummy Data
const posts = [
{ id: '1', title: 'Lord of the Rings', content: 'Awesome book' },
{ id: '2', title: 'Avengers', content: 'Awesome movie' },
{ id: '3', title: 'Harry Potter', content: 'Awesome book' },
];
// Define an object type called 'PostType'.
const PostType = new GraphQLObjectType({
name: 'Post',
fields: () => ({
id: { type: GraphQLString },
title: { type: GraphQLString },
content: { type: GraphQLString }
})
});
// Define RootQuery
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
post: {
type: PostType,
args: { id: { type: GraphQLString } },
resolve( parent, args ) {
// Get the data.
return posts.find( post => ( post.id === args.id ) );
}
}
}
});
module.exports = new GraphQLSchema({
query: RootQuery
}) ;