@subsquid/openreader 4.5.1 → 5.0.0-beta.62d187

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 +6 -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 +2 -2
  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 +8 -6
  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 +6 -22
  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 +3 -1
  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,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ const dialect_1 = require("../dialect");
3
4
  const setup_1 = require("./setup");
4
5
  describe('basic tests', function () {
5
6
  (0, setup_1.useDatabase)([
@@ -15,271 +16,512 @@ describe('basic tests', function () {
15
16
  `insert into historical_balance (id, account_id, balance) values ('2-3', '2', 60)`,
16
17
  `insert into historical_balance (id, account_id, balance) values ('3-1', '3', 300)`,
17
18
  ]);
18
- const client = (0, setup_1.useServer)(`
19
- interface HasBalance {
20
- balance: Int!
21
- }
19
+ describe('opencrud', function () {
20
+ const client = (0, setup_1.useServer)(`
21
+ interface HasBalance {
22
+ balance: Int!
23
+ }
24
+
25
+ type Account implements HasBalance @entity {
26
+ id: ID!
27
+ wallet: String!
28
+ balance: Int!
29
+ history: [HistoricalBalance!] @derivedFrom(field: "account")
30
+ }
22
31
 
23
- type Account implements HasBalance @entity {
24
- id: ID!
25
- wallet: String!
26
- balance: Int!
27
- history: [HistoricalBalance!] @derivedFrom(field: "account")
28
- }
29
-
30
- "Historical record of account balance"
31
- type HistoricalBalance implements HasBalance @entity {
32
- "Unique identifier"
33
- id: ID!
34
-
35
- "Related account"
36
- account: Account!
37
-
38
- "Balance"
39
- balance: Int!
40
- }
41
- `);
42
- it('can fetch all accounts', function () {
43
- return client.test(`query {
44
- accounts(orderBy: id_ASC) {
45
- id
46
- wallet
47
- balance
48
- history(orderBy: id_ASC) { balance }
49
- }
50
- }`, {
51
- accounts: [
52
- { id: '1', wallet: 'a', balance: 100, history: [{ balance: 20 }, { balance: 80 }] },
53
- { id: '2', wallet: 'b', balance: 200, history: [{ balance: 50 }, { balance: 90 }, { balance: 60 }] },
54
- { id: '3', wallet: 'c', balance: 300, history: [{ balance: 300 }] },
55
- ]
56
- });
57
- });
58
- it('supports filtering by id', function () {
59
- return client.test(`query {
60
- accounts(where: {id_eq: "3"}) {
61
- id
62
- wallet
63
- }
64
- }`, {
65
- accounts: [{ id: '3', wallet: 'c' }]
32
+ "Historical record of account balance"
33
+ type HistoricalBalance implements HasBalance @entity {
34
+ "Unique identifier"
35
+ id: ID!
36
+
37
+ "Related account"
38
+ account: Account!
39
+
40
+ "Balance"
41
+ balance: Int!
42
+ }
43
+ `);
44
+ it('can fetch all accounts', function () {
45
+ return client.test(`query {
46
+ accounts(orderBy: id_ASC) {
47
+ id
48
+ wallet
49
+ balance
50
+ history(orderBy: id_ASC) { balance }
51
+ }
52
+ }`, {
53
+ accounts: [
54
+ { id: '1', wallet: 'a', balance: 100, history: [{ balance: 20 }, { balance: 80 }] },
55
+ { id: '2', wallet: 'b', balance: 200, history: [{ balance: 50 }, { balance: 90 }, { balance: 60 }] },
56
+ { id: '3', wallet: 'c', balance: 300, history: [{ balance: 300 }] },
57
+ ]
58
+ });
66
59
  });
67
- });
68
- it('supports by id query', function () {
69
- return client.test(`query {
70
- a3: accountById(id: "3") {
71
- id
72
- wallet
73
- }
74
- nonexistent: accountById(id: "foo") {
75
- id
76
- wallet
77
- }
78
- }`, {
79
- a3: { id: '3', wallet: 'c' },
80
- nonexistent: null
60
+ it('supports filtering by id', function () {
61
+ return client.test(`query {
62
+ accounts(where: {id_eq: "3"}) {
63
+ id
64
+ wallet
65
+ }
66
+ }`, {
67
+ accounts: [{ id: '3', wallet: 'c' }]
68
+ });
81
69
  });
82
- });
83
- it('supports by unique input query', function () {
84
- return client.test(`query {
85
- a2: accountByUniqueInput(where: {id: "2"}) {
86
- id
87
- wallet
88
- }
89
- nonexistent: accountByUniqueInput(where: {id: "foo"}) {
90
- id
91
- wallet
92
- }
93
- }`, {
94
- a2: { id: '2', wallet: 'b' },
95
- nonexistent: null
70
+ it('supports by id query', function () {
71
+ return client.test(`query {
72
+ a3: accountById(id: "3") {
73
+ id
74
+ wallet
75
+ }
76
+ nonexistent: accountById(id: "foo") {
77
+ id
78
+ wallet
79
+ }
80
+ }`, {
81
+ a3: { id: '3', wallet: 'c' },
82
+ nonexistent: null
83
+ });
96
84
  });
97
- });
98
- it('can fetch deep relations', function () {
99
- return client.test(`query {
100
- accounts(where: {id_eq: "3"}) {
101
- id
102
- history {
85
+ it('can fetch deep relations', function () {
86
+ return client.test(`query {
87
+ accounts(where: {id_eq: "3"}) {
103
88
  id
104
- account {
105
- wallet
106
- history {
107
- balance
108
- account {
109
- id
89
+ history {
90
+ id
91
+ account {
92
+ wallet
93
+ history {
94
+ balance
95
+ account {
96
+ id
97
+ }
110
98
  }
111
99
  }
112
100
  }
113
101
  }
114
- }
115
- }`, {
116
- accounts: [{
117
- id: '3',
118
- history: [{
119
- id: '3-1',
120
- account: {
121
- wallet: 'c',
122
- history: [{
123
- balance: 300,
124
- account: {
125
- id: '3'
126
- }
127
- }]
128
- }
129
- }]
130
- }]
102
+ }`, {
103
+ accounts: [{
104
+ id: '3',
105
+ history: [{
106
+ id: '3-1',
107
+ account: {
108
+ wallet: 'c',
109
+ history: [{
110
+ balance: 300,
111
+ account: {
112
+ id: '3'
113
+ }
114
+ }]
115
+ }
116
+ }]
117
+ }]
118
+ });
131
119
  });
132
- });
133
- it('supports *_some filter', function () {
134
- return client.test(`query {
135
- accounts(where: {history_some: {balance_lt: 50}}) {
136
- id
137
- }
138
- }`, {
139
- accounts: [{ id: '1' }]
120
+ it('supports *_some filter', function () {
121
+ return client.test(`query {
122
+ accounts(where: {history_some: {balance_lt: 50}}) {
123
+ id
124
+ }
125
+ }`, {
126
+ accounts: [{ id: '1' }]
127
+ });
140
128
  });
141
- });
142
- it('supports *_every filter', function () {
143
- return client.test(`query {
144
- accounts(where: {history_every: {balance_gt: 20}}) {
129
+ it('supports *_every filter', function () {
130
+ return client.test(`query {
131
+ accounts(where: {history_every: {balance_gt: 20}}) {
132
+ wallet
133
+ }
134
+ }`, {
135
+ accounts: [{ wallet: 'b' }, { wallet: 'c' }]
136
+ });
137
+ });
138
+ it('supports *_none filter', function () {
139
+ return client.test(`query {
140
+ accounts(where: {history_none: {balance_lt: 60}}) {
141
+ wallet
142
+ }
143
+ }`, {
144
+ accounts: [{ wallet: 'c' }]
145
+ });
146
+ });
147
+ it('supports gql aliases', function () {
148
+ return client.test(`query {
149
+ accounts(where: {id_eq: "1"}) {
150
+ balance
151
+ bag: wallet
152
+ purse: wallet
153
+ payment1: history(where: {id_eq: "1-1"}) {
154
+ balance
155
+ }
156
+ payment2: history(where: {id_eq: "1-2"}) {
157
+ balance
158
+ }
159
+ }
160
+ }`, {
161
+ accounts: [{
162
+ balance: 100,
163
+ bag: 'a',
164
+ purse: 'a',
165
+ payment1: [{ balance: 20 }],
166
+ payment2: [{ balance: 80 }]
167
+ }]
168
+ });
169
+ });
170
+ it('supports gql fragments', function () {
171
+ return client.test(`query {
172
+ accounts(where: {id_eq: "1"}) {
173
+ ...accountFields
174
+ history {
175
+ ...historicalBalance
176
+ }
177
+ }
178
+ }
179
+
180
+ fragment accountFields on Account {
181
+ id
145
182
  wallet
146
183
  }
147
- }`, {
148
- accounts: [{ wallet: 'b' }, { wallet: 'c' }]
184
+
185
+ fragment historicalBalance on HistoricalBalance {
186
+ balance
187
+ }`, {
188
+ accounts: [{
189
+ id: '1',
190
+ wallet: 'a',
191
+ history: [{ balance: 20 }, { balance: 80 }]
192
+ }]
193
+ });
149
194
  });
150
- });
151
- it('supports *_none filter', function () {
152
- return client.test(`query {
153
- accounts(where: {history_none: {balance_lt: 60}}) {
154
- wallet
195
+ it('supports gql fragments on interfaces', function () {
196
+ return client.test(`query {
197
+ accounts(where: {id_eq: "1"}) {
198
+ ...balance
199
+ history {
200
+ ...balance
201
+ }
202
+ }
155
203
  }
156
- }`, {
157
- accounts: [{ wallet: 'c' }]
204
+
205
+ fragment balance on HasBalance {
206
+ ... on Account {
207
+ accountBalance: balance
208
+ }
209
+ ... on HistoricalBalance {
210
+ payment: balance
211
+ }
212
+ }`, {
213
+ accounts: [{
214
+ accountBalance: 100,
215
+ history: [{ payment: 20 }, { payment: 80 }]
216
+ }]
217
+ });
158
218
  });
159
- });
160
- it('supports gql aliases', function () {
161
- return client.test(`query {
162
- accounts(where: {id_eq: "1"}) {
163
- balance
164
- bag: wallet
165
- purse: wallet
166
- payment1: history(where: {id_eq: "1-1"}) {
219
+ it('supports sorting', function () {
220
+ return client.test(`query {
221
+ historicalBalances(orderBy: balance_ASC) {
167
222
  balance
168
223
  }
169
- payment2: history(where: {id_eq: "1-2"}) {
224
+ }`, {
225
+ historicalBalances: [
226
+ { balance: 20 },
227
+ { balance: 50 },
228
+ { balance: 60 },
229
+ { balance: 80 },
230
+ { balance: 90 },
231
+ { balance: 300 }
232
+ ]
233
+ });
234
+ });
235
+ it('supports sorting by referenced entity field', function () {
236
+ return client.test(`query {
237
+ historicalBalances(orderBy: [account_wallet_ASC, balance_DESC]) {
170
238
  balance
171
239
  }
172
- }
173
- }`, {
174
- accounts: [{
175
- balance: 100,
176
- bag: 'a',
177
- purse: 'a',
178
- payment1: [{ balance: 20 }],
179
- payment2: [{ balance: 80 }]
180
- }]
240
+ }`, {
241
+ historicalBalances: [
242
+ { balance: 80 },
243
+ { balance: 20 },
244
+ { balance: 90 },
245
+ { balance: 60 },
246
+ { balance: 50 },
247
+ { balance: 300 }
248
+ ]
249
+ });
181
250
  });
182
- });
183
- it('supports gql fragments', function () {
184
- return client.test(`query {
185
- accounts(where: {id_eq: "1"}) {
186
- ...accountFields
187
- history {
188
- ...historicalBalance
251
+ it('supports descriptions', function () {
252
+ return client.test(`
253
+ query {
254
+ HistoricalBalance: __type(name: "HistoricalBalance") {
255
+ description
256
+ fields {
257
+ description
258
+ }
189
259
  }
190
260
  }
261
+ `, {
262
+ HistoricalBalance: {
263
+ description: 'Historical record of account balance',
264
+ fields: [
265
+ { description: 'Unique identifier' },
266
+ { description: 'Related account' },
267
+ { description: 'Balance' },
268
+ ]
269
+ }
270
+ });
271
+ });
272
+ });
273
+ describe('thegraph', function () {
274
+ const client = (0, setup_1.useServer)(`
275
+ interface HasBalance {
276
+ balance: Int!
277
+ }
278
+
279
+ type Account implements HasBalance @entity {
280
+ id: ID!
281
+ wallet: String!
282
+ balance: Int!
283
+ history: [HistoricalBalance!] @derivedFrom(field: "account")
191
284
  }
192
-
193
- fragment accountFields on Account {
194
- id
195
- wallet
285
+
286
+ "Historical record of account balance"
287
+ type HistoricalBalance implements HasBalance @entity {
288
+ "Unique identifier"
289
+ id: ID!
290
+
291
+ "Related account"
292
+ account: Account!
293
+
294
+ "Balance"
295
+ balance: Int!
196
296
  }
197
-
198
- fragment historicalBalance on HistoricalBalance {
199
- balance
200
- }`, {
201
- accounts: [{
202
- id: '1',
203
- wallet: 'a',
204
- history: [{ balance: 20 }, { balance: 80 }]
205
- }]
297
+ `, { dialect: dialect_1.Dialect.TheGraph });
298
+ it('can fetch all accounts', function () {
299
+ return client.test(`query {
300
+ accounts(orderBy: id, orderDirection: asc) {
301
+ id
302
+ wallet
303
+ balance
304
+ history(orderBy: id, orderDirection: asc) { balance }
305
+ }
306
+ }`, {
307
+ accounts: [
308
+ { id: '1', wallet: 'a', balance: 100, history: [{ balance: 20 }, { balance: 80 }] },
309
+ { id: '2', wallet: 'b', balance: 200, history: [{ balance: 50 }, { balance: 90 }, { balance: 60 }] },
310
+ { id: '3', wallet: 'c', balance: 300, history: [{ balance: 300 }] },
311
+ ]
312
+ });
206
313
  });
207
- });
208
- it('supports gql fragments on interfaces', function () {
209
- return client.test(`query {
210
- accounts(where: {id_eq: "1"}) {
211
- ...balance
212
- history {
213
- ...balance
314
+ it('supports filtering by id', function () {
315
+ return client.test(`query {
316
+ accounts(where: {id: "3"}) {
317
+ id
318
+ wallet
319
+ }
320
+ }`, {
321
+ accounts: [{ id: '3', wallet: 'c' }]
322
+ });
323
+ });
324
+ it('supports by id query', function () {
325
+ return client.test(`query {
326
+ a3: account(id: "3") {
327
+ id
328
+ wallet
329
+ }
330
+ nonexistent: account(id: "foo") {
331
+ id
332
+ wallet
333
+ }
334
+ }`, {
335
+ a3: { id: '3', wallet: 'c' },
336
+ nonexistent: null
337
+ });
338
+ });
339
+ it('can fetch deep relations', function () {
340
+ return client.test(`query {
341
+ accounts(where: {id: "3"}) {
342
+ id
343
+ history {
344
+ id
345
+ account {
346
+ wallet
347
+ history {
348
+ balance
349
+ account {
350
+ id
351
+ }
352
+ }
353
+ }
354
+ }
355
+ }
356
+ }`, {
357
+ accounts: [{
358
+ id: '3',
359
+ history: [{
360
+ id: '3-1',
361
+ account: {
362
+ wallet: 'c',
363
+ history: [{
364
+ balance: 300,
365
+ account: {
366
+ id: '3'
367
+ }
368
+ }]
369
+ }
370
+ }]
371
+ }]
372
+ });
373
+ });
374
+ it('supports *_some filter', function () {
375
+ return client.test(`query {
376
+ accounts(where: {history_some: {balance_lt: 50}}) {
377
+ id
378
+ }
379
+ }`, {
380
+ accounts: [{ id: '1' }]
381
+ });
382
+ });
383
+ it('supports *_every filter', function () {
384
+ return client.test(`query {
385
+ accounts(where: {history_every: {balance_gt: 20}}) {
386
+ wallet
387
+ }
388
+ }`, {
389
+ accounts: [{ wallet: 'b' }, { wallet: 'c' }]
390
+ });
391
+ });
392
+ it('supports *_none filter', function () {
393
+ return client.test(`query {
394
+ accounts(where: {history_none: {balance_lt: 60}}) {
395
+ wallet
396
+ }
397
+ }`, {
398
+ accounts: [{ wallet: 'c' }]
399
+ });
400
+ });
401
+ it('supports gql aliases', function () {
402
+ return client.test(`query {
403
+ accounts(where: {id: "1"}) {
404
+ balance
405
+ bag: wallet
406
+ purse: wallet
407
+ payment1: history(where: {id: "1-1"}) {
408
+ balance
409
+ }
410
+ payment2: history(where: {id: "1-2"}) {
411
+ balance
412
+ }
413
+ }
414
+ }`, {
415
+ accounts: [{
416
+ balance: 100,
417
+ bag: 'a',
418
+ purse: 'a',
419
+ payment1: [{ balance: 20 }],
420
+ payment2: [{ balance: 80 }]
421
+ }]
422
+ });
423
+ });
424
+ it('supports gql fragments', function () {
425
+ return client.test(`query {
426
+ accounts(where: {id: "1"}) {
427
+ ...accountFields
428
+ history {
429
+ ...historicalBalance
430
+ }
214
431
  }
215
432
  }
216
- }
217
-
218
- fragment balance on HasBalance {
219
- ... on Account {
220
- accountBalance: balance
221
- }
222
- ... on HistoricalBalance {
223
- payment: balance
433
+
434
+ fragment accountFields on Account {
435
+ id
436
+ wallet
224
437
  }
225
- }`, {
226
- accounts: [{
227
- accountBalance: 100,
228
- history: [{ payment: 20 }, { payment: 80 }]
229
- }]
230
- });
231
- });
232
- it('supports sorting', function () {
233
- return client.test(`query {
234
- historicalBalances(orderBy: balance_ASC) {
438
+
439
+ fragment historicalBalance on HistoricalBalance {
235
440
  balance
236
- }
237
- }`, {
238
- historicalBalances: [
239
- { balance: 20 },
240
- { balance: 50 },
241
- { balance: 60 },
242
- { balance: 80 },
243
- { balance: 90 },
244
- { balance: 300 }
245
- ]
441
+ }`, {
442
+ accounts: [{
443
+ id: '1',
444
+ wallet: 'a',
445
+ history: [{ balance: 20 }, { balance: 80 }]
446
+ }]
447
+ });
246
448
  });
247
- });
248
- it('supports sorting by referenced entity field', function () {
249
- return client.test(`query {
250
- historicalBalances(orderBy: [account_wallet_ASC, balance_DESC]) {
251
- balance
449
+ it('supports gql fragments on interfaces', function () {
450
+ return client.test(`query {
451
+ accounts(where: {id: "1"}) {
452
+ ...balance
453
+ history {
454
+ ...balance
455
+ }
456
+ }
252
457
  }
253
- }`, {
254
- historicalBalances: [
255
- { balance: 80 },
256
- { balance: 20 },
257
- { balance: 90 },
258
- { balance: 60 },
259
- { balance: 50 },
260
- { balance: 300 }
261
- ]
458
+
459
+ fragment balance on HasBalance {
460
+ ... on Account {
461
+ accountBalance: balance
462
+ }
463
+ ... on HistoricalBalance {
464
+ payment: balance
465
+ }
466
+ }`, {
467
+ accounts: [{
468
+ accountBalance: 100,
469
+ history: [{ payment: 20 }, { payment: 80 }]
470
+ }]
471
+ });
262
472
  });
263
- });
264
- it('supports descriptions', function () {
265
- return client.test(`
266
- query {
267
- HistoricalBalance: __type(name: "HistoricalBalance") {
268
- description
269
- fields {
473
+ it('supports sorting', function () {
474
+ return client.test(`query {
475
+ historicalBalances(orderBy: balance, orderDirection: asc) {
476
+ balance
477
+ }
478
+ }`, {
479
+ historicalBalances: [
480
+ { balance: 20 },
481
+ { balance: 50 },
482
+ { balance: 60 },
483
+ { balance: 80 },
484
+ { balance: 90 },
485
+ { balance: 300 }
486
+ ]
487
+ });
488
+ });
489
+ it('supports sorting by referenced entity field', function () {
490
+ return client.test(`query {
491
+ historicalBalances(orderBy: account__wallet, orderDirection: asc) {
492
+ balance
493
+ }
494
+ }`, {
495
+ historicalBalances: [
496
+ { balance: 20 },
497
+ { balance: 80 },
498
+ { balance: 50 },
499
+ { balance: 90 },
500
+ { balance: 60 },
501
+ { balance: 300 }
502
+ ]
503
+ });
504
+ });
505
+ it('supports descriptions', function () {
506
+ return client.test(`
507
+ query {
508
+ HistoricalBalance: __type(name: "HistoricalBalance") {
270
509
  description
510
+ fields {
511
+ description
512
+ }
271
513
  }
272
514
  }
273
- }
274
- `, {
275
- HistoricalBalance: {
276
- description: 'Historical record of account balance',
277
- fields: [
278
- { description: 'Unique identifier' },
279
- { description: 'Related account' },
280
- { description: 'Balance' },
281
- ]
282
- }
515
+ `, {
516
+ HistoricalBalance: {
517
+ description: 'Historical record of account balance',
518
+ fields: [
519
+ { description: 'Unique identifier' },
520
+ { description: 'Related account' },
521
+ { description: 'Balance' },
522
+ ]
523
+ }
524
+ });
283
525
  });
284
526
  });
285
527
  });