-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathdgraph_schemagen_test.yml
625 lines (595 loc) · 13 KB
/
dgraph_schemagen_test.yml
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
schemas:
-
name: "Object data type"
input: |
type A {
id: ID!
p: P
}
type P {
id: ID!
q: A
}
output: |
type A {
A.p
}
A.p: uid .
type P {
P.q
}
P.q: uid .
-
name: "Scalar list"
input: |
type X {
id: ID!
names: [String!]
}
output: |
type X {
X.names
}
X.names: [string] .
-
name: "Password type"
input: |
type X @secret(field: "pwd"){
id: ID!
names: [String!]
}
output: |
type X {
X.names
X.pwd
}
X.names: [string] .
X.pwd: password .
-
name: "Object list"
input: |
type X {
p: [P!]!
}
type P {
id: ID!
name: String
}
output: |
type X {
X.p
}
X.p: [uid] .
type P {
P.name
}
P.name: string .
-
name: "Scalar types"
input: |
type X {
p: Int
pList: [Int]
q: Boolean
r: String
rList: [String]
s: DateTime
sList: [DateTime]
t: Float
tList: [Float]
u: ID
v: Int64
vList: [Int64]
}
output: |
type X {
X.p
X.pList
X.q
X.r
X.rList
X.s
X.sList
X.t
X.tList
X.v
X.vList
}
X.p: int .
X.pList: [int] .
X.q: bool .
X.r: string .
X.rList: [string] .
X.s: dateTime .
X.sList: [dateTime] .
X.t: float .
X.tList: [float] .
X.v: int .
X.vList: [int] .
-
name: "enum - always gets an index"
input: |
type X {
e: E
f: [E]
}
enum E { A }
output: |
type X {
X.e
X.f
}
X.e: string @index(hash) .
X.f: [string] @index(hash) .
-
name: "Search indexes are correct"
input: |
type X {
i1: Int @search
i2: Int @search(by: [int])
i64_1: Int64 @search
i64_2: Int64 @search(by: [int64])
f1: Float @search
f2: Float @search(by: [float])
b1: Boolean @search
b2: Boolean @search(by: [bool])
s1: String @search
s2: String @search(by: [hash])
s3: String @search(by: [exact])
s4: String @search(by: [term])
s5: String @search(by: [fulltext])
s6: String @search(by: [trigram])
s7: String @search(by: [regexp])
s8: String @search(by: [exact, fulltext, term, trigram])
dt1: DateTime @search
dt2: DateTime @search(by: [year])
dt3: DateTime @search(by: [month])
dt4: DateTime @search(by: [day])
dt5: DateTime @search(by: [hour])
e: E @search
e1: E @search(by: [hash])
e2: E @search(by: [exact])
e3: E @search(by: [trigram])
e4: E @search(by: [regexp])
e5: E @search(by: [hash, regexp])
e6: E @search(by: [hash, trigram])
e7: E @search(by: [exact, regexp])
}
enum E { A }
output: |
type X {
X.i1
X.i2
X.i64_1
X.i64_2
X.f1
X.f2
X.b1
X.b2
X.s1
X.s2
X.s3
X.s4
X.s5
X.s6
X.s7
X.s8
X.dt1
X.dt2
X.dt3
X.dt4
X.dt5
X.e
X.e1
X.e2
X.e3
X.e4
X.e5
X.e6
X.e7
}
X.i1: int @index(int) .
X.i2: int @index(int) .
X.i64_1: int @index(int) .
X.i64_2: int @index(int) .
X.f1: float @index(float) .
X.f2: float @index(float) .
X.b1: bool @index(bool) .
X.b2: bool @index(bool) .
X.s1: string @index(term) .
X.s2: string @index(hash) .
X.s3: string @index(exact) .
X.s4: string @index(term) .
X.s5: string @index(fulltext) .
X.s6: string @index(trigram) .
X.s7: string @index(trigram) .
X.s8: string @index(exact, fulltext, term, trigram) .
X.dt1: dateTime @index(year) .
X.dt2: dateTime @index(year) .
X.dt3: dateTime @index(month) .
X.dt4: dateTime @index(day) .
X.dt5: dateTime @index(hour) .
X.e: string @index(hash) .
X.e1: string @index(hash) .
X.e2: string @index(exact) .
X.e3: string @index(trigram) .
X.e4: string @index(trigram) .
X.e5: string @index(hash, trigram) .
X.e6: string @index(hash, trigram) .
X.e7: string @index(exact, trigram) .
-
name: "interface and types interact properly"
input: |
interface A {
id: ID!
name: String! @search(by: [exact])
}
type B implements A {
correct: Boolean @search
}
type C implements A {
dob: DateTime!
}
output: |
type A {
A.name
}
A.name: string @index(exact) .
type B {
A.name
B.correct
}
B.correct: bool @index(bool) .
type C {
A.name
C.dob
}
C.dob: dateTime .
-
name: "interface using other interface generate type in dgraph"
input: |
interface A {
id: ID!
data: [D]
}
type C implements A {
lname: String
}
interface B {
name: String! @id
fname: String!
}
type D implements B {
link: A
correct: Boolean!
}
output: |
type A {
A.data
}
A.data: [uid] .
type C {
A.data
C.lname
}
C.lname: string .
type B {
B.name
B.fname
}
B.name: string @index(hash) @upsert .
B.fname: string .
type D {
B.name
B.fname
D.link
D.correct
}
D.link: uid .
D.correct: bool .
-
name: "Schema with @dgraph directive."
input: |
type A @dgraph(type: "dgraph.type.A") {
id: ID!
p: Int
pList: [Int] @dgraph(pred: "pList")
q: Boolean
r: String @dgraph(pred: "dgraph.r")
rList: [String]
s: DateTime @dgraph(pred: "s")
t: Float
tList: [Float] @dgraph(pred: "dgraph.tList")
}
interface B @dgraph(type: "dgraph.interface.B") {
id: ID!
name: String! @search(by: [exact]) @dgraph(pred: "dgraph.abc.name")
age: Int
}
type C implements B @dgraph(type: "type.C") {
correct: Boolean @search @dgraph(pred: "dgraph.correct")
incorrect: Boolean
}
type X @dgraph(type: "dgraph.type.X") {
e: E @dgraph(pred: "dgraph.x.e")
f: [E] @dgraph(pred: "dgraph.x.eList")
}
enum E { A }
type Y {
p: Int
q: String
pList: [Int] @dgraph(pred: "dgraph.pList")
f: Float @dgraph(pred: "f")
}
output: |
type dgraph.type.A {
dgraph.type.A.p
pList
dgraph.type.A.q
dgraph.r
dgraph.type.A.rList
s
dgraph.type.A.t
dgraph.tList
}
dgraph.type.A.p: int .
pList: [int] .
dgraph.type.A.q: bool .
dgraph.r: string .
dgraph.type.A.rList: [string] .
s: dateTime .
dgraph.type.A.t: float .
dgraph.tList: [float] .
type dgraph.interface.B {
dgraph.abc.name
dgraph.interface.B.age
}
dgraph.abc.name: string @index(exact) .
dgraph.interface.B.age: int .
type type.C {
dgraph.abc.name
dgraph.interface.B.age
dgraph.correct
type.C.incorrect
}
dgraph.correct: bool @index(bool) .
type.C.incorrect: bool .
type dgraph.type.X {
dgraph.x.e
dgraph.x.eList
}
dgraph.x.e: string @index(hash) .
dgraph.x.eList: [string] @index(hash) .
type Y {
Y.p
Y.q
dgraph.pList
f
}
Y.p: int .
Y.q: string .
dgraph.pList: [int] .
f: float .
-
name: "Field with @id directive but no search directive gets hash index."
input: |
interface A {
id: String! @id
}
type B implements A {
correct: Boolean @search
}
output: |
type A {
A.id
}
A.id: string @index(hash) @upsert .
type B {
A.id
B.correct
}
B.correct: bool @index(bool) .
-
name: "Field with @id directive gets hash index."
input: |
interface A {
id: String! @id @search(by: [trigram])
}
type B implements A {
correct: Boolean @search
}
output: |
type A {
A.id
}
A.id: string @index(hash, trigram) @upsert .
type B {
A.id
B.correct
}
B.correct: bool @index(bool) .
-
name: "Field with @id directive and a hash arg in search directive generates correct schema."
input: |
interface A {
id: String! @id @search(by: [hash, term])
}
type B implements A {
correct: Boolean @search
}
output: |
type A {
A.id
}
A.id: string @index(hash, term) @upsert .
type B {
A.id
B.correct
}
B.correct: bool @index(bool) .
-
name: "Field with reverse predicate in dgraph directive adds @reverse to predicate."
input: |
type Movie {
director: [Person] @dgraph(pred: "~directed.movies")
}
type Person {
directed: [Movie] @dgraph(pred: "directed.movies")
}
output: |
type Movie {
}
type Person {
directed.movies
}
directed.movies: [uid] @reverse .
-
name: "Field with reverse predicate in dgraph directive where actual predicate comes first."
input: |
type Person {
directed: [Movie] @dgraph(pred: "directed.movies")
}
type Movie {
director: [Person] @dgraph(pred: "~directed.movies")
}
output: |
type Person {
directed.movies
}
directed.movies: [uid] @reverse .
type Movie {
}
-
name: "deprecated fields get included in Dgraph schema"
input: |
type A {
id: ID!
p: String @deprecated
q: String @deprecated(reason: "just because it is")
}
output: |
type A {
A.p
A.q
}
A.p: string .
A.q: string .
- name: "remote types shouldn't be part of Dgraph schema"
input: |
type B {
id: ID!
q: String
}
interface C @remote{
c: String
}
type A implements C @remote {
id: ID!
p: String
q: String
}
output: |
type B {
B.q
}
B.q: string .
- name: "fields with same @dgraph(pred: ...) occur only once in schema"
input: |
interface A {
p: String @dgraph(pred: "key")
}
type B implements A {
q: String @dgraph(pred: "name")
}
type C {
r: String @dgraph(pred: "name")
s: String @dgraph(pred: "key")
name: String
}
output: |
type A {
key
}
key: string .
type B {
key
name
}
name: string .
type C {
name
key
C.name
}
C.name: string .
- name: "fields with same @dgraph(pred: ...) and different @search(by: [...]) have indexes
combined"
input: |
type A {
p: String @dgraph(pred: "name") @search(by: [exact, term])
}
type B {
q: String @dgraph(pred: "name") @search(by: [trigram])
}
type C {
q: String @dgraph(pred: "name") @search(by: [exact, term])
}
output: |
type A {
name
}
name: string @index(exact, term, trigram) .
type B {
name
}
type C {
name
}
- name: "fields with @dgraph(pred: ...) contain different language."
input: |
type A {
content: String! @dgraph(pred: "post") @search(by: [exact, term])
author: String @dgraph(pred: "<公司>") @search(by: [exact, term])
}
output: |
type A {
post
<公司>
}
post: string @index(exact, term) .
<公司>: string @index(exact, term) .
-
name: "custom query and mutation shouldn't be part of Dgraph schema"
input: |
type User @remote {
id: ID!
name: String!
}
type Query {
favUsers(id: ID!, name: String!): [User] @custom(http: {
url: "http://mock:8888/users",
method: "GET"
})
}
type Mutation {
setFavUsers(id: ID!, name: String!): [User] @custom(http: {
url: "http://mock:8888/users",
method: "POST"
})
}
-
name: "custom field shouldn't be part of dgraph schema"
input: |
type User {
id: ID!
name: String!
friends: [User] @custom(http: {
url: "http://mock:8888/users",
method: "GET"
})
}
output: |
type User {
User.name
}
User.name: string .