forked from graphql-kit/graphql-voyager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema.js
192 lines (180 loc) · 4.61 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/**
* Copyright (c) Facebook, Inc.
* All rights reserved.
*/
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLUnionType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLBoolean,
GraphQLInt,
GraphQLFloat,
GraphQLString,
GraphQLID,
GraphQLList,
} = require('graphql');
// Test Schema
const TestEnum = new GraphQLEnumType({
name: 'TestEnum',
values: {
RED: { description: 'A rosy color' },
GREEN: { description: 'The color of martians and slime' },
BLUE: { description: 'A feeling you might have if you can\'t use GraphQL' },
}
});
const TestInputObject = new GraphQLInputObjectType({
name: 'TestInput',
fields: () => ({
string: {
type: GraphQLString,
description: 'Repeats back this string'
},
int: { type: GraphQLInt },
float: { type: GraphQLFloat },
boolean: { type: GraphQLBoolean },
id: { type: GraphQLID },
enum: { type: TestEnum },
object: { type: TestInputObject },
// List
listString: { type: new GraphQLList(GraphQLString) },
listInt: { type: new GraphQLList(GraphQLInt) },
listFloat: { type: new GraphQLList(GraphQLFloat) },
listBoolean: { type: new GraphQLList(GraphQLBoolean) },
listID: { type: new GraphQLList(GraphQLID) },
listEnum: { type: new GraphQLList(TestEnum) },
listObject: { type: new GraphQLList(TestInputObject) },
})
});
const TestInterface = new GraphQLInterfaceType({
name: 'TestInterface',
description: 'Test interface.',
fields: () => ({
name: {
type: GraphQLString,
description: 'Common name string.'
}
}),
resolveType: check => {
return check ? UnionFirst : UnionSecond;
}
});
const UnionFirst = new GraphQLObjectType({
name: 'First',
fields: () => ({
name: {
type: GraphQLString,
description: 'Common name string for UnionFirst.'
},
first: {
type: new GraphQLList(TestInterface),
resolve: () => { return true; }
}
}),
interfaces: [ TestInterface ]
});
const UnionSecond = new GraphQLObjectType({
name: 'Second',
fields: () => ({
name: {
type: GraphQLString,
description: 'Common name string for UnionFirst.'
},
second: {
type: TestInterface,
resolve: () => { return false; }
}
}),
interfaces: [ TestInterface ]
});
const TestUnion = new GraphQLUnionType({
name: 'TestUnion',
types: [ UnionFirst, UnionSecond ],
resolveType() {
return UnionFirst;
}
});
const TestType = new GraphQLObjectType({
name: 'Test',
fields: () => ({
test: {
type: TestType,
description: '`test` field from `Test` type.',
resolve: () => ({})
},
union: {
type: TestUnion,
description: '> union field from Test type, block-quoted.',
resolve: () => ({})
},
id: {
type: GraphQLID,
description: 'id field from Test type.',
resolve: () => 'abc123',
},
isTest: {
type: GraphQLBoolean,
description: 'Is this a test schema? Sure it is.',
resolve: () => {
return true;
}
},
hasArgs: {
type: GraphQLString,
resolve(value, args) {
return JSON.stringify(args);
},
args: {
string: { type: GraphQLString },
int: { type: GraphQLInt },
float: { type: GraphQLFloat },
boolean: { type: GraphQLBoolean },
id: { type: GraphQLID },
enum: { type: TestEnum },
object: { type: TestInputObject },
// List
listString: { type: new GraphQLList(GraphQLString) },
listInt: { type: new GraphQLList(GraphQLInt) },
listFloat: { type: new GraphQLList(GraphQLFloat) },
listBoolean: { type: new GraphQLList(GraphQLBoolean) },
listID: { type: new GraphQLList(GraphQLID) },
listEnum: { type: new GraphQLList(TestEnum) },
listObject: { type: new GraphQLList(TestInputObject) },
}
},
})
});
const TestMutationType = new GraphQLObjectType({
name: 'MutationType',
description: 'This is a simple mutation type',
fields: {
setString: {
type: GraphQLString,
description: 'Set the string field',
args: {
value: { type: GraphQLString }
}
}
}
});
const TestSubscriptionType = new GraphQLObjectType({
name: 'SubscriptionType',
description: 'This is a simple subscription type',
fields: {
subscribeToTest: {
type: TestType,
description: 'Subscribe to the test type',
args: {
id: { type: GraphQLString }
}
}
}
});
const myTestSchema = new GraphQLSchema({
query: TestType,
mutation: TestMutationType,
subscription: TestSubscriptionType
});
module.exports = myTestSchema;