forked from baer/graphql-demo-evolution-of-api-design
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathschema.js
More file actions
54 lines (49 loc) · 1.29 KB
/
schema.js
File metadata and controls
54 lines (49 loc) · 1.29 KB
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
const {
GraphQLInt,
GraphQLList,
GraphQLObjectType,
GraphQLSchema,
GraphQLString
} = require("graphql");
const data = require("./data.js");
const Author = new GraphQLObjectType({
name: "Author",
description: "Author of article",
fields: {
id: {type: GraphQLInt},
name: {type: GraphQLString, description: "Name of author"},
company: {type: GraphQLString},
}
});
const Post = new GraphQLObjectType({
name: "Post",
description: "Articles in the blog",
fields: {
id: {type: GraphQLInt},
author: {
type: Author,
resolve: (subTree) => {
const author = subTree.author.split("/")[1];
return data.getAuthor(author);
}
},
categories: {type: new GraphQLList(GraphQLString)},
publishDate: {type: GraphQLString},
summary: {type: GraphQLString},
tags: {type: new GraphQLList(GraphQLString)},
title: {type: GraphQLString}
}
});
const Blog = new GraphQLObjectType({
name: "Blog",
description: "A website of fantastic content",
fields: {
posts: {
type: new GraphQLList(Post),
resolve: () => data.getPosts()
}
}
});
module.exports = new GraphQLSchema({
query: Blog
});