-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathschema.js
116 lines (107 loc) · 2.56 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import {
GraphQLObjectType,
GraphQLSchema,
GraphQLList,
GraphQLString,
GraphQLNonNull
} from 'graphql';
import {
GraphQLLimitedString
} from 'graphql-custom-types';
import { getPosts, getAuthor, getAuthors, getComments, createPost } from './dynamo';
const Author = new GraphQLObjectType({
name: "Author",
description: "Author of the blog post",
fields: () => ({
id: {type: GraphQLString},
name: {type: GraphQLString}
})
});
const Comment = new GraphQLObjectType({
name: "Comment",
description: "Comment on the blog post",
fields: () => ({
id: {type: GraphQLString},
content: {type: GraphQLString},
author: {
type: Author,
resolve: function({author}) {
return getAuthor(author);
}
}
})
});
const Post = new GraphQLObjectType({
name: "Post",
description: "Blog post content",
fields: () => ({
id: {type: GraphQLString},
title: {type: GraphQLString},
bodyContent: {type: GraphQLString},
author: {
type: Author,
resolve: function({author}) {
return getAuthor(author);
}
},
comments: {
type: new GraphQLList(Comment),
resolve: function(post) {
return getComments();
}
}
})
});
const Query = new GraphQLObjectType({
name: 'BlogSchema',
description: "Root of the Blog Schema",
fields: () => ({
posts: {
type: new GraphQLList(Post),
description: "List of posts in the blog",
resolve: function(source, {category}) {
return getPosts();
}
},
authors: {
type: new GraphQLList(Author),
description: "List of Authors",
resolve: function() {
return getAuthors();
}
},
author: {
type: Author,
description: "Get Author by id",
args: {
id: {type: new GraphQLNonNull(GraphQLString)}
},
resolve: function(source, {id}) {
return getAuthor(author);
}
}
})
});
const Mutuation = new GraphQLObjectType({
name: 'BlogMutations',
fields: {
createPost: {
type: Post,
description: "Create blog post",
args: {
id: {type: new GraphQLNonNull(GraphQLString)},
title: {type: new GraphQLLimitedString(10, 30)},
bodyContent: {type: new GraphQLNonNull(GraphQLString)},
author: {type: new GraphQLNonNull(GraphQLString), description: "Id of the author"}
},
resolve: function(source, args) {
return createPost(args);
}
}
}
});
const Schema = new GraphQLSchema({
query: Query,
mutation: Mutuation
});
export default Schema;