-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathschema.graphql
374 lines (319 loc) · 7.78 KB
/
schema.graphql
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# **Don't delete** Comments at top of schemas should work
# See: https://github.com/dgraph-io/dgraph/issues/4227
type Hotel {
id: ID!
name: String! @search(by: [exact])
location: Point @search
area: Polygon @search
branches: MultiPolygon @search
}
type Country {
# **Don't delete** Comments in types should work
id: ID! # **Don't delete** Comments in lines should work
name: String! @search(by: [trigram, hash])
states: [State] @hasInverse(field: country) @dgraph(pred: "hasStates")
}
type State {
id: ID!
xcode: String! @id @search(by: [regexp])
name: String!
capital: String
region: Region
country: Country @dgraph(pred: "inCountry")
}
# **Don't delete** Comments in the middle of schemas should work
# Comments in input schemas should _not_ make it through to the
# generated schema.
"""
GraphQL descriptions look like this. They should work in the input
schema and should make their way into the generated schema.
"""
type Author @dgraph(type: "test.dgraph.author") {
id: ID!
"""
GraphQL descriptions can be on fields. They should work in the input
schema and should make their way into the generated schema.
"""
name: String! @search(by: [hash, trigram])
dob: DateTime @search
reputation: Float @search
qualification: String @search(by: [hash, trigram])
country: Country
posts: [Post!] @hasInverse(field: author)
bio: String @lambda
rank: Int @lambda
}
type Post @dgraph(type: "myPost") {
postID: ID!
title: String! @search(by: [term, fulltext])
text: String @search(by: [fulltext]) @dgraph(pred: "text")
tags: [String] @search(by: [exact])
topic: String @search(by: [exact]) @dgraph(pred: "test.dgraph.topic")
numLikes: Int @search
numViews: Int64 @search
isPublished: Boolean @search @dgraph(pred: "is_published")
postType: PostType @search(by: [hash, trigram])
author: Author! @hasInverse(field: posts) @dgraph(pred: "post.author")
category: Category @hasInverse(field: posts)
}
type Category {
id: ID
name: String
posts: [Post]
}
type User @secret(field: "password", pred:"pwd"){
name: String! @id
}
"""
GraphQL descriptions can be on enums. They should work in the input
schema and should make their way into the generated schema.
"""
enum PostType {
Fact
"""
GraphQL descriptions can be on enum values. They should work in the input
schema and should make their way into the generated schema.
"""
Question
Opinion
}
"""
GraphQL descriptions can be on interfaces. They should work in the input
schema and should make their way into the generated schema.
"""
interface Employee @dgraph(type: "test.dgraph.employee.en") {
ename: String!
}
interface Character @dgraph(type: "performance.character") {
id: ID!
name: String! @search(by: [exact])
appearsIn: [Episode!] @search @dgraph(pred: "appears_in")
bio: String @lambda
}
type Human implements Character & Employee {
id: ID!
name: String! @search(by: [exact])
appearsIn: [Episode!] @search
bio: String @lambda
ename: String!
starships: [Starship]
totalCredits: Float @dgraph(pred: "credits")
}
type Droid implements Character @dgraph(type: "roboDroid") {
id: ID!
name: String! @search(by: [exact])
appearsIn: [Episode!] @search
bio: String @lambda
primaryFunction: String
}
enum Episode {
NEWHOPE
EMPIRE
JEDI
}
type Starship @dgraph(type: "star.ship") {
id: ID!
name: String! @search(by: [term]) @dgraph(pred: "star.ship.name")
length: Float
}
type Movie {
id: ID!
name: String!
director: [MovieDirector] @dgraph(pred: "~directed.movies")
}
type MovieDirector {
id: ID!
name: String!
directed: [Movie] @dgraph(pred: "directed.movies")
}
interface People {
id: ID!
xid: String! @id
name: String!
}
type Teacher implements People {
subject: String
teaches: [Student]
}
type Student implements People {
taughtBy: [Teacher] @hasInverse(field: "teaches")
}
type Message @withSubscription {
content: String! @dgraph(pred: "post")
author: String @dgraph(pred: "<职业>")
}
"""
This is used for fragment related testing
"""
interface Thing {
name: String # field to act as a common inherited field for both ThingOne and ThingTwo
}
type ThingOne implements Thing {
id: ID! # ID field with same name as the ID field in ThingTwo
color: String # field with same name as a field in ThingTwo
usedBy: String # field with different name than any field in ThingTwo
}
type ThingTwo implements Thing {
id: ID!
color: String
owner: String
}
type Post1 {
id: String! @id
comments: [Comment1]
}
type Comment1 {
id: String! @id
replies: [Comment1]
}
type post1{
id: ID
title: String! @id @search(by: [regexp])
numLikes: Int64 @search
commentsByMonth: [Int]
likesByMonth: [Int64]
author: author1 @hasInverse(field: posts)
}
type Person1 {
id: ID!
name: String!
friends: [Person1] @hasInverse(field: friends)
}
# union testing - start
enum AnimalCategory {
Fish
Amphibian
Reptile
Bird
Mammal
InVertebrate
}
interface Animal {
id: ID!
category: AnimalCategory @search
}
type Dog implements Animal {
breed: String @search
}
type Parrot implements Animal {
repeatsWords: [String]
}
type Cheetah implements Animal {
speed: Float
}
"""
This type specifically doesn't implement any interface.
We need this to test out all cases with union.
"""
type Plant {
id: ID!
breed: String # field with same name as a field in type Dog
}
union HomeMember = Dog | Parrot | Human | Plant
type Zoo {
id: ID!
animals: [Animal]
city: String
}
type Home {
id: ID!
address: String
members: [HomeMember]
favouriteMember: HomeMember
}
# union testing - end
type Query {
authorsByName(name: String!): [Author] @lambda
}
type Mutation {
newAuthor(name: String!): ID! @lambda
}
# generate directive testing
type University @generate(
query: {
query: false
},
mutation: {
add: true,
update: true,
delete: false
}
){
id: ID!
name: String!
numStudents: Int
}
# @id directive with multiple data types
type Book {
bookId: Int64! @id
name: String!
desc: String
summary: String @lambda
chapters: [Chapter] @hasInverse(field: book)
}
type Chapter {
chapterId: Int! @id
name: String!
book: Book
}
type Section {
sectionId: Float! @id
name: String!
chapterId: Int! @search
}
type Mission @key(fields: "id") {
id: String! @id
crew: [Astronaut] @hasInverse(field: missions)
spaceShip: [SpaceShip]
designation: String!
startDate: String
endDate: String
}
type Astronaut @key(fields: "id") @extends {
id: ID! @external
missions: [Mission]
}
type SpaceShip @key(fields: "id") @extends {
id: String! @id @external
missions: [Mission]
}
type Region {
id: String! @id
name: String!
district: District
}
type District {
id: String! @id
name: String!
}
type Owner {
username: String! @id
password: String!
projects: [Project!] @hasInverse(field: owner)
}
type Project {
id: String! @id
owner: Owner!
name: String! @search(by: [hash])
datasets: [Dataset!] @hasInverse(field: project)
}
type Dataset {
id: String! @id
owner: Owner!
project: Project!
name: String! @search(by: [hash])
}
type author1{
name:String! @id @search(by: [regexp])
posts:[post1] @hasInverse(field: author)
}
# multiple fields with @id directive
type Worker {
name: String!
reg_No: Int! @id
emp_Id: String! @id
}
type Employer {
company: String! @id
worker: [Worker]
}