@graphprotocol/graph-cli 0.45.0-alpha-20230404035730-507217d → 0.45.0-alpha-20230404094958-e618363
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 +16 -7
- package/dist/codegen/schema.js +7 -31
- package/dist/codegen/schema.test.js +8 -25
- package/oclif.manifest.json +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
-
## 0.45.0-alpha-
|
|
3
|
+
## 0.45.0-alpha-20230404094958-e618363
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -13,12 +13,6 @@
|
|
|
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
|
-
|
|
22
16
|
### Patch Changes
|
|
23
17
|
|
|
24
18
|
- [#1216](https://github.com/graphprotocol/graph-tooling/pull/1216)
|
|
@@ -52,6 +46,14 @@
|
|
|
52
46
|
- Updated dependency [`debug@4.3.4` ↗︎](https://www.npmjs.com/package/debug/v/4.3.4) (from
|
|
53
47
|
`4.3.1`, in `dependencies`)
|
|
54
48
|
|
|
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
|
+
|
|
55
57
|
- [#1228](https://github.com/graphprotocol/graph-tooling/pull/1228)
|
|
56
58
|
[`cefbf3a`](https://github.com/graphprotocol/graph-tooling/commit/cefbf3a0d4601d79c4700eed45f1fc3ede35fbd7)
|
|
57
59
|
Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
|
|
@@ -108,6 +110,13 @@
|
|
|
108
110
|
- Updated dependency [`glob@9.3.4` ↗︎](https://www.npmjs.com/package/glob/v/9.3.4) (from `7.1.6`,
|
|
109
111
|
in `dependencies`)
|
|
110
112
|
|
|
113
|
+
- [#1255](https://github.com/graphprotocol/graph-tooling/pull/1255)
|
|
114
|
+
[`e618363`](https://github.com/graphprotocol/graph-tooling/commit/e618363ff2c5fe07989b342ebd8196bd112eff0f)
|
|
115
|
+
Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
|
|
116
|
+
|
|
117
|
+
- Updated dependency [`which@3.0.0` ↗︎](https://www.npmjs.com/package/which/v/3.0.0) (from
|
|
118
|
+
`2.0.2`, in `dependencies`)
|
|
119
|
+
|
|
111
120
|
- [#1207](https://github.com/graphprotocol/graph-tooling/pull/1207)
|
|
112
121
|
[`ad275b3`](https://github.com/graphprotocol/graph-tooling/commit/ad275b31e635dab03cfefda00617ef9f612b01c0)
|
|
113
122
|
Thanks [@saihaj](https://github.com/saihaj)! - bring back short hand for version and help
|
package/dist/codegen/schema.js
CHANGED
|
@@ -153,11 +153,7 @@ 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(
|
|
157
|
-
gqlType,
|
|
158
|
-
entityDef: _entityDef,
|
|
159
|
-
fieldDef,
|
|
160
|
-
});
|
|
156
|
+
const returnType = this._typeFromGraphQl(gqlType);
|
|
161
157
|
const isNullable = returnType instanceof tsCodegen.NullableType;
|
|
162
158
|
const getNonNullable = `return ${typesCodegen.valueToAsc('value!', fieldValueType)}`;
|
|
163
159
|
const getNullable = `if (!value || value.kind == ValueKind.NULL) {
|
|
@@ -180,7 +176,7 @@ class SchemaCodeGenerator {
|
|
|
180
176
|
return null;
|
|
181
177
|
const gqlType = fieldDef.get('type');
|
|
182
178
|
const fieldValueType = this._valueTypeFromGraphQl(gqlType);
|
|
183
|
-
const paramType = this._typeFromGraphQl(
|
|
179
|
+
const paramType = this._typeFromGraphQl(gqlType);
|
|
184
180
|
const isNullable = paramType instanceof tsCodegen.NullableType;
|
|
185
181
|
const paramTypeString = isNullable ? paramType.inner.toString() : paramType.toString();
|
|
186
182
|
const isArray = paramType instanceof tsCodegen.ArrayType;
|
|
@@ -240,38 +236,18 @@ Suggestion: add an '!' to the member type of the List, change from '[${baseType}
|
|
|
240
236
|
}
|
|
241
237
|
return gqlType.getIn(['name', 'value']);
|
|
242
238
|
}
|
|
243
|
-
_typeFromGraphQl(
|
|
239
|
+
_typeFromGraphQl(gqlType, nullable = true) {
|
|
244
240
|
if (gqlType.get('kind') === 'NonNullType') {
|
|
245
|
-
return this._typeFromGraphQl(
|
|
246
|
-
gqlType: gqlType.get('type'),
|
|
247
|
-
nullable: false,
|
|
248
|
-
entityDef,
|
|
249
|
-
fieldDef,
|
|
250
|
-
});
|
|
241
|
+
return this._typeFromGraphQl(gqlType.get('type'), false);
|
|
251
242
|
}
|
|
252
243
|
if (gqlType.get('kind') === 'ListType') {
|
|
253
|
-
const type = tsCodegen.arrayType(this._typeFromGraphQl(
|
|
244
|
+
const type = tsCodegen.arrayType(this._typeFromGraphQl(gqlType.get('type')));
|
|
254
245
|
return nullable ? tsCodegen.nullableType(type) : type;
|
|
255
246
|
}
|
|
256
247
|
// NamedType
|
|
257
248
|
const type = tsCodegen.namedType(typesCodegen.ascTypeForValue(this._resolveFieldType(gqlType)));
|
|
258
|
-
//
|
|
259
|
-
|
|
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;
|
|
249
|
+
// In AssemblyScript, primitives cannot be nullable.
|
|
250
|
+
return nullable && !type.isPrimitive() ? tsCodegen.nullableType(type) : type;
|
|
275
251
|
}
|
|
276
252
|
}
|
|
277
253
|
exports.default = SchemaCodeGenerator;
|
|
@@ -43,9 +43,6 @@ 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
|
-
}
|
|
49
46
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
50
47
|
expectedMethod.static
|
|
51
48
|
? expect(method instanceof typescript_1.StaticMethod).toBe(true)
|
|
@@ -84,8 +81,8 @@ describe('Schema code generator', () => {
|
|
|
84
81
|
name: String!
|
|
85
82
|
|
|
86
83
|
# two primitive types (i32)
|
|
84
|
+
age: Int
|
|
87
85
|
count: Int!
|
|
88
|
-
isActive: Boolean!
|
|
89
86
|
|
|
90
87
|
# derivedFrom
|
|
91
88
|
wallets: [Wallet!] @derivedFrom(field: "account")
|
|
@@ -202,20 +199,20 @@ describe('Schema code generator', () => {
|
|
|
202
199
|
`,
|
|
203
200
|
},
|
|
204
201
|
{
|
|
205
|
-
name: 'get
|
|
202
|
+
name: 'get age',
|
|
206
203
|
params: [],
|
|
207
|
-
returnType: new typescript_1.NamedType('
|
|
204
|
+
returnType: new typescript_1.NamedType('i32'),
|
|
208
205
|
body: `
|
|
209
|
-
let value = this.get('
|
|
210
|
-
return value!.
|
|
206
|
+
let value = this.get('age')
|
|
207
|
+
return value!.toI32()
|
|
211
208
|
`,
|
|
212
209
|
},
|
|
213
210
|
{
|
|
214
|
-
name: 'set
|
|
215
|
-
params: [new typescript_1.Param('value', new typescript_1.NamedType('
|
|
211
|
+
name: 'set age',
|
|
212
|
+
params: [new typescript_1.Param('value', new typescript_1.NamedType('i32'))],
|
|
216
213
|
returnType: undefined,
|
|
217
214
|
body: `
|
|
218
|
-
this.set('
|
|
215
|
+
this.set('age', Value.fromI32(value))
|
|
219
216
|
`,
|
|
220
217
|
},
|
|
221
218
|
{
|
|
@@ -444,18 +441,4 @@ describe('Schema code generator', () => {
|
|
|
444
441
|
],
|
|
445
442
|
});
|
|
446
443
|
});
|
|
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
|
-
});
|
|
461
444
|
});
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.45.0-alpha-
|
|
3
|
+
"version": "0.45.0-alpha-20230404094958-e618363",
|
|
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.
|
|
28
|
+
"docker-compose": "0.23.19",
|
|
29
29
|
"dockerode": "2.5.8",
|
|
30
30
|
"fs-extra": "9.1.0",
|
|
31
31
|
"glob": "9.3.4",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"sync-request": "6.1.0",
|
|
42
42
|
"tmp-promise": "3.0.3",
|
|
43
43
|
"web3-eth-abi": "1.7.0",
|
|
44
|
-
"which": "
|
|
44
|
+
"which": "3.0.0",
|
|
45
45
|
"yaml": "1.10.2"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"@types/jest": "^26.0.24",
|
|
51
51
|
"@types/js-yaml": "^3.12.7",
|
|
52
52
|
"@types/semver": "^7.3.13",
|
|
53
|
-
"@types/which": "^
|
|
53
|
+
"@types/which": "^3.0.0",
|
|
54
54
|
"copyfiles": "^2.4.1",
|
|
55
55
|
"jest": "26.6.3",
|
|
56
56
|
"oclif": "3.7.3",
|