@graphprotocol/graph-cli 0.45.0-alpha-20230403202002-10dfa2c → 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 +7 -8
- package/dist/codegen/schema.js +31 -7
- package/dist/codegen/schema.test.js +25 -8
- package/dist/commands/add.js +1 -1
- package/dist/commands/auth.js +1 -1
- package/dist/commands/build.js +1 -1
- package/dist/commands/codegen.js +1 -1
- package/dist/commands/create.js +1 -1
- package/dist/commands/deploy.js +1 -1
- package/dist/commands/init.js +1 -1
- package/dist/commands/local.js +1 -1
- package/dist/commands/remove.js +1 -1
- package/dist/commands/test.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
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-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)
|
|
@@ -74,13 +80,6 @@
|
|
|
74
80
|
- Updated dependency [`fs-extra@9.1.0` ↗︎](https://www.npmjs.com/package/fs-extra/v/9.1.0) (from
|
|
75
81
|
`9.0.0`, in `dependencies`)
|
|
76
82
|
|
|
77
|
-
- [#1237](https://github.com/graphprotocol/graph-tooling/pull/1237)
|
|
78
|
-
[`10dfa2c`](https://github.com/graphprotocol/graph-tooling/commit/10dfa2cd1a4165f9c792d76cbdd3e2483453cc7e)
|
|
79
|
-
Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
|
|
80
|
-
|
|
81
|
-
- Updated dependency [`graphql@15.8.0` ↗︎](https://www.npmjs.com/package/graphql/v/15.8.0) (from
|
|
82
|
-
`15.5.0`, in `dependencies`)
|
|
83
|
-
|
|
84
83
|
- [#1239](https://github.com/graphprotocol/graph-tooling/pull/1239)
|
|
85
84
|
[`b331905`](https://github.com/graphprotocol/graph-tooling/commit/b331905790c193183fb9cad834f488027cb3fd91)
|
|
86
85
|
Thanks [@renovate](https://github.com/apps/renovate)! - dependencies updates:
|
package/dist/codegen/schema.js
CHANGED
|
@@ -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(
|
|
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(
|
|
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
|
-
//
|
|
250
|
-
|
|
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
|
|
205
|
+
name: 'get isActive',
|
|
203
206
|
params: [],
|
|
204
|
-
returnType: new typescript_1.NamedType('
|
|
207
|
+
returnType: new typescript_1.NamedType('boolean'),
|
|
205
208
|
body: `
|
|
206
|
-
let value = this.get('
|
|
207
|
-
return value!.
|
|
209
|
+
let value = this.get('isActive')
|
|
210
|
+
return value!.toBoolean()
|
|
208
211
|
`,
|
|
209
212
|
},
|
|
210
213
|
{
|
|
211
|
-
name: 'set
|
|
212
|
-
params: [new typescript_1.Param('value', new typescript_1.NamedType('
|
|
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('
|
|
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
|
});
|
package/dist/commands/add.js
CHANGED
|
@@ -102,7 +102,6 @@ class AddCommand extends core_1.Command {
|
|
|
102
102
|
await (0, spinner_1.withSpinner)('Running codegen', 'Failed to run codegen', 'Warning during codegen', () => gluegun_1.system.run(yarn ? 'yarn codegen' : 'npm run codegen'));
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
exports.default = AddCommand;
|
|
106
105
|
AddCommand.description = 'Adds a new datasource to a subgraph.';
|
|
107
106
|
AddCommand.args = {
|
|
108
107
|
address: core_1.Args.string({
|
|
@@ -137,6 +136,7 @@ AddCommand.flags = {
|
|
|
137
136
|
default: 'networks.json',
|
|
138
137
|
}),
|
|
139
138
|
};
|
|
139
|
+
exports.default = AddCommand;
|
|
140
140
|
const getEntities = (manifest) => {
|
|
141
141
|
const dataSources = manifest.result.get('dataSources', immutable_1.default.List());
|
|
142
142
|
const templates = manifest.result.get('templates', immutable_1.default.List());
|
package/dist/commands/auth.js
CHANGED
|
@@ -42,7 +42,6 @@ class AuthCommand extends core_1.Command {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
exports.default = AuthCommand;
|
|
46
45
|
AuthCommand.description = 'Sets the deploy key to use when deploying to a Graph node.';
|
|
47
46
|
AuthCommand.args = {
|
|
48
47
|
node: core_1.Args.string(),
|
|
@@ -61,3 +60,4 @@ AuthCommand.flags = {
|
|
|
61
60
|
exclusive: ['product'],
|
|
62
61
|
}),
|
|
63
62
|
};
|
|
63
|
+
exports.default = AuthCommand;
|
package/dist/commands/build.js
CHANGED
|
@@ -78,7 +78,6 @@ class BuildCommand extends core_1.Command {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
exports.default = BuildCommand;
|
|
82
81
|
BuildCommand.description = 'Builds a subgraph and (optionally) uploads it to IPFS.';
|
|
83
82
|
BuildCommand.args = {
|
|
84
83
|
'subgraph-manifest': core_1.Args.string({
|
|
@@ -120,3 +119,4 @@ BuildCommand.flags = {
|
|
|
120
119
|
default: 'networks.json',
|
|
121
120
|
}),
|
|
122
121
|
};
|
|
122
|
+
exports.default = BuildCommand;
|
package/dist/commands/codegen.js
CHANGED
|
@@ -72,7 +72,6 @@ class CodegenCommand extends core_1.Command {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
|
-
exports.default = CodegenCommand;
|
|
76
75
|
CodegenCommand.description = 'Generates AssemblyScript types for a subgraph.';
|
|
77
76
|
CodegenCommand.args = {
|
|
78
77
|
'subgraph-manifest': core_1.Args.string({
|
|
@@ -107,3 +106,4 @@ CodegenCommand.flags = {
|
|
|
107
106
|
dependsOn: ['uncrashable'],
|
|
108
107
|
}),
|
|
109
108
|
};
|
|
109
|
+
exports.default = CodegenCommand;
|
package/dist/commands/create.js
CHANGED
|
@@ -52,7 +52,6 @@ class CreateCommand extends core_1.Command {
|
|
|
52
52
|
});
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
exports.default = CreateCommand;
|
|
56
55
|
CreateCommand.description = 'Registers a subgraph name';
|
|
57
56
|
CreateCommand.args = {
|
|
58
57
|
'subgraph-name': core_1.Args.string({
|
|
@@ -72,3 +71,4 @@ CreateCommand.flags = {
|
|
|
72
71
|
summary: 'Graph access token.',
|
|
73
72
|
}),
|
|
74
73
|
};
|
|
74
|
+
exports.default = CreateCommand;
|
package/dist/commands/deploy.js
CHANGED
|
@@ -214,7 +214,6 @@ $ graph create --node ${node} ${subgraphName}`;
|
|
|
214
214
|
}
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
exports.default = DeployCommand;
|
|
218
217
|
DeployCommand.description = 'Deploys a subgraph to a Graph node.';
|
|
219
218
|
DeployCommand.args = {
|
|
220
219
|
'subgraph-name': core_1.Args.string({
|
|
@@ -283,3 +282,4 @@ DeployCommand.flags = {
|
|
|
283
282
|
default: 'networks.json',
|
|
284
283
|
}),
|
|
285
284
|
};
|
|
285
|
+
exports.default = DeployCommand;
|
package/dist/commands/init.js
CHANGED
|
@@ -193,7 +193,6 @@ class InitCommand extends core_1.Command {
|
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
exports.default = InitCommand;
|
|
197
196
|
InitCommand.description = 'Creates a new subgraph with basic scaffolding.';
|
|
198
197
|
InitCommand.args = {
|
|
199
198
|
subgraphName: core_1.Args.string(),
|
|
@@ -265,6 +264,7 @@ InitCommand.flags = {
|
|
|
265
264
|
],
|
|
266
265
|
}),
|
|
267
266
|
};
|
|
267
|
+
exports.default = InitCommand;
|
|
268
268
|
async function processInitForm({ protocol, product, studio, node, abi, allowSimpleName, directory, contract, indexEvents, fromExample, network, subgraphName, contractName, startBlock, }) {
|
|
269
269
|
let abiFromEtherscan = undefined;
|
|
270
270
|
let abiFromFile = undefined;
|
package/dist/commands/local.js
CHANGED
|
@@ -137,7 +137,6 @@ class LocalCommand extends core_1.Command {
|
|
|
137
137
|
this.exit(result.exitCode);
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
-
exports.default = LocalCommand;
|
|
141
140
|
LocalCommand.description = 'Runs local tests against a Graph Node environment (using Ganache by default).';
|
|
142
141
|
LocalCommand.args = {
|
|
143
142
|
'local-command': core_1.Args.string({
|
|
@@ -182,6 +181,7 @@ LocalCommand.flags = {
|
|
|
182
181
|
default: 120000,
|
|
183
182
|
}),
|
|
184
183
|
};
|
|
184
|
+
exports.default = LocalCommand;
|
|
185
185
|
/**
|
|
186
186
|
* Indents all lines of a string
|
|
187
187
|
*/
|
package/dist/commands/remove.js
CHANGED
|
@@ -53,7 +53,6 @@ class RemoveCommand extends core_1.Command {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
exports.default = RemoveCommand;
|
|
57
56
|
RemoveCommand.description = 'Unregisters a subgraph name';
|
|
58
57
|
RemoveCommand.args = {
|
|
59
58
|
'subgraph-name': core_1.Args.string({
|
|
@@ -73,3 +72,4 @@ RemoveCommand.flags = {
|
|
|
73
72
|
summary: 'Graph access token.',
|
|
74
73
|
}),
|
|
75
74
|
};
|
|
75
|
+
exports.default = RemoveCommand;
|
package/dist/commands/test.js
CHANGED
|
@@ -66,7 +66,6 @@ class TestCommand extends core_1.Command {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
exports.default = TestCommand;
|
|
70
69
|
TestCommand.description = 'Runs rust binary for subgraph testing.';
|
|
71
70
|
TestCommand.args = {
|
|
72
71
|
datasource: core_1.Args.string(),
|
|
@@ -100,6 +99,7 @@ TestCommand.flags = {
|
|
|
100
99
|
char: 'v',
|
|
101
100
|
}),
|
|
102
101
|
};
|
|
102
|
+
exports.default = TestCommand;
|
|
103
103
|
function getLatestVersionFromCache(cachePath) {
|
|
104
104
|
if (gluegun_1.filesystem.exists(cachePath) == 'file') {
|
|
105
105
|
const cached = gluegun_1.filesystem.read(cachePath, 'json');
|
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-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": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"fs-extra": "9.1.0",
|
|
31
31
|
"glob": "9.3.4",
|
|
32
32
|
"gluegun": "https://github.com/edgeandnode/gluegun#v4.3.1-pin-colors-dep",
|
|
33
|
-
"graphql": "15.
|
|
33
|
+
"graphql": "15.5.0",
|
|
34
34
|
"immutable": "4.2.1",
|
|
35
35
|
"ipfs-http-client": "34.0.0",
|
|
36
36
|
"jayson": "3.7.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"spawn-command": "0.0.2-1",
|
|
58
58
|
"strip-ansi": "6.0.1",
|
|
59
59
|
"tern": "0.24.3",
|
|
60
|
-
"typescript": "^
|
|
60
|
+
"typescript": "^5.0.0"
|
|
61
61
|
},
|
|
62
62
|
"publishConfig": {
|
|
63
63
|
"access": "public"
|