@subsquid/openreader 4.6.0 → 5.0.0-beta.79fbfe

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. package/lib/context.d.ts +2 -2
  2. package/lib/context.d.ts.map +1 -1
  3. package/lib/db.d.ts +3 -3
  4. package/lib/db.d.ts.map +1 -1
  5. package/lib/db.js +2 -2
  6. package/lib/db.js.map +1 -1
  7. package/lib/dialect/common.d.ts +19 -0
  8. package/lib/dialect/common.d.ts.map +1 -0
  9. package/lib/dialect/common.js +42 -0
  10. package/lib/dialect/common.js.map +1 -0
  11. package/lib/dialect/index.d.ts +6 -0
  12. package/lib/dialect/index.d.ts.map +1 -0
  13. package/lib/dialect/index.js +49 -0
  14. package/lib/dialect/index.js.map +1 -0
  15. package/lib/{opencrud → dialect/opencrud}/orderBy.d.ts +2 -3
  16. package/lib/dialect/opencrud/orderBy.d.ts.map +1 -0
  17. package/lib/{opencrud → dialect/opencrud}/orderBy.js +4 -21
  18. package/lib/dialect/opencrud/orderBy.js.map +1 -0
  19. package/lib/{opencrud → dialect/opencrud}/schema.d.ts +2 -6
  20. package/lib/dialect/opencrud/schema.d.ts.map +1 -0
  21. package/lib/{opencrud → dialect/opencrud}/schema.js +21 -34
  22. package/lib/dialect/opencrud/schema.js.map +1 -0
  23. package/lib/{opencrud → dialect/opencrud}/tree.d.ts +3 -3
  24. package/lib/dialect/opencrud/tree.d.ts.map +1 -0
  25. package/lib/{opencrud → dialect/opencrud}/tree.js +3 -3
  26. package/lib/dialect/opencrud/tree.js.map +1 -0
  27. package/lib/{opencrud → dialect/opencrud}/where.d.ts +1 -1
  28. package/lib/dialect/opencrud/where.d.ts.map +1 -0
  29. package/lib/{opencrud → dialect/opencrud}/where.js +4 -13
  30. package/lib/dialect/opencrud/where.js.map +1 -0
  31. package/lib/dialect/thegraph/locale.d.ts +2 -0
  32. package/lib/dialect/thegraph/locale.d.ts.map +1 -0
  33. package/lib/dialect/thegraph/locale.js +49 -0
  34. package/lib/dialect/thegraph/locale.js.map +1 -0
  35. package/lib/dialect/thegraph/orderBy.d.ts +11 -0
  36. package/lib/dialect/thegraph/orderBy.d.ts.map +1 -0
  37. package/lib/dialect/thegraph/orderBy.js +71 -0
  38. package/lib/dialect/thegraph/orderBy.js.map +1 -0
  39. package/lib/dialect/thegraph/schema.d.ts +25 -0
  40. package/lib/dialect/thegraph/schema.d.ts.map +1 -0
  41. package/lib/dialect/thegraph/schema.js +429 -0
  42. package/lib/dialect/thegraph/schema.js.map +1 -0
  43. package/lib/dialect/thegraph/tree.d.ts +10 -0
  44. package/lib/dialect/thegraph/tree.d.ts.map +1 -0
  45. package/lib/dialect/thegraph/tree.js +148 -0
  46. package/lib/dialect/thegraph/tree.js.map +1 -0
  47. package/lib/dialect/thegraph/where.d.ts +9 -0
  48. package/lib/dialect/thegraph/where.d.ts.map +1 -0
  49. package/lib/dialect/thegraph/where.js +188 -0
  50. package/lib/dialect/thegraph/where.js.map +1 -0
  51. package/lib/ir/args.d.ts +1 -1
  52. package/lib/ir/args.d.ts.map +1 -1
  53. package/lib/main.js +1 -1
  54. package/lib/main.js.map +1 -1
  55. package/lib/model.d.ts +2 -0
  56. package/lib/model.d.ts.map +1 -1
  57. package/lib/model.schema.d.ts.map +1 -1
  58. package/lib/model.schema.js +31 -2
  59. package/lib/model.schema.js.map +1 -1
  60. package/lib/server.d.ts +3 -1
  61. package/lib/server.d.ts.map +1 -1
  62. package/lib/server.js +7 -6
  63. package/lib/server.js.map +1 -1
  64. package/lib/sql/cursor.d.ts +2 -2
  65. package/lib/sql/cursor.d.ts.map +1 -1
  66. package/lib/sql/cursor.js +2 -2
  67. package/lib/sql/cursor.js.map +1 -1
  68. package/lib/sql/printer.d.ts +3 -3
  69. package/lib/sql/printer.d.ts.map +1 -1
  70. package/lib/sql/printer.js +17 -15
  71. package/lib/sql/printer.js.map +1 -1
  72. package/lib/sql/query.d.ts +5 -5
  73. package/lib/sql/query.d.ts.map +1 -1
  74. package/lib/sql/query.js.map +1 -1
  75. package/lib/sql/util.d.ts +2 -2
  76. package/lib/sql/util.d.ts.map +1 -1
  77. package/lib/sql/util.js.map +1 -1
  78. package/lib/test/basic.test.js +471 -229
  79. package/lib/test/basic.test.js.map +1 -1
  80. package/lib/test/isNull.test.js +87 -36
  81. package/lib/test/isNull.test.js.map +1 -1
  82. package/lib/test/limits.test.js +206 -94
  83. package/lib/test/limits.test.js.map +1 -1
  84. package/lib/test/lookup.test.js +184 -81
  85. package/lib/test/lookup.test.js.map +1 -1
  86. package/lib/test/setup.js +2 -2
  87. package/lib/test/setup.js.map +1 -1
  88. package/lib/test/where.test.js +216 -99
  89. package/lib/test/where.test.js.map +1 -1
  90. package/package.json +5 -3
  91. package/src/context.ts +2 -2
  92. package/src/db.ts +4 -2
  93. package/src/dialect/common.ts +49 -0
  94. package/src/dialect/index.ts +20 -0
  95. package/src/{opencrud → dialect/opencrud}/orderBy.ts +4 -21
  96. package/src/{opencrud → dialect/opencrud}/schema.ts +30 -55
  97. package/src/{opencrud → dialect/opencrud}/tree.ts +6 -7
  98. package/src/{opencrud → dialect/opencrud}/where.ts +4 -16
  99. package/src/dialect/thegraph/locale.ts +284 -0
  100. package/src/dialect/thegraph/orderBy.ts +75 -0
  101. package/src/dialect/thegraph/schema.ts +484 -0
  102. package/src/dialect/thegraph/tree.ts +162 -0
  103. package/src/dialect/thegraph/where.ts +184 -0
  104. package/src/ir/args.ts +2 -0
  105. package/src/main.ts +3 -3
  106. package/src/model.schema.ts +37 -4
  107. package/src/model.ts +2 -0
  108. package/src/server.ts +21 -19
  109. package/src/sql/cursor.ts +4 -4
  110. package/src/sql/printer.ts +22 -18
  111. package/src/sql/query.ts +5 -5
  112. package/src/sql/util.ts +2 -2
  113. package/src/test/basic.test.ts +570 -282
  114. package/src/test/isNull.test.ts +95 -38
  115. package/src/test/limits.test.ts +212 -91
  116. package/src/test/lookup.test.ts +190 -83
  117. package/src/test/setup.ts +2 -2
  118. package/src/test/where.test.ts +235 -108
  119. package/lib/dialect.d.ts +0 -2
  120. package/lib/dialect.d.ts.map +0 -1
  121. package/lib/dialect.js +0 -3
  122. package/lib/dialect.js.map +0 -1
  123. package/lib/opencrud/orderBy.d.ts.map +0 -1
  124. package/lib/opencrud/orderBy.js.map +0 -1
  125. package/lib/opencrud/schema.d.ts.map +0 -1
  126. package/lib/opencrud/schema.js.map +0 -1
  127. package/lib/opencrud/tree.d.ts.map +0 -1
  128. package/lib/opencrud/tree.js.map +0 -1
  129. package/lib/opencrud/where.d.ts.map +0 -1
  130. package/lib/opencrud/where.js.map +0 -1
  131. package/src/dialect.ts +0 -2
@@ -1,3 +1,4 @@
1
+ import {Dialect} from '../dialect'
1
2
  import {useDatabase, useServer} from "./setup"
2
3
 
3
4
 
@@ -16,324 +17,611 @@ describe('basic tests', function() {
16
17
  `insert into historical_balance (id, account_id, balance) values ('3-1', '3', 300)`,
17
18
  ])
18
19
 
19
- const client = useServer(`
20
- interface HasBalance {
21
- balance: Int!
22
- }
23
-
24
- type Account implements HasBalance @entity {
25
- id: ID!
26
- wallet: String!
27
- balance: Int!
28
- history: [HistoricalBalance!] @derivedFrom(field: "account")
29
- }
30
-
31
- "Historical record of account balance"
32
- type HistoricalBalance implements HasBalance @entity {
33
- "Unique identifier"
34
- id: ID!
35
-
36
- "Related account"
37
- account: Account!
38
-
39
- "Balance"
40
- balance: Int!
41
- }
42
- `)
43
-
44
- it('can fetch all accounts', function() {
45
- return client.test(
46
- `query {
47
- accounts(orderBy: id_ASC) {
48
- id
49
- wallet
50
- balance
51
- history(orderBy: id_ASC) { balance }
52
- }
53
- }`,
54
- {
55
- accounts: [
56
- {id: '1', wallet: 'a', balance: 100, history: [{balance: 20}, {balance: 80}]},
57
- {id: '2', wallet: 'b', balance: 200, history: [{balance: 50}, {balance: 90}, {balance: 60}]},
58
- {id: '3', wallet: 'c', balance: 300, history: [{balance: 300}]},
59
- ]
20
+ describe('opencrud', function() {
21
+ const client = useServer(`
22
+ interface HasBalance {
23
+ balance: Int!
60
24
  }
61
- )
62
- })
63
-
64
- it('supports filtering by id', function () {
65
- return client.test(
66
- `query {
67
- accounts(where: {id_eq: "3"}) {
68
- id
69
- wallet
70
- }
71
- }`,
72
- {
73
- accounts: [{id: '3', wallet: 'c'}]
25
+
26
+ type Account implements HasBalance @entity {
27
+ id: ID!
28
+ wallet: String!
29
+ balance: Int!
30
+ history: [HistoricalBalance!] @derivedFrom(field: "account")
74
31
  }
75
- )
76
- })
77
-
78
- it('supports by id query', function () {
79
- return client.test(
80
- `query {
81
- a3: accountById(id: "3") {
82
- id
83
- wallet
84
- }
85
- nonexistent: accountById(id: "foo") {
86
- id
87
- wallet
88
- }
89
- }`,
90
- {
91
- a3: {id: '3', wallet: 'c'},
92
- nonexistent: null
32
+
33
+ "Historical record of account balance"
34
+ type HistoricalBalance implements HasBalance @entity {
35
+ "Unique identifier"
36
+ id: ID!
37
+
38
+ "Related account"
39
+ account: Account!
40
+
41
+ "Balance"
42
+ balance: Int!
93
43
  }
94
- )
95
- })
96
-
97
- it('supports by unique input query', function () {
98
- return client.test(
99
- `query {
100
- a2: accountByUniqueInput(where: {id: "2"}) {
101
- id
102
- wallet
44
+ `)
45
+
46
+ it('can fetch all accounts', function() {
47
+ return client.test(
48
+ `query {
49
+ accounts(orderBy: id_ASC) {
50
+ id
51
+ wallet
52
+ balance
53
+ history(orderBy: id_ASC) { balance }
54
+ }
55
+ }`,
56
+ {
57
+ accounts: [
58
+ {id: '1', wallet: 'a', balance: 100, history: [{balance: 20}, {balance: 80}]},
59
+ {id: '2', wallet: 'b', balance: 200, history: [{balance: 50}, {balance: 90}, {balance: 60}]},
60
+ {id: '3', wallet: 'c', balance: 300, history: [{balance: 300}]},
61
+ ]
103
62
  }
104
- nonexistent: accountByUniqueInput(where: {id: "foo"}) {
105
- id
106
- wallet
63
+ )
64
+ })
65
+
66
+ it('supports filtering by id', function () {
67
+ return client.test(
68
+ `query {
69
+ accounts(where: {id_eq: "3"}) {
70
+ id
71
+ wallet
72
+ }
73
+ }`,
74
+ {
75
+ accounts: [{id: '3', wallet: 'c'}]
107
76
  }
108
- }`,
109
- {
110
- a2: {id: '2', wallet: 'b'},
111
- nonexistent: null
112
- }
113
- )
114
- })
115
-
116
- it('can fetch deep relations', function () {
117
- return client.test(
118
- `query {
119
- accounts(where: {id_eq: "3"}) {
120
- id
121
- history {
77
+ )
78
+ })
79
+
80
+ it('supports by id query', function () {
81
+ return client.test(
82
+ `query {
83
+ a3: accountById(id: "3") {
122
84
  id
123
- account {
124
- wallet
125
- history {
126
- balance
127
- account {
128
- id
85
+ wallet
86
+ }
87
+ nonexistent: accountById(id: "foo") {
88
+ id
89
+ wallet
90
+ }
91
+ }`,
92
+ {
93
+ a3: {id: '3', wallet: 'c'},
94
+ nonexistent: null
95
+ }
96
+ )
97
+ })
98
+
99
+ it('can fetch deep relations', function () {
100
+ return client.test(
101
+ `query {
102
+ accounts(where: {id_eq: "3"}) {
103
+ id
104
+ history {
105
+ id
106
+ account {
107
+ wallet
108
+ history {
109
+ balance
110
+ account {
111
+ id
112
+ }
129
113
  }
130
114
  }
131
115
  }
132
116
  }
117
+ }`,
118
+ {
119
+ accounts: [{
120
+ id: '3',
121
+ history: [{
122
+ id: '3-1',
123
+ account: {
124
+ wallet: 'c',
125
+ history: [{
126
+ balance: 300,
127
+ account: {
128
+ id: '3'
129
+ }
130
+ }]
131
+ }
132
+ }]
133
+ }]
133
134
  }
134
- }`,
135
- {
136
- accounts: [{
137
- id: '3',
138
- history: [{
139
- id: '3-1',
140
- account: {
141
- wallet: 'c',
142
- history: [{
143
- balance: 300,
144
- account: {
145
- id: '3'
146
- }
147
- }]
135
+ )
136
+ })
137
+
138
+ it('supports *_some filter', function () {
139
+ return client.test(
140
+ `query {
141
+ accounts(where: {history_some: {balance_lt: 50}}) {
142
+ id
143
+ }
144
+ }`,
145
+ {
146
+ accounts: [{id: '1'}]
147
+ }
148
+ )
149
+ })
150
+
151
+ it('supports *_every filter', function () {
152
+ return client.test(
153
+ `query {
154
+ accounts(where: {history_every: {balance_gt: 20}}) {
155
+ wallet
156
+ }
157
+ }`,
158
+ {
159
+ accounts: [{wallet: 'b'}, {wallet: 'c'}]
160
+ }
161
+ )
162
+ })
163
+
164
+ it('supports *_none filter', function () {
165
+ return client.test(
166
+ `query {
167
+ accounts(where: {history_none: {balance_lt: 60}}) {
168
+ wallet
169
+ }
170
+ }`,
171
+ {
172
+ accounts: [{wallet: 'c'}]
173
+ }
174
+ )
175
+ })
176
+
177
+ it('supports gql aliases', function () {
178
+ return client.test(
179
+ `query {
180
+ accounts(where: {id_eq: "1"}) {
181
+ balance
182
+ bag: wallet
183
+ purse: wallet
184
+ payment1: history(where: {id_eq: "1-1"}) {
185
+ balance
148
186
  }
187
+ payment2: history(where: {id_eq: "1-2"}) {
188
+ balance
189
+ }
190
+ }
191
+ }`,
192
+ {
193
+ accounts: [{
194
+ balance: 100,
195
+ bag: 'a',
196
+ purse: 'a',
197
+ payment1: [{balance: 20}],
198
+ payment2: [{balance: 80}]
149
199
  }]
150
- }]
151
- }
152
- )
153
- })
154
-
155
- it('supports *_some filter', function () {
156
- return client.test(
157
- `query {
158
- accounts(where: {history_some: {balance_lt: 50}}) {
159
- id
160
200
  }
161
- }`,
162
- {
163
- accounts: [{id: '1'}]
164
- }
165
- )
166
- })
167
-
168
- it('supports *_every filter', function () {
169
- return client.test(
170
- `query {
171
- accounts(where: {history_every: {balance_gt: 20}}) {
172
- wallet
201
+ )
202
+ })
203
+
204
+ it('supports gql fragments', function () {
205
+ return client.test(
206
+ `query {
207
+ accounts(where: {id_eq: "1"}) {
208
+ ...accountFields
209
+ history {
210
+ ...historicalBalance
211
+ }
212
+ }
173
213
  }
174
- }`,
175
- {
176
- accounts: [{wallet: 'b'}, {wallet: 'c'}]
177
- }
178
- )
179
- })
180
-
181
- it('supports *_none filter', function () {
182
- return client.test(
183
- `query {
184
- accounts(where: {history_none: {balance_lt: 60}}) {
214
+
215
+ fragment accountFields on Account {
216
+ id
185
217
  wallet
186
218
  }
187
- }`,
188
- {
189
- accounts: [{wallet: 'c'}]
190
- }
191
- )
192
- })
193
-
194
- it('supports gql aliases', function () {
195
- return client.test(
196
- `query {
197
- accounts(where: {id_eq: "1"}) {
219
+
220
+ fragment historicalBalance on HistoricalBalance {
198
221
  balance
199
- bag: wallet
200
- purse: wallet
201
- payment1: history(where: {id_eq: "1-1"}) {
222
+ }`,
223
+ {
224
+ accounts: [{
225
+ id: '1',
226
+ wallet: 'a',
227
+ history: [{balance: 20}, {balance: 80}]
228
+ }]
229
+ }
230
+ )
231
+ })
232
+
233
+ it('supports gql fragments on interfaces', function () {
234
+ return client.test(
235
+ `query {
236
+ accounts(where: {id_eq: "1"}) {
237
+ ...balance
238
+ history {
239
+ ...balance
240
+ }
241
+ }
242
+ }
243
+
244
+ fragment balance on HasBalance {
245
+ ... on Account {
246
+ accountBalance: balance
247
+ }
248
+ ... on HistoricalBalance {
249
+ payment: balance
250
+ }
251
+ }`,
252
+ {
253
+ accounts: [{
254
+ accountBalance: 100,
255
+ history: [{payment: 20}, {payment: 80}]
256
+ }]
257
+ }
258
+ )
259
+ })
260
+
261
+ it('supports sorting', function () {
262
+ return client.test(
263
+ `query {
264
+ historicalBalances(orderBy: balance_ASC) {
202
265
  balance
203
266
  }
204
- payment2: history(where: {id_eq: "1-2"}) {
267
+ }`,
268
+ {
269
+ historicalBalances: [
270
+ {balance: 20},
271
+ {balance: 50},
272
+ {balance: 60},
273
+ {balance: 80},
274
+ {balance: 90},
275
+ {balance: 300}
276
+ ]
277
+ }
278
+ )
279
+ })
280
+
281
+ it('supports sorting by referenced entity field', function () {
282
+ return client.test(
283
+ `query {
284
+ historicalBalances(orderBy: [account_wallet_ASC, balance_DESC]) {
205
285
  balance
206
286
  }
287
+ }`,
288
+ {
289
+ historicalBalances: [
290
+ {balance: 80},
291
+ {balance: 20},
292
+ {balance: 90},
293
+ {balance: 60},
294
+ {balance: 50},
295
+ {balance: 300}
296
+ ]
207
297
  }
208
- }`,
209
- {
210
- accounts: [{
211
- balance: 100,
212
- bag: 'a',
213
- purse: 'a',
214
- payment1: [{balance: 20}],
215
- payment2: [{balance: 80}]
216
- }]
217
- }
218
- )
219
- })
220
-
221
- it('supports gql fragments', function () {
222
- return client.test(
223
- `query {
224
- accounts(where: {id_eq: "1"}) {
225
- ...accountFields
226
- history {
227
- ...historicalBalance
298
+ )
299
+ })
300
+
301
+ it('supports descriptions', function () {
302
+ return client.test(`
303
+ query {
304
+ HistoricalBalance: __type(name: "HistoricalBalance") {
305
+ description
306
+ fields {
307
+ description
308
+ }
228
309
  }
229
310
  }
311
+ `, {
312
+ HistoricalBalance: {
313
+ description: 'Historical record of account balance',
314
+ fields: [
315
+ {description: 'Unique identifier'},
316
+ {description: 'Related account'},
317
+ {description: 'Balance'},
318
+ ]
319
+ }
320
+ })
321
+ })
322
+ })
323
+
324
+ describe('thegraph', function() {
325
+ const client = useServer(`
326
+ interface HasBalance {
327
+ balance: Int!
230
328
  }
231
-
232
- fragment accountFields on Account {
233
- id
234
- wallet
329
+
330
+ type Account implements HasBalance @entity {
331
+ id: ID!
332
+ wallet: String!
333
+ balance: Int!
334
+ history: [HistoricalBalance!] @derivedFrom(field: "account")
235
335
  }
236
-
237
- fragment historicalBalance on HistoricalBalance {
238
- balance
239
- }`,
240
- {
241
- accounts: [{
242
- id: '1',
243
- wallet: 'a',
244
- history: [{balance: 20}, {balance: 80}]
245
- }]
336
+
337
+ "Historical record of account balance"
338
+ type HistoricalBalance implements HasBalance @entity {
339
+ "Unique identifier"
340
+ id: ID!
341
+
342
+ "Related account"
343
+ account: Account!
344
+
345
+ "Balance"
346
+ balance: Int!
246
347
  }
247
- )
248
- })
249
-
250
- it('supports gql fragments on interfaces', function () {
251
- return client.test(
252
- `query {
253
- accounts(where: {id_eq: "1"}) {
254
- ...balance
255
- history {
256
- ...balance
348
+ `, {dialect: Dialect.TheGraph})
349
+
350
+ it('can fetch all accounts', function() {
351
+ return client.test(
352
+ `query {
353
+ accounts(orderBy: id, orderDirection: asc) {
354
+ id
355
+ wallet
356
+ balance
357
+ history(orderBy: id, orderDirection: asc) { balance }
257
358
  }
359
+ }`,
360
+ {
361
+ accounts: [
362
+ {id: '1', wallet: 'a', balance: 100, history: [{balance: 20}, {balance: 80}]},
363
+ {id: '2', wallet: 'b', balance: 200, history: [{balance: 50}, {balance: 90}, {balance: 60}]},
364
+ {id: '3', wallet: 'c', balance: 300, history: [{balance: 300}]},
365
+ ]
258
366
  }
259
- }
260
-
261
- fragment balance on HasBalance {
262
- ... on Account {
263
- accountBalance: balance
264
- }
265
- ... on HistoricalBalance {
266
- payment: balance
267
- }
268
- }`,
269
- {
270
- accounts: [{
271
- accountBalance: 100,
272
- history: [{payment: 20}, {payment: 80}]
273
- }]
274
- }
275
- )
276
- })
277
-
278
- it('supports sorting', function () {
279
- return client.test(
280
- `query {
281
- historicalBalances(orderBy: balance_ASC) {
282
- balance
367
+ )
368
+ })
369
+
370
+ it('supports filtering by id', function () {
371
+ return client.test(
372
+ `query {
373
+ accounts(where: {id: "3"}) {
374
+ id
375
+ wallet
376
+ }
377
+ }`,
378
+ {
379
+ accounts: [{id: '3', wallet: 'c'}]
283
380
  }
284
- }`,
285
- {
286
- historicalBalances: [
287
- {balance: 20},
288
- {balance: 50},
289
- {balance: 60},
290
- {balance: 80},
291
- {balance: 90},
292
- {balance: 300}
293
- ]
294
- }
295
- )
296
- })
297
-
298
- it('supports sorting by referenced entity field', function () {
299
- return client.test(
300
- `query {
301
- historicalBalances(orderBy: [account_wallet_ASC, balance_DESC]) {
381
+ )
382
+ })
383
+
384
+ it('supports by id query', function () {
385
+ return client.test(
386
+ `query {
387
+ a3: account(id: "3") {
388
+ id
389
+ wallet
390
+ }
391
+ nonexistent: account(id: "foo") {
392
+ id
393
+ wallet
394
+ }
395
+ }`,
396
+ {
397
+ a3: {id: '3', wallet: 'c'},
398
+ nonexistent: null
399
+ }
400
+ )
401
+ })
402
+
403
+ it('can fetch deep relations', function () {
404
+ return client.test(
405
+ `query {
406
+ accounts(where: {id: "3"}) {
407
+ id
408
+ history {
409
+ id
410
+ account {
411
+ wallet
412
+ history {
413
+ balance
414
+ account {
415
+ id
416
+ }
417
+ }
418
+ }
419
+ }
420
+ }
421
+ }`,
422
+ {
423
+ accounts: [{
424
+ id: '3',
425
+ history: [{
426
+ id: '3-1',
427
+ account: {
428
+ wallet: 'c',
429
+ history: [{
430
+ balance: 300,
431
+ account: {
432
+ id: '3'
433
+ }
434
+ }]
435
+ }
436
+ }]
437
+ }]
438
+ }
439
+ )
440
+ })
441
+
442
+ it('supports *_some filter', function () {
443
+ return client.test(
444
+ `query {
445
+ accounts(where: {history_some: {balance_lt: 50}}) {
446
+ id
447
+ }
448
+ }`,
449
+ {
450
+ accounts: [{id: '1'}]
451
+ }
452
+ )
453
+ })
454
+
455
+ it('supports *_every filter', function () {
456
+ return client.test(
457
+ `query {
458
+ accounts(where: {history_every: {balance_gt: 20}}) {
459
+ wallet
460
+ }
461
+ }`,
462
+ {
463
+ accounts: [{wallet: 'b'}, {wallet: 'c'}]
464
+ }
465
+ )
466
+ })
467
+
468
+ it('supports *_none filter', function () {
469
+ return client.test(
470
+ `query {
471
+ accounts(where: {history_none: {balance_lt: 60}}) {
472
+ wallet
473
+ }
474
+ }`,
475
+ {
476
+ accounts: [{wallet: 'c'}]
477
+ }
478
+ )
479
+ })
480
+
481
+ it('supports gql aliases', function () {
482
+ return client.test(
483
+ `query {
484
+ accounts(where: {id: "1"}) {
485
+ balance
486
+ bag: wallet
487
+ purse: wallet
488
+ payment1: history(where: {id: "1-1"}) {
489
+ balance
490
+ }
491
+ payment2: history(where: {id: "1-2"}) {
492
+ balance
493
+ }
494
+ }
495
+ }`,
496
+ {
497
+ accounts: [{
498
+ balance: 100,
499
+ bag: 'a',
500
+ purse: 'a',
501
+ payment1: [{balance: 20}],
502
+ payment2: [{balance: 80}]
503
+ }]
504
+ }
505
+ )
506
+ })
507
+
508
+ it('supports gql fragments', function () {
509
+ return client.test(
510
+ `query {
511
+ accounts(where: {id: "1"}) {
512
+ ...accountFields
513
+ history {
514
+ ...historicalBalance
515
+ }
516
+ }
517
+ }
518
+
519
+ fragment accountFields on Account {
520
+ id
521
+ wallet
522
+ }
523
+
524
+ fragment historicalBalance on HistoricalBalance {
302
525
  balance
526
+ }`,
527
+ {
528
+ accounts: [{
529
+ id: '1',
530
+ wallet: 'a',
531
+ history: [{balance: 20}, {balance: 80}]
532
+ }]
303
533
  }
304
- }`,
305
- {
306
- historicalBalances: [
307
- {balance: 80},
308
- {balance: 20},
309
- {balance: 90},
310
- {balance: 60},
311
- {balance: 50},
312
- {balance: 300}
313
- ]
314
- }
315
- )
316
- })
317
-
318
- it('supports descriptions', function () {
319
- return client.test(`
320
- query {
321
- HistoricalBalance: __type(name: "HistoricalBalance") {
322
- description
323
- fields {
534
+ )
535
+ })
536
+
537
+ it('supports gql fragments on interfaces', function () {
538
+ return client.test(
539
+ `query {
540
+ accounts(where: {id: "1"}) {
541
+ ...balance
542
+ history {
543
+ ...balance
544
+ }
545
+ }
546
+ }
547
+
548
+ fragment balance on HasBalance {
549
+ ... on Account {
550
+ accountBalance: balance
551
+ }
552
+ ... on HistoricalBalance {
553
+ payment: balance
554
+ }
555
+ }`,
556
+ {
557
+ accounts: [{
558
+ accountBalance: 100,
559
+ history: [{payment: 20}, {payment: 80}]
560
+ }]
561
+ }
562
+ )
563
+ })
564
+
565
+ it('supports sorting', function () {
566
+ return client.test(
567
+ `query {
568
+ historicalBalances(orderBy: balance, orderDirection: asc) {
569
+ balance
570
+ }
571
+ }`,
572
+ {
573
+ historicalBalances: [
574
+ {balance: 20},
575
+ {balance: 50},
576
+ {balance: 60},
577
+ {balance: 80},
578
+ {balance: 90},
579
+ {balance: 300}
580
+ ]
581
+ }
582
+ )
583
+ })
584
+
585
+ it('supports sorting by referenced entity field', function () {
586
+ return client.test(
587
+ `query {
588
+ historicalBalances(orderBy: account__wallet, orderDirection: asc) {
589
+ balance
590
+ }
591
+ }`,
592
+ {
593
+ historicalBalances: [
594
+ {balance: 20},
595
+ {balance: 80},
596
+ {balance: 50},
597
+ {balance: 90},
598
+ {balance: 60},
599
+ {balance: 300}
600
+ ]
601
+ }
602
+ )
603
+ })
604
+
605
+ it('supports descriptions', function () {
606
+ return client.test(`
607
+ query {
608
+ HistoricalBalance: __type(name: "HistoricalBalance") {
324
609
  description
610
+ fields {
611
+ description
612
+ }
325
613
  }
326
614
  }
327
- }
328
- `, {
329
- HistoricalBalance: {
330
- description: 'Historical record of account balance',
331
- fields: [
332
- {description: 'Unique identifier'},
333
- {description: 'Related account'},
334
- {description: 'Balance'},
335
- ]
336
- }
615
+ `, {
616
+ HistoricalBalance: {
617
+ description: 'Historical record of account balance',
618
+ fields: [
619
+ {description: 'Unique identifier'},
620
+ {description: 'Related account'},
621
+ {description: 'Balance'},
622
+ ]
623
+ }
624
+ })
337
625
  })
338
626
  })
339
627
  })