@graphprotocol/graph-cli 0.45.0-alpha-20230404031827-a04a9e9 → 0.45.0-alpha-20230404035238-bfb8437

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.45.0-alpha-20230404031827-a04a9e9
3
+ ## 0.45.0-alpha-20230404035238-bfb8437
4
4
 
5
5
  ### Minor Changes
6
6
 
@@ -13,6 +13,12 @@
13
13
  [`f26398e`](https://github.com/graphprotocol/graph-tooling/commit/f26398e054c556f414a1b45e92b7e4007a9b5a79)
14
14
  Thanks [@kalloc](https://github.com/kalloc)! - Support `ts` typing in tests folder
15
15
 
16
+ - [#1253](https://github.com/graphprotocol/graph-tooling/pull/1253)
17
+ [`bfb8437`](https://github.com/graphprotocol/graph-tooling/commit/bfb8437fccdde0630ae2c47735b59a663a63b4ae)
18
+ Thanks [@saihaj](https://github.com/saihaj)! - Disallow nullable primitive types. In
19
+ AssemblyScript, nullable primitive types are not allowed. An error will be thrown when it
20
+ encounters a nullable primitive type in the GraphQL Schema.
21
+
16
22
  ### Patch Changes
17
23
 
18
24
  - [#1216](https://github.com/graphprotocol/graph-tooling/pull/1216)
@@ -46,14 +52,6 @@
46
52
  - Updated dependency [`debug@4.3.4` ↗︎](https://www.npmjs.com/package/debug/v/4.3.4) (from
47
53
  `4.3.1`, in `dependencies`)
48
54
 
49
- - [#1227](https://github.com/graphprotocol/graph-tooling/pull/1227)
50
- [`7516030`](https://github.com/graphprotocol/graph-tooling/commit/751603045fc5f92d0d4b950f3a0fa263f040c401)
51
- Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
52
-
53
- - Updated dependency
54
- [`docker-compose@0.23.19` ↗︎](https://www.npmjs.com/package/docker-compose/v/0.23.19) (from
55
- `0.23.4`, in `dependencies`)
56
-
57
55
  - [#1228](https://github.com/graphprotocol/graph-tooling/pull/1228)
58
56
  [`cefbf3a`](https://github.com/graphprotocol/graph-tooling/commit/cefbf3a0d4601d79c4700eed45f1fc3ede35fbd7)
59
57
  Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
@@ -110,13 +108,6 @@
110
108
  - Updated dependency [`glob@9.3.4` ↗︎](https://www.npmjs.com/package/glob/v/9.3.4) (from `7.1.6`,
111
109
  in `dependencies`)
112
110
 
113
- - [#1251](https://github.com/graphprotocol/graph-tooling/pull/1251)
114
- [`a04a9e9`](https://github.com/graphprotocol/graph-tooling/commit/a04a9e9455a2f6575b6bc6e1a8867f78dd46ba09)
115
- Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
116
-
117
- - Updated dependency [`jayson@4.0.0` ↗︎](https://www.npmjs.com/package/jayson/v/4.0.0) (from
118
- `3.7.0`, in `dependencies`)
119
-
120
111
  - [#1207](https://github.com/graphprotocol/graph-tooling/pull/1207)
121
112
  [`ad275b3`](https://github.com/graphprotocol/graph-tooling/commit/ad275b31e635dab03cfefda00617ef9f612b01c0)
122
113
  Thanks [@saihaj](https://github.com/saihaj)! - bring back short hand for version and help
@@ -153,7 +153,11 @@ class SchemaCodeGenerator {
153
153
  const name = fieldDef.getIn(['name', 'value']);
154
154
  const gqlType = fieldDef.get('type');
155
155
  const fieldValueType = this._valueTypeFromGraphQl(gqlType);
156
- const returnType = this._typeFromGraphQl(gqlType);
156
+ const returnType = this._typeFromGraphQl({
157
+ gqlType,
158
+ entityDef: _entityDef,
159
+ fieldDef: fieldDef,
160
+ });
157
161
  const isNullable = returnType instanceof tsCodegen.NullableType;
158
162
  const getNonNullable = `return ${typesCodegen.valueToAsc('value!', fieldValueType)}`;
159
163
  const getNullable = `if (!value || value.kind == ValueKind.NULL) {
@@ -176,7 +180,7 @@ class SchemaCodeGenerator {
176
180
  return null;
177
181
  const gqlType = fieldDef.get('type');
178
182
  const fieldValueType = this._valueTypeFromGraphQl(gqlType);
179
- const paramType = this._typeFromGraphQl(gqlType);
183
+ const paramType = this._typeFromGraphQl({ gqlType, entityDef: _entityDef, fieldDef });
180
184
  const isNullable = paramType instanceof tsCodegen.NullableType;
181
185
  const paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString();
182
186
  const isArray = paramType instanceof tsCodegen.ArrayType;
@@ -236,18 +240,38 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
236
240
  }
237
241
  return gqlType.getIn(['name', 'value']);
238
242
  }
239
- _typeFromGraphQl(gqlType, nullable = true) {
243
+ _typeFromGraphQl({ gqlType, nullable = true, entityDef, fieldDef, }) {
240
244
  if (gqlType.get('kind') === 'NonNullType') {
241
- return this._typeFromGraphQl(gqlType.get('type'), false);
245
+ return this._typeFromGraphQl({
246
+ gqlType: gqlType.get('type'),
247
+ nullable: false,
248
+ entityDef,
249
+ fieldDef,
250
+ });
242
251
  }
243
252
  if (gqlType.get('kind') === 'ListType') {
244
- const type = tsCodegen.arrayType(this._typeFromGraphQl(gqlType.get('type')));
253
+ const type = tsCodegen.arrayType(this._typeFromGraphQl({ gqlType: gqlType.get('type'), entityDef, fieldDef }));
245
254
  return nullable ? tsCodegen.nullableType(type) : type;
246
255
  }
247
256
  // NamedType
248
257
  const type = tsCodegen.namedType(typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)));
249
- // In AssemblyScript, primitives cannot be nullable.
250
- return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type;
258
+ // This is helpful for debugging
259
+ const schemaCoordinate = `${entityDef.getIn(['name', 'value'])}.${fieldDef.getIn([
260
+ 'name',
261
+ 'value',
262
+ ])}`;
263
+ const gqlTypeName = gqlType.get('name').get('value');
264
+ if (nullable) {
265
+ // In AssemblyScript, primitives cannot be nullable.
266
+ if (type.isPrimitive()) {
267
+ throw Error(`A primitive type cannot be nullable. AssemblyScript does not support nullable primitives.
268
+ Consider changing the type of "${schemaCoordinate}" from "${gqlTypeName}" to "${gqlTypeName}!"`);
269
+ }
270
+ else {
271
+ return tsCodegen.nullableType(type);
272
+ }
273
+ }
274
+ return type;
251
275
  }
252
276
  }
253
277
  exports.default = SchemaCodeGenerator;
@@ -43,6 +43,9 @@ const testEntity = (generatedTypes, expectedEntity) => {
43
43
  expect(members).toStrictEqual(expectedEntity.members);
44
44
  for (const expectedMethod of expectedEntity.methods) {
45
45
  const method = methods.find((method) => method.name === expectedMethod.name);
46
+ if (!method) {
47
+ throw new Error(`Method ${expectedMethod.name} not found`);
48
+ }
46
49
  // eslint-disable-next-line @typescript-eslint/no-unused-expressions
47
50
  expectedMethod.static
48
51
  ? expect(method instanceof typescript_1.StaticMethod).toBe(true)
@@ -81,8 +84,8 @@ describe('Schema code generator', () => {
81
84
  name: String!
82
85
 
83
86
  # two primitive types (i32)
84
- age: Int
85
87
  count: Int!
88
+ isActive: Boolean!
86
89
 
87
90
  # derivedFrom
88
91
  wallets: [Wallet!] @derivedFrom(field: "account")
@@ -199,20 +202,20 @@ describe('Schema code generator', () => {
199
202
  `,
200
203
  },
201
204
  {
202
- name: 'get age',
205
+ name: 'get isActive',
203
206
  params: [],
204
- returnType: new typescript_1.NamedType('i32'),
207
+ returnType: new typescript_1.NamedType('boolean'),
205
208
  body: `
206
- let value = this.get('age')
207
- return value!.toI32()
209
+ let value = this.get('isActive')
210
+ return value!.toBoolean()
208
211
  `,
209
212
  },
210
213
  {
211
- name: 'set age',
212
- params: [new typescript_1.Param('value', new typescript_1.NamedType('i32'))],
214
+ name: 'set isActive',
215
+ params: [new typescript_1.Param('value', new typescript_1.NamedType('boolean'))],
213
216
  returnType: undefined,
214
217
  body: `
215
- this.set('age', Value.fromI32(value))
218
+ this.set('isActive', Value.fromBoolean(value))
216
219
  `,
217
220
  },
218
221
  {
@@ -441,4 +444,18 @@ describe('Schema code generator', () => {
441
444
  ],
442
445
  });
443
446
  });
447
+ test('throw error when entity has nullable primitives', () => {
448
+ const codegen = createSchemaCodeGen(`
449
+ type Account @entity {
450
+ id: ID!
451
+ isActive: Boolean
452
+ }
453
+ `);
454
+ try {
455
+ codegen.generateTypes();
456
+ }
457
+ catch (err) {
458
+ expect(err.message).toBe(`A primitive type cannot be nullable. AssemblyScript does not support nullable primitives.\nConsider changing the type of "Account.isActive" from "Boolean" to "Boolean!"`);
459
+ }
460
+ });
444
461
  });
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.45.0-alpha-20230404031827-a04a9e9",
2
+ "version": "0.45.0-alpha-20230404035238-bfb8437",
3
3
  "commands": {
4
4
  "add": {
5
5
  "id": "add",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphprotocol/graph-cli",
3
- "version": "0.45.0-alpha-20230404031827-a04a9e9",
3
+ "version": "0.45.0-alpha-20230404035238-bfb8437",
4
4
  "description": "CLI for building for and deploying to The Graph",
5
5
  "license": "(Apache-2.0 OR MIT)",
6
6
  "engines": {
@@ -25,7 +25,7 @@
25
25
  "chalk": "3.0.0",
26
26
  "chokidar": "3.5.3",
27
27
  "debug": "4.3.4",
28
- "docker-compose": "0.23.19",
28
+ "docker-compose": "0.23.4",
29
29
  "dockerode": "2.5.8",
30
30
  "fs-extra": "9.1.0",
31
31
  "glob": "9.3.4",
@@ -33,7 +33,7 @@
33
33
  "graphql": "15.5.0",
34
34
  "immutable": "4.2.1",
35
35
  "ipfs-http-client": "34.0.0",
36
- "jayson": "4.0.0",
36
+ "jayson": "3.7.0",
37
37
  "js-yaml": "3.14.1",
38
38
  "prettier": "1.19.1",
39
39
  "request": "2.88.2",