@graphprotocol/graph-cli 0.63.0-alpha-20231129164209-bdb5146 → 0.63.0-alpha-20231129164624-7160f52
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.
- package/CHANGELOG.md +2 -2
- package/dist/codegen/schema.test.js +134 -138
- package/dist/validation/schema.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.63.0-alpha-
|
|
3
|
+
## 0.63.0-alpha-20231129164624-7160f52
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
7
|
- [#1522](https://github.com/graphprotocol/graph-tooling/pull/1522)
|
|
8
|
-
[`
|
|
8
|
+
[`7160f52`](https://github.com/graphprotocol/graph-tooling/commit/7160f5247acf2e2587345e6b68ad8553a6162d3a)
|
|
9
9
|
Thanks [@dotansimha](https://github.com/dotansimha)! - Added support for handling GraphQL
|
|
10
10
|
`Timestamp` scalar as `i64` (AssemblyScript)
|
|
11
11
|
|
|
@@ -32,12 +32,12 @@ const prettier_1 = __importDefault(require("prettier"));
|
|
|
32
32
|
const schema_1 = __importDefault(require("../schema"));
|
|
33
33
|
const schema_2 = __importDefault(require("./schema"));
|
|
34
34
|
const typescript_1 = require("./typescript");
|
|
35
|
-
const formatTS = (code) => prettier_1.default.format(code, { parser:
|
|
36
|
-
const createSchemaCodeGen = (schema) => new schema_2.default(new schema_1.default(
|
|
35
|
+
const formatTS = (code) => prettier_1.default.format(code, { parser: 'typescript', semi: false });
|
|
36
|
+
const createSchemaCodeGen = (schema) => new schema_2.default(new schema_1.default('', schema, graphql.parse(schema)));
|
|
37
37
|
const testEntity = (generatedTypes, expectedEntity) => {
|
|
38
|
-
const entity = generatedTypes.find(
|
|
38
|
+
const entity = generatedTypes.find(type => type.name === expectedEntity.name);
|
|
39
39
|
expect(entity instanceof typescript_1.Class).toBe(true);
|
|
40
|
-
expect(entity.extends).toBe(
|
|
40
|
+
expect(entity.extends).toBe('Entity');
|
|
41
41
|
expect(entity.export).toBe(true);
|
|
42
42
|
const { members, methods } = entity;
|
|
43
43
|
expect(members).toStrictEqual(expectedEntity.members);
|
|
@@ -53,8 +53,8 @@ const testEntity = (generatedTypes, expectedEntity) => {
|
|
|
53
53
|
}
|
|
54
54
|
expect(methods.length).toBe(expectedEntity.methods.length);
|
|
55
55
|
};
|
|
56
|
-
describe(
|
|
57
|
-
test(
|
|
56
|
+
describe('Schema code generator', () => {
|
|
57
|
+
test('Should generate nothing for non entity types', () => {
|
|
58
58
|
const codegen = createSchemaCodeGen(`
|
|
59
59
|
type Foo {
|
|
60
60
|
foobar: Int
|
|
@@ -66,7 +66,7 @@ describe("Schema code generator", () => {
|
|
|
66
66
|
`);
|
|
67
67
|
expect(codegen.generateTypes().length).toBe(0);
|
|
68
68
|
});
|
|
69
|
-
describe(
|
|
69
|
+
describe('Should generate correct classes for each entity', () => {
|
|
70
70
|
const codegen = createSchemaCodeGen(`
|
|
71
71
|
# just to be sure nothing will be generated from non-entity types alongside regular ones
|
|
72
72
|
type Foo {
|
|
@@ -100,20 +100,20 @@ describe("Schema code generator", () => {
|
|
|
100
100
|
}
|
|
101
101
|
`);
|
|
102
102
|
const generatedTypes = codegen.generateTypes();
|
|
103
|
-
test(
|
|
104
|
-
const foo = generatedTypes.find((type) => type.name ===
|
|
103
|
+
test('Foo is NOT an entity', () => {
|
|
104
|
+
const foo = generatedTypes.find((type) => type.name === 'Foo');
|
|
105
105
|
expect(foo).toBe(undefined);
|
|
106
106
|
// Account and Wallet
|
|
107
107
|
expect(generatedTypes.length).toBe(2);
|
|
108
108
|
});
|
|
109
|
-
test(
|
|
109
|
+
test('Account is an entity with the correct methods', () => {
|
|
110
110
|
testEntity(generatedTypes, {
|
|
111
|
-
name:
|
|
111
|
+
name: 'Account',
|
|
112
112
|
members: [],
|
|
113
113
|
methods: [
|
|
114
114
|
{
|
|
115
|
-
name:
|
|
116
|
-
params: [new typescript_1.Param(
|
|
115
|
+
name: 'constructor',
|
|
116
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
117
117
|
returnType: undefined,
|
|
118
118
|
body: `
|
|
119
119
|
super()
|
|
@@ -121,9 +121,9 @@ describe("Schema code generator", () => {
|
|
|
121
121
|
`,
|
|
122
122
|
},
|
|
123
123
|
{
|
|
124
|
-
name:
|
|
124
|
+
name: 'save',
|
|
125
125
|
params: [],
|
|
126
|
-
returnType: new typescript_1.NamedType(
|
|
126
|
+
returnType: new typescript_1.NamedType('void'),
|
|
127
127
|
body: `
|
|
128
128
|
let id = this.get('id')
|
|
129
129
|
assert(id != null, 'Cannot save Account entity without an ID')
|
|
@@ -136,27 +136,27 @@ describe("Schema code generator", () => {
|
|
|
136
136
|
`,
|
|
137
137
|
},
|
|
138
138
|
{
|
|
139
|
-
name:
|
|
139
|
+
name: 'loadInBlock',
|
|
140
140
|
static: true,
|
|
141
|
-
params: [new typescript_1.Param(
|
|
142
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
141
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
142
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Account')),
|
|
143
143
|
body: `
|
|
144
144
|
return changetype<Account | null>(store.get_in_block('Account', id))
|
|
145
145
|
`,
|
|
146
146
|
},
|
|
147
147
|
{
|
|
148
|
-
name:
|
|
148
|
+
name: 'load',
|
|
149
149
|
static: true,
|
|
150
|
-
params: [new typescript_1.Param(
|
|
151
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
150
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
151
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Account')),
|
|
152
152
|
body: `
|
|
153
153
|
return changetype<Account | null>(store.get('Account', id))
|
|
154
154
|
`,
|
|
155
155
|
},
|
|
156
156
|
{
|
|
157
|
-
name:
|
|
157
|
+
name: 'get id',
|
|
158
158
|
params: [],
|
|
159
|
-
returnType: new typescript_1.NamedType(
|
|
159
|
+
returnType: new typescript_1.NamedType('string'),
|
|
160
160
|
body: `let value = this.get('id')
|
|
161
161
|
if (!value || value.kind == ValueKind.NULL) {
|
|
162
162
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -166,17 +166,17 @@ describe("Schema code generator", () => {
|
|
|
166
166
|
`,
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
|
-
name:
|
|
170
|
-
params: [new typescript_1.Param(
|
|
169
|
+
name: 'set id',
|
|
170
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('string'))],
|
|
171
171
|
returnType: undefined,
|
|
172
172
|
body: `
|
|
173
173
|
this.set('id', Value.fromString(value))
|
|
174
174
|
`,
|
|
175
175
|
},
|
|
176
176
|
{
|
|
177
|
-
name:
|
|
177
|
+
name: 'get description',
|
|
178
178
|
params: [],
|
|
179
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
179
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('string')),
|
|
180
180
|
body: `
|
|
181
181
|
let value = this.get('description')
|
|
182
182
|
if (!value || value.kind == ValueKind.NULL) {
|
|
@@ -187,10 +187,8 @@ describe("Schema code generator", () => {
|
|
|
187
187
|
`,
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
|
-
name:
|
|
191
|
-
params: [
|
|
192
|
-
new typescript_1.Param("value", new typescript_1.NullableType(new typescript_1.NamedType("string"))),
|
|
193
|
-
],
|
|
190
|
+
name: 'set description',
|
|
191
|
+
params: [new typescript_1.Param('value', new typescript_1.NullableType(new typescript_1.NamedType('string')))],
|
|
194
192
|
returnType: undefined,
|
|
195
193
|
body: `
|
|
196
194
|
if (!value) {
|
|
@@ -201,9 +199,9 @@ describe("Schema code generator", () => {
|
|
|
201
199
|
`,
|
|
202
200
|
},
|
|
203
201
|
{
|
|
204
|
-
name:
|
|
202
|
+
name: 'get name',
|
|
205
203
|
params: [],
|
|
206
|
-
returnType: new typescript_1.NamedType(
|
|
204
|
+
returnType: new typescript_1.NamedType('string'),
|
|
207
205
|
body: `let value = this.get('name')
|
|
208
206
|
if (!value || value.kind == ValueKind.NULL) {
|
|
209
207
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -213,17 +211,17 @@ describe("Schema code generator", () => {
|
|
|
213
211
|
`,
|
|
214
212
|
},
|
|
215
213
|
{
|
|
216
|
-
name:
|
|
217
|
-
params: [new typescript_1.Param(
|
|
214
|
+
name: 'set name',
|
|
215
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('string'))],
|
|
218
216
|
returnType: undefined,
|
|
219
217
|
body: `
|
|
220
218
|
this.set('name', Value.fromString(value))
|
|
221
219
|
`,
|
|
222
220
|
},
|
|
223
221
|
{
|
|
224
|
-
name:
|
|
222
|
+
name: 'get age',
|
|
225
223
|
params: [],
|
|
226
|
-
returnType: new typescript_1.NamedType(
|
|
224
|
+
returnType: new typescript_1.NamedType('i32'),
|
|
227
225
|
body: `let value = this.get('age')
|
|
228
226
|
if (!value || value.kind == ValueKind.NULL) {
|
|
229
227
|
return 0
|
|
@@ -233,17 +231,17 @@ describe("Schema code generator", () => {
|
|
|
233
231
|
`,
|
|
234
232
|
},
|
|
235
233
|
{
|
|
236
|
-
name:
|
|
237
|
-
params: [new typescript_1.Param(
|
|
234
|
+
name: 'set age',
|
|
235
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('i32'))],
|
|
238
236
|
returnType: undefined,
|
|
239
237
|
body: `
|
|
240
238
|
this.set('age', Value.fromI32(value))
|
|
241
239
|
`,
|
|
242
240
|
},
|
|
243
241
|
{
|
|
244
|
-
name:
|
|
242
|
+
name: 'get count',
|
|
245
243
|
params: [],
|
|
246
|
-
returnType: new typescript_1.NamedType(
|
|
244
|
+
returnType: new typescript_1.NamedType('i32'),
|
|
247
245
|
body: `let value = this.get('count')
|
|
248
246
|
if (!value || value.kind == ValueKind.NULL) {
|
|
249
247
|
return 0
|
|
@@ -253,17 +251,17 @@ describe("Schema code generator", () => {
|
|
|
253
251
|
`,
|
|
254
252
|
},
|
|
255
253
|
{
|
|
256
|
-
name:
|
|
257
|
-
params: [new typescript_1.Param(
|
|
254
|
+
name: 'set count',
|
|
255
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('i32'))],
|
|
258
256
|
returnType: undefined,
|
|
259
257
|
body: `
|
|
260
258
|
this.set('count', Value.fromI32(value))
|
|
261
259
|
`,
|
|
262
260
|
},
|
|
263
261
|
{
|
|
264
|
-
name:
|
|
262
|
+
name: 'get isActive',
|
|
265
263
|
params: [],
|
|
266
|
-
returnType: new typescript_1.NamedType(
|
|
264
|
+
returnType: new typescript_1.NamedType('boolean'),
|
|
267
265
|
body: `let value = this.get('isActive')
|
|
268
266
|
if (!value || value.kind == ValueKind.NULL) {
|
|
269
267
|
return false
|
|
@@ -273,17 +271,17 @@ describe("Schema code generator", () => {
|
|
|
273
271
|
`,
|
|
274
272
|
},
|
|
275
273
|
{
|
|
276
|
-
name:
|
|
277
|
-
params: [new typescript_1.Param(
|
|
274
|
+
name: 'set isActive',
|
|
275
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('boolean'))],
|
|
278
276
|
returnType: undefined,
|
|
279
277
|
body: `
|
|
280
278
|
this.set('isActive', Value.fromBoolean(value))
|
|
281
279
|
`,
|
|
282
280
|
},
|
|
283
281
|
{
|
|
284
|
-
name:
|
|
282
|
+
name: 'get int8',
|
|
285
283
|
params: [],
|
|
286
|
-
returnType: new typescript_1.NamedType(
|
|
284
|
+
returnType: new typescript_1.NamedType('i64'),
|
|
287
285
|
body: `let value = this.get('int8')
|
|
288
286
|
if (!value || value.kind == ValueKind.NULL) {
|
|
289
287
|
return 0
|
|
@@ -293,17 +291,17 @@ describe("Schema code generator", () => {
|
|
|
293
291
|
`,
|
|
294
292
|
},
|
|
295
293
|
{
|
|
296
|
-
name:
|
|
297
|
-
params: [new typescript_1.Param(
|
|
294
|
+
name: 'set int8',
|
|
295
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('i64'))],
|
|
298
296
|
returnType: undefined,
|
|
299
297
|
body: `
|
|
300
298
|
this.set('int8', Value.fromI64(value))
|
|
301
299
|
`,
|
|
302
300
|
},
|
|
303
301
|
{
|
|
304
|
-
name:
|
|
302
|
+
name: 'get timtestamp',
|
|
305
303
|
params: [],
|
|
306
|
-
returnType: new typescript_1.NamedType(
|
|
304
|
+
returnType: new typescript_1.NamedType('i64'),
|
|
307
305
|
body: `let value = this.get('timestamp')
|
|
308
306
|
if (!value || value.kind == ValueKind.NULL) {
|
|
309
307
|
return 0
|
|
@@ -313,17 +311,17 @@ describe("Schema code generator", () => {
|
|
|
313
311
|
`,
|
|
314
312
|
},
|
|
315
313
|
{
|
|
316
|
-
name:
|
|
317
|
-
params: [new typescript_1.Param(
|
|
314
|
+
name: 'set timestamp',
|
|
315
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('i64'))],
|
|
318
316
|
returnType: undefined,
|
|
319
317
|
body: `
|
|
320
318
|
this.set('timestamp', Value.fromI64(value))
|
|
321
319
|
`,
|
|
322
320
|
},
|
|
323
321
|
{
|
|
324
|
-
name:
|
|
322
|
+
name: 'get wallets',
|
|
325
323
|
params: [],
|
|
326
|
-
returnType: new typescript_1.NamedType(
|
|
324
|
+
returnType: new typescript_1.NamedType('WalletLoader'),
|
|
327
325
|
body: `
|
|
328
326
|
return new WalletLoader("Account", this.get('id')!.toString(), "wallets")
|
|
329
327
|
`,
|
|
@@ -331,14 +329,14 @@ describe("Schema code generator", () => {
|
|
|
331
329
|
],
|
|
332
330
|
});
|
|
333
331
|
});
|
|
334
|
-
test(
|
|
332
|
+
test('Wallet is an entity with the correct methods', () => {
|
|
335
333
|
testEntity(generatedTypes, {
|
|
336
|
-
name:
|
|
334
|
+
name: 'Wallet',
|
|
337
335
|
members: [],
|
|
338
336
|
methods: [
|
|
339
337
|
{
|
|
340
|
-
name:
|
|
341
|
-
params: [new typescript_1.Param(
|
|
338
|
+
name: 'constructor',
|
|
339
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
342
340
|
returnType: undefined,
|
|
343
341
|
body: `
|
|
344
342
|
super()
|
|
@@ -346,9 +344,9 @@ describe("Schema code generator", () => {
|
|
|
346
344
|
`,
|
|
347
345
|
},
|
|
348
346
|
{
|
|
349
|
-
name:
|
|
347
|
+
name: 'save',
|
|
350
348
|
params: [],
|
|
351
|
-
returnType: new typescript_1.NamedType(
|
|
349
|
+
returnType: new typescript_1.NamedType('void'),
|
|
352
350
|
body: `
|
|
353
351
|
let id = this.get('id')
|
|
354
352
|
assert(id != null, 'Cannot save Wallet entity without an ID')
|
|
@@ -361,27 +359,27 @@ describe("Schema code generator", () => {
|
|
|
361
359
|
`,
|
|
362
360
|
},
|
|
363
361
|
{
|
|
364
|
-
name:
|
|
362
|
+
name: 'loadInBlock',
|
|
365
363
|
static: true,
|
|
366
|
-
params: [new typescript_1.Param(
|
|
367
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
364
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
365
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Wallet')),
|
|
368
366
|
body: `
|
|
369
367
|
return changetype<Wallet | null>(store.get_in_block('Wallet', id))
|
|
370
368
|
`,
|
|
371
369
|
},
|
|
372
370
|
{
|
|
373
|
-
name:
|
|
371
|
+
name: 'load',
|
|
374
372
|
static: true,
|
|
375
|
-
params: [new typescript_1.Param(
|
|
376
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
373
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('string'))],
|
|
374
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Wallet')),
|
|
377
375
|
body: `
|
|
378
376
|
return changetype<Wallet | null>(store.get('Wallet', id))
|
|
379
377
|
`,
|
|
380
378
|
},
|
|
381
379
|
{
|
|
382
|
-
name:
|
|
380
|
+
name: 'get id',
|
|
383
381
|
params: [],
|
|
384
|
-
returnType: new typescript_1.NamedType(
|
|
382
|
+
returnType: new typescript_1.NamedType('string'),
|
|
385
383
|
body: `let value = this.get('id')
|
|
386
384
|
if (!value || value.kind == ValueKind.NULL) {
|
|
387
385
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -391,17 +389,17 @@ describe("Schema code generator", () => {
|
|
|
391
389
|
`,
|
|
392
390
|
},
|
|
393
391
|
{
|
|
394
|
-
name:
|
|
395
|
-
params: [new typescript_1.Param(
|
|
392
|
+
name: 'set id',
|
|
393
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('string'))],
|
|
396
394
|
returnType: undefined,
|
|
397
395
|
body: `
|
|
398
396
|
this.set('id', Value.fromString(value))
|
|
399
397
|
`,
|
|
400
398
|
},
|
|
401
399
|
{
|
|
402
|
-
name:
|
|
400
|
+
name: 'get amount',
|
|
403
401
|
params: [],
|
|
404
|
-
returnType: new typescript_1.NamedType(
|
|
402
|
+
returnType: new typescript_1.NamedType('BigInt'),
|
|
405
403
|
body: `let value = this.get('amount')
|
|
406
404
|
if (!value || value.kind == ValueKind.NULL) {
|
|
407
405
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -411,17 +409,17 @@ describe("Schema code generator", () => {
|
|
|
411
409
|
`,
|
|
412
410
|
},
|
|
413
411
|
{
|
|
414
|
-
name:
|
|
415
|
-
params: [new typescript_1.Param(
|
|
412
|
+
name: 'set amount',
|
|
413
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('BigInt'))],
|
|
416
414
|
returnType: undefined,
|
|
417
415
|
body: `
|
|
418
416
|
this.set('amount', Value.fromBigInt(value))
|
|
419
417
|
`,
|
|
420
418
|
},
|
|
421
419
|
{
|
|
422
|
-
name:
|
|
420
|
+
name: 'get account',
|
|
423
421
|
params: [],
|
|
424
|
-
returnType: new typescript_1.NamedType(
|
|
422
|
+
returnType: new typescript_1.NamedType('string'),
|
|
425
423
|
body: `let value = this.get('account')
|
|
426
424
|
if (!value || value.kind == ValueKind.NULL) {
|
|
427
425
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -431,8 +429,8 @@ describe("Schema code generator", () => {
|
|
|
431
429
|
`,
|
|
432
430
|
},
|
|
433
431
|
{
|
|
434
|
-
name:
|
|
435
|
-
params: [new typescript_1.Param(
|
|
432
|
+
name: 'set account',
|
|
433
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('string'))],
|
|
436
434
|
returnType: undefined,
|
|
437
435
|
body: `
|
|
438
436
|
this.set('account', Value.fromString(value))
|
|
@@ -442,7 +440,7 @@ describe("Schema code generator", () => {
|
|
|
442
440
|
});
|
|
443
441
|
});
|
|
444
442
|
});
|
|
445
|
-
test(
|
|
443
|
+
test('Should handle references with Bytes id types', () => {
|
|
446
444
|
const codegen = createSchemaCodeGen(`
|
|
447
445
|
interface Employee {
|
|
448
446
|
id: Bytes!
|
|
@@ -464,51 +462,51 @@ describe("Schema code generator", () => {
|
|
|
464
462
|
`);
|
|
465
463
|
const generatedTypes = codegen.generateTypes();
|
|
466
464
|
testEntity(generatedTypes, {
|
|
467
|
-
name:
|
|
465
|
+
name: 'Task',
|
|
468
466
|
members: [],
|
|
469
467
|
methods: [
|
|
470
468
|
{
|
|
471
|
-
name:
|
|
472
|
-
params: [new typescript_1.Param(
|
|
469
|
+
name: 'constructor',
|
|
470
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
473
471
|
returnType: undefined,
|
|
474
472
|
body: "\n super()\n this.set('id', Value.fromBytes(id))\n ",
|
|
475
473
|
},
|
|
476
474
|
{
|
|
477
|
-
name:
|
|
475
|
+
name: 'save',
|
|
478
476
|
params: [],
|
|
479
|
-
returnType: new typescript_1.NamedType(
|
|
480
|
-
body:
|
|
477
|
+
returnType: new typescript_1.NamedType('void'),
|
|
478
|
+
body: '\n' +
|
|
481
479
|
" let id = this.get('id')\n" +
|
|
482
|
-
|
|
480
|
+
' assert(id != null,\n' +
|
|
483
481
|
" 'Cannot save Task entity without an ID')\n" +
|
|
484
|
-
|
|
485
|
-
|
|
482
|
+
' if (id) {\n' +
|
|
483
|
+
' assert(id.kind == ValueKind.BYTES,\n' +
|
|
486
484
|
" `Entities of type Task must have an ID of type Bytes but the id '${id.displayData()}' is of type ${id.displayKind()}`)\n" +
|
|
487
485
|
" store.set('Task', id.toBytes().toHexString(), this)\n" +
|
|
488
|
-
|
|
486
|
+
' }',
|
|
489
487
|
},
|
|
490
488
|
{
|
|
491
|
-
name:
|
|
489
|
+
name: 'loadInBlock',
|
|
492
490
|
static: true,
|
|
493
|
-
params: [new typescript_1.Param(
|
|
494
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
495
|
-
body:
|
|
491
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
492
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Task')),
|
|
493
|
+
body: '\n' +
|
|
496
494
|
" return changetype<Task | null>(store.get_in_block('Task', id.toHexString()))\n" +
|
|
497
|
-
|
|
495
|
+
' ',
|
|
498
496
|
},
|
|
499
497
|
{
|
|
500
|
-
name:
|
|
498
|
+
name: 'load',
|
|
501
499
|
static: true,
|
|
502
|
-
params: [new typescript_1.Param(
|
|
503
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
504
|
-
body:
|
|
500
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
501
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('Task')),
|
|
502
|
+
body: '\n' +
|
|
505
503
|
" return changetype<Task | null>(store.get('Task', id.toHexString()))\n" +
|
|
506
|
-
|
|
504
|
+
' ',
|
|
507
505
|
},
|
|
508
506
|
{
|
|
509
|
-
name:
|
|
507
|
+
name: 'get id',
|
|
510
508
|
params: [],
|
|
511
|
-
returnType: new typescript_1.NamedType(
|
|
509
|
+
returnType: new typescript_1.NamedType('Bytes'),
|
|
512
510
|
body: `let value = this.get("id")
|
|
513
511
|
if (!value || value.kind == ValueKind.NULL) {
|
|
514
512
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -517,15 +515,15 @@ describe("Schema code generator", () => {
|
|
|
517
515
|
}`,
|
|
518
516
|
},
|
|
519
517
|
{
|
|
520
|
-
name:
|
|
521
|
-
params: [new typescript_1.Param(
|
|
518
|
+
name: 'set id',
|
|
519
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('Bytes'))],
|
|
522
520
|
returnType: undefined,
|
|
523
521
|
body: "\n this.set('id', Value.fromBytes(value))\n ",
|
|
524
522
|
},
|
|
525
523
|
{
|
|
526
|
-
name:
|
|
524
|
+
name: 'get employee',
|
|
527
525
|
params: [],
|
|
528
|
-
returnType: new typescript_1.NamedType(
|
|
526
|
+
returnType: new typescript_1.NamedType('Bytes'),
|
|
529
527
|
body: `let value = this.get('employee')
|
|
530
528
|
if (!value || value.kind == ValueKind.NULL) {
|
|
531
529
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -534,15 +532,15 @@ describe("Schema code generator", () => {
|
|
|
534
532
|
}`,
|
|
535
533
|
},
|
|
536
534
|
{
|
|
537
|
-
name:
|
|
538
|
-
params: [new typescript_1.Param(
|
|
535
|
+
name: 'set employee',
|
|
536
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('Bytes'))],
|
|
539
537
|
returnType: undefined,
|
|
540
538
|
body: "\n this.set('employee', Value.fromBytes(value))\n ",
|
|
541
539
|
},
|
|
542
540
|
{
|
|
543
|
-
name:
|
|
541
|
+
name: 'get worker',
|
|
544
542
|
params: [],
|
|
545
|
-
returnType: new typescript_1.NamedType(
|
|
543
|
+
returnType: new typescript_1.NamedType('Bytes'),
|
|
546
544
|
body: `let value = this.get('worker')
|
|
547
545
|
if (!value || value.kind == ValueKind.NULL) {
|
|
548
546
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -551,21 +549,21 @@ describe("Schema code generator", () => {
|
|
|
551
549
|
}`,
|
|
552
550
|
},
|
|
553
551
|
{
|
|
554
|
-
name:
|
|
555
|
-
params: [new typescript_1.Param(
|
|
552
|
+
name: 'set worker',
|
|
553
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('Bytes'))],
|
|
556
554
|
returnType: undefined,
|
|
557
555
|
body: "\n this.set('worker', Value.fromBytes(value))\n ",
|
|
558
556
|
},
|
|
559
557
|
{
|
|
560
|
-
name:
|
|
558
|
+
name: 'get workers',
|
|
561
559
|
params: [],
|
|
562
|
-
returnType: new typescript_1.NamedType(
|
|
560
|
+
returnType: new typescript_1.NamedType('WorkerLoader'),
|
|
563
561
|
body: "\n return new WorkerLoader('Task', this.get('id')!.toBytes().toHexString(), 'workers')\n ",
|
|
564
562
|
},
|
|
565
563
|
],
|
|
566
564
|
});
|
|
567
565
|
});
|
|
568
|
-
test(
|
|
566
|
+
test('get related method for WithBytes entity', () => {
|
|
569
567
|
const codegen = createSchemaCodeGen(`
|
|
570
568
|
type WithBytes @entity {
|
|
571
569
|
id: Bytes!
|
|
@@ -579,21 +577,21 @@ describe("Schema code generator", () => {
|
|
|
579
577
|
`);
|
|
580
578
|
const generatedTypes = codegen.generateTypes();
|
|
581
579
|
testEntity(generatedTypes, {
|
|
582
|
-
name:
|
|
580
|
+
name: 'WithBytes',
|
|
583
581
|
members: [],
|
|
584
582
|
methods: [
|
|
585
583
|
{
|
|
586
|
-
name:
|
|
587
|
-
params: [new typescript_1.Param(
|
|
584
|
+
name: 'constructor',
|
|
585
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
588
586
|
returnType: undefined,
|
|
589
587
|
body: `
|
|
590
588
|
super()
|
|
591
589
|
this.set('id', Value.fromBytes(id));`,
|
|
592
590
|
},
|
|
593
591
|
{
|
|
594
|
-
name:
|
|
592
|
+
name: 'save',
|
|
595
593
|
params: [],
|
|
596
|
-
returnType: new typescript_1.NamedType(
|
|
594
|
+
returnType: new typescript_1.NamedType('void'),
|
|
597
595
|
body: `
|
|
598
596
|
let id = this.get('id');
|
|
599
597
|
assert(id != null, 'Cannot save WithBytes entity without an ID');
|
|
@@ -604,23 +602,23 @@ describe("Schema code generator", () => {
|
|
|
604
602
|
`,
|
|
605
603
|
},
|
|
606
604
|
{
|
|
607
|
-
name:
|
|
605
|
+
name: 'load',
|
|
608
606
|
static: true,
|
|
609
|
-
params: [new typescript_1.Param(
|
|
610
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
607
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
608
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('WithBytes')),
|
|
611
609
|
body: `return changetype<WithBytes | null>(store.get('WithBytes', id.toHexString()));`,
|
|
612
610
|
},
|
|
613
611
|
{
|
|
614
|
-
name:
|
|
612
|
+
name: 'loadInBlock',
|
|
615
613
|
static: true,
|
|
616
|
-
params: [new typescript_1.Param(
|
|
617
|
-
returnType: new typescript_1.NullableType(new typescript_1.NamedType(
|
|
614
|
+
params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
|
|
615
|
+
returnType: new typescript_1.NullableType(new typescript_1.NamedType('WithBytes')),
|
|
618
616
|
body: `return changetype<WithBytes | null>(store.get_in_block('WithBytes', id.toHexString()));`,
|
|
619
617
|
},
|
|
620
618
|
{
|
|
621
|
-
name:
|
|
619
|
+
name: 'get id',
|
|
622
620
|
params: [],
|
|
623
|
-
returnType: new typescript_1.NamedType(
|
|
621
|
+
returnType: new typescript_1.NamedType('Bytes'),
|
|
624
622
|
body: `let value = this.get("id")
|
|
625
623
|
if (!value || value.kind == ValueKind.NULL) {
|
|
626
624
|
throw new Error("Cannot return null for a required field.")
|
|
@@ -630,22 +628,22 @@ describe("Schema code generator", () => {
|
|
|
630
628
|
`,
|
|
631
629
|
},
|
|
632
630
|
{
|
|
633
|
-
name:
|
|
634
|
-
params: [new typescript_1.Param(
|
|
631
|
+
name: 'set id',
|
|
632
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('Bytes'))],
|
|
635
633
|
returnType: undefined,
|
|
636
634
|
body: `this.set('id', Value.fromBytes(value));`,
|
|
637
635
|
},
|
|
638
636
|
{
|
|
639
|
-
name:
|
|
637
|
+
name: 'get related',
|
|
640
638
|
params: [],
|
|
641
|
-
returnType: new typescript_1.NamedType(
|
|
639
|
+
returnType: new typescript_1.NamedType('RelatedBytesLoader'),
|
|
642
640
|
body: `return new RelatedBytesLoader('WithBytes', this.get('id')!.toBytes().toHexString(), 'related');`,
|
|
643
641
|
},
|
|
644
642
|
// Add any additional getters and setters for other fields if necessary
|
|
645
643
|
],
|
|
646
644
|
});
|
|
647
645
|
});
|
|
648
|
-
test(
|
|
646
|
+
test('no derived loader for interface', () => {
|
|
649
647
|
const codegen = createSchemaCodeGen(`
|
|
650
648
|
interface IExample {
|
|
651
649
|
id: ID!
|
|
@@ -664,9 +662,7 @@ describe("Schema code generator", () => {
|
|
|
664
662
|
examples: [IExample!]! @derivedFrom(field: "main")
|
|
665
663
|
}
|
|
666
664
|
`);
|
|
667
|
-
const generateDerivedLoaders = codegen
|
|
668
|
-
.generateDerivedLoaders()
|
|
669
|
-
.filter(Boolean);
|
|
665
|
+
const generateDerivedLoaders = codegen.generateDerivedLoaders().filter(Boolean);
|
|
670
666
|
(0, assert_1.default)(generateDerivedLoaders.length === 0);
|
|
671
667
|
});
|
|
672
668
|
});
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED