@graphprotocol/graph-cli 0.61.0 → 0.61.1-alpha-20231114172419-d3c3cb4
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 +10 -0
- package/dist/codegen/schema.test.js +11 -11
- package/dist/command-helpers/scaffold.d.ts +8 -8
- package/dist/command-helpers/scaffold.js +4 -4
- package/dist/protocols/ethereum/type-generator.js +2 -2
- package/dist/scaffold/cosmos.test.js +2 -2
- package/dist/scaffold/ethereum.test.js +14 -14
- package/dist/scaffold/index.d.ts +15 -15
- package/dist/scaffold/index.js +20 -20
- package/dist/scaffold/tests.d.ts +3 -3
- package/dist/scaffold/tests.js +3 -3
- package/dist/type-generator.js +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @graphprotocol/graph-cli
|
|
2
2
|
|
|
3
|
+
## 0.61.1-alpha-20231114172419-d3c3cb4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1501](https://github.com/graphprotocol/graph-tooling/pull/1501)
|
|
8
|
+
[`6acf2a7`](https://github.com/graphprotocol/graph-tooling/commit/6acf2a7fc927857704ed734d2e6d974c3bbc772f)
|
|
9
|
+
Thanks [@saihaj](https://github.com/saihaj)! - dependencies updates:
|
|
10
|
+
- Updated dependency [`prettier@3.0.3` ↗︎](https://www.npmjs.com/package/prettier/v/3.0.3) (from
|
|
11
|
+
`1.19.1`, in `dependencies`)
|
|
12
|
+
|
|
3
13
|
## 0.61.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -32,9 +32,9 @@ 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: 'typescript', semi: false });
|
|
35
|
+
const formatTS = async (code) => prettier_1.default.format(code, { parser: 'typescript', semi: false });
|
|
36
36
|
const createSchemaCodeGen = (schema) => new schema_2.default(new schema_1.default('', schema, graphql.parse(schema)));
|
|
37
|
-
const testEntity = (generatedTypes, expectedEntity) => {
|
|
37
|
+
const testEntity = async (generatedTypes, expectedEntity) => {
|
|
38
38
|
const entity = generatedTypes.find(type => type.name === expectedEntity.name);
|
|
39
39
|
expect(entity instanceof typescript_1.Class).toBe(true);
|
|
40
40
|
expect(entity.extends).toBe('Entity');
|
|
@@ -49,7 +49,7 @@ const testEntity = (generatedTypes, expectedEntity) => {
|
|
|
49
49
|
: expect(method instanceof typescript_1.Method).toBe(true);
|
|
50
50
|
expect(method.params).toStrictEqual(expectedMethod.params);
|
|
51
51
|
expect(method.returnType).toStrictEqual(expectedMethod.returnType);
|
|
52
|
-
expect(formatTS(method.body)).toBe(formatTS(expectedMethod.body));
|
|
52
|
+
expect(await formatTS(method.body)).toBe(await formatTS(expectedMethod.body));
|
|
53
53
|
}
|
|
54
54
|
expect(methods.length).toBe(expectedEntity.methods.length);
|
|
55
55
|
};
|
|
@@ -105,8 +105,8 @@ describe('Schema code generator', () => {
|
|
|
105
105
|
// Account and Wallet
|
|
106
106
|
expect(generatedTypes.length).toBe(2);
|
|
107
107
|
});
|
|
108
|
-
test('Account is an entity with the correct methods', () => {
|
|
109
|
-
testEntity(generatedTypes, {
|
|
108
|
+
test('Account is an entity with the correct methods', async () => {
|
|
109
|
+
await testEntity(generatedTypes, {
|
|
110
110
|
name: 'Account',
|
|
111
111
|
members: [],
|
|
112
112
|
methods: [
|
|
@@ -308,8 +308,8 @@ describe('Schema code generator', () => {
|
|
|
308
308
|
],
|
|
309
309
|
});
|
|
310
310
|
});
|
|
311
|
-
test('Wallet is an entity with the correct methods', () => {
|
|
312
|
-
testEntity(generatedTypes, {
|
|
311
|
+
test('Wallet is an entity with the correct methods', async () => {
|
|
312
|
+
await testEntity(generatedTypes, {
|
|
313
313
|
name: 'Wallet',
|
|
314
314
|
members: [],
|
|
315
315
|
methods: [
|
|
@@ -419,7 +419,7 @@ describe('Schema code generator', () => {
|
|
|
419
419
|
});
|
|
420
420
|
});
|
|
421
421
|
});
|
|
422
|
-
test('Should handle references with Bytes id types', () => {
|
|
422
|
+
test('Should handle references with Bytes id types', async () => {
|
|
423
423
|
const codegen = createSchemaCodeGen(`
|
|
424
424
|
interface Employee {
|
|
425
425
|
id: Bytes!
|
|
@@ -440,7 +440,7 @@ describe('Schema code generator', () => {
|
|
|
440
440
|
}
|
|
441
441
|
`);
|
|
442
442
|
const generatedTypes = codegen.generateTypes();
|
|
443
|
-
testEntity(generatedTypes, {
|
|
443
|
+
await testEntity(generatedTypes, {
|
|
444
444
|
name: 'Task',
|
|
445
445
|
members: [],
|
|
446
446
|
methods: [
|
|
@@ -542,7 +542,7 @@ describe('Schema code generator', () => {
|
|
|
542
542
|
],
|
|
543
543
|
});
|
|
544
544
|
});
|
|
545
|
-
test('get related method for WithBytes entity', () => {
|
|
545
|
+
test('get related method for WithBytes entity', async () => {
|
|
546
546
|
const codegen = createSchemaCodeGen(`
|
|
547
547
|
type WithBytes @entity {
|
|
548
548
|
id: Bytes!
|
|
@@ -555,7 +555,7 @@ describe('Schema code generator', () => {
|
|
|
555
555
|
}
|
|
556
556
|
`);
|
|
557
557
|
const generatedTypes = codegen.generateTypes();
|
|
558
|
-
testEntity(generatedTypes, {
|
|
558
|
+
await testEntity(generatedTypes, {
|
|
559
559
|
name: 'WithBytes',
|
|
560
560
|
members: [],
|
|
561
561
|
methods: [
|
|
@@ -15,18 +15,18 @@ export declare const generateScaffold: ({ protocolInstance, abi, contract, netwo
|
|
|
15
15
|
node?: string | undefined;
|
|
16
16
|
spkgPath?: string | undefined;
|
|
17
17
|
}, spinner: Spinner) => Promise<{
|
|
18
|
-
'subgraph.yaml':
|
|
19
|
-
'schema.graphql':
|
|
20
|
-
'package.json':
|
|
18
|
+
'subgraph.yaml': string;
|
|
19
|
+
'schema.graphql': string;
|
|
20
|
+
'package.json': string;
|
|
21
21
|
'tsconfig.json'?: undefined;
|
|
22
22
|
src?: undefined;
|
|
23
23
|
abis?: undefined;
|
|
24
24
|
tests?: undefined;
|
|
25
25
|
} | {
|
|
26
|
-
'package.json':
|
|
27
|
-
'subgraph.yaml':
|
|
28
|
-
'schema.graphql':
|
|
29
|
-
'tsconfig.json':
|
|
26
|
+
'package.json': string;
|
|
27
|
+
'subgraph.yaml': string;
|
|
28
|
+
'schema.graphql': string;
|
|
29
|
+
'tsconfig.json': string;
|
|
30
30
|
src: {
|
|
31
31
|
[x: string]: Promise<string>;
|
|
32
32
|
} | undefined;
|
|
@@ -34,7 +34,7 @@ export declare const generateScaffold: ({ protocolInstance, abi, contract, netwo
|
|
|
34
34
|
[x: string]: Promise<string>;
|
|
35
35
|
} | undefined;
|
|
36
36
|
tests: {
|
|
37
|
-
[x: string]:
|
|
37
|
+
[x: string]: string;
|
|
38
38
|
} | undefined;
|
|
39
39
|
}>;
|
|
40
40
|
export declare const writeScaffold: (scaffold: any, directory: string, spinner: Spinner) => Promise<void>;
|
|
@@ -42,7 +42,7 @@ const generateScaffold = async ({ protocolInstance, abi, contract, network, subg
|
|
|
42
42
|
node,
|
|
43
43
|
spkgPath,
|
|
44
44
|
});
|
|
45
|
-
return scaffold.generate();
|
|
45
|
+
return await scaffold.generate();
|
|
46
46
|
};
|
|
47
47
|
exports.generateScaffold = generateScaffold;
|
|
48
48
|
const writeScaffoldDirectory = async (scaffold, directory, spinner) => {
|
|
@@ -70,7 +70,7 @@ const writeScaffold = async (scaffold, directory, spinner) => {
|
|
|
70
70
|
};
|
|
71
71
|
exports.writeScaffold = writeScaffold;
|
|
72
72
|
const writeABI = async (abi, contractName) => {
|
|
73
|
-
const data = prettier_1.default.format(JSON.stringify(abi.data), {
|
|
73
|
+
const data = await prettier_1.default.format(JSON.stringify(abi.data), {
|
|
74
74
|
parser: 'json',
|
|
75
75
|
});
|
|
76
76
|
await fs_extra_1.default.writeFile(`./abis/${contractName}.json`, data, 'utf-8');
|
|
@@ -82,7 +82,7 @@ const writeSchema = async (abi, protocol, schemaPath, entities, contractName) =>
|
|
|
82
82
|
.filter(event => !entities.includes(event.get('name')))
|
|
83
83
|
.toJS()
|
|
84
84
|
: [];
|
|
85
|
-
const data = prettier_1.default.format(events.map(event => (0, schema_1.generateEventType)(event, protocol.name, contractName)).join('\n\n'), {
|
|
85
|
+
const data = await prettier_1.default.format(events.map(event => (0, schema_1.generateEventType)(event, protocol.name, contractName)).join('\n\n'), {
|
|
86
86
|
parser: 'graphql',
|
|
87
87
|
});
|
|
88
88
|
await fs_extra_1.default.appendFile(schemaPath, data, { encoding: 'utf-8' });
|
|
@@ -94,7 +94,7 @@ const writeMapping = async (abi, protocol, contractName, entities) => {
|
|
|
94
94
|
.filter(event => !entities.includes(event.get('name')))
|
|
95
95
|
.toJS()
|
|
96
96
|
: [];
|
|
97
|
-
const mapping = prettier_1.default.format((0, mapping_1.generateEventIndexingHandlers)(events, contractName), {
|
|
97
|
+
const mapping = await prettier_1.default.format((0, mapping_1.generateEventIndexingHandlers)(events, contractName), {
|
|
98
98
|
parser: 'typescript',
|
|
99
99
|
semi: false,
|
|
100
100
|
});
|
|
@@ -76,7 +76,7 @@ class EthereumTypeGenerator {
|
|
|
76
76
|
try {
|
|
77
77
|
(0, spinner_1.step)(spinner, `Generate types for contract ABI:`, `${abi.abi.name} (${(0, fs_1.displayPath)(abi.abi.file)})`);
|
|
78
78
|
const codeGenerator = abi.abi.codeGenerator();
|
|
79
|
-
const code = prettier_1.default.format([
|
|
79
|
+
const code = await prettier_1.default.format([
|
|
80
80
|
typescript_1.GENERATED_FILE_NOTE,
|
|
81
81
|
...codeGenerator.generateModuleImports(),
|
|
82
82
|
...codeGenerator.generateTypes(),
|
|
@@ -101,7 +101,7 @@ class EthereumTypeGenerator {
|
|
|
101
101
|
try {
|
|
102
102
|
(0, spinner_1.step)(spinner, `Generate types for data source template ABI:`, `${abi.template.get('name')} > ${abi.abi.name} (${(0, fs_1.displayPath)(abi.abi.file)})`);
|
|
103
103
|
const codeGenerator = abi.abi.codeGenerator();
|
|
104
|
-
const code = prettier_1.default.format([
|
|
104
|
+
const code = await prettier_1.default.format([
|
|
105
105
|
typescript_1.GENERATED_FILE_NOTE,
|
|
106
106
|
...codeGenerator.generateModuleImports(),
|
|
107
107
|
...codeGenerator.generateTypes(),
|
|
@@ -13,8 +13,8 @@ const scaffoldOptions = {
|
|
|
13
13
|
};
|
|
14
14
|
const scaffold = new index_1.default(scaffoldOptions);
|
|
15
15
|
describe('Cosmos subgraph scaffolding', () => {
|
|
16
|
-
test('Manifest', () => {
|
|
17
|
-
expect(scaffold.generateManifest()).toEqual(`\
|
|
16
|
+
test('Manifest', async () => {
|
|
17
|
+
expect(await scaffold.generateManifest()).toEqual(`\
|
|
18
18
|
specVersion: 0.0.5
|
|
19
19
|
schema:
|
|
20
20
|
file: ./schema.graphql
|
|
@@ -70,8 +70,8 @@ const scaffoldWithIndexEvents = new index_1.default({
|
|
|
70
70
|
indexEvents: true,
|
|
71
71
|
});
|
|
72
72
|
describe('Ethereum subgraph scaffolding', () => {
|
|
73
|
-
test('Manifest', () => {
|
|
74
|
-
expect(scaffold.generateManifest()).toEqual(`\
|
|
73
|
+
test('Manifest', async () => {
|
|
74
|
+
expect(await scaffold.generateManifest()).toEqual(`\
|
|
75
75
|
specVersion: 0.0.5
|
|
76
76
|
schema:
|
|
77
77
|
file: ./schema.graphql
|
|
@@ -101,8 +101,8 @@ dataSources:
|
|
|
101
101
|
file: ./src/contract.ts
|
|
102
102
|
`);
|
|
103
103
|
});
|
|
104
|
-
test('Schema (default)', () => {
|
|
105
|
-
expect(scaffold.generateSchema()).toEqual(`\
|
|
104
|
+
test('Schema (default)', async () => {
|
|
105
|
+
expect(await scaffold.generateSchema()).toEqual(`\
|
|
106
106
|
type ExampleEntity @entity {
|
|
107
107
|
id: Bytes!
|
|
108
108
|
count: BigInt!
|
|
@@ -111,8 +111,8 @@ type ExampleEntity @entity {
|
|
|
111
111
|
}
|
|
112
112
|
`);
|
|
113
113
|
});
|
|
114
|
-
test('Schema (for indexing events)', () => {
|
|
115
|
-
expect(scaffoldWithIndexEvents.generateSchema()).toEqual(`\
|
|
114
|
+
test('Schema (for indexing events)', async () => {
|
|
115
|
+
expect(await scaffoldWithIndexEvents.generateSchema()).toEqual(`\
|
|
116
116
|
type ExampleEvent @entity(immutable: true) {
|
|
117
117
|
id: Bytes!
|
|
118
118
|
a: BigInt! # uint256
|
|
@@ -139,8 +139,8 @@ type ExampleEvent1 @entity(immutable: true) {
|
|
|
139
139
|
}
|
|
140
140
|
`);
|
|
141
141
|
});
|
|
142
|
-
test('Mapping (default)', () => {
|
|
143
|
-
expect(scaffold.generateMapping()).toEqual(`\
|
|
142
|
+
test('Mapping (default)', async () => {
|
|
143
|
+
expect(await scaffold.generateMapping()).toEqual(`\
|
|
144
144
|
import { BigInt } from "@graphprotocol/graph-ts"
|
|
145
145
|
import {
|
|
146
146
|
Contract,
|
|
@@ -195,8 +195,8 @@ export function handleExampleEvent(event: ExampleEvent): void {
|
|
|
195
195
|
export function handleExampleEvent1(event: ExampleEvent1): void {}
|
|
196
196
|
`);
|
|
197
197
|
});
|
|
198
|
-
test('Mapping (for indexing events)', () => {
|
|
199
|
-
expect(scaffoldWithIndexEvents.generateMapping()).toEqual(`\
|
|
198
|
+
test('Mapping (for indexing events)', async () => {
|
|
199
|
+
expect(await scaffoldWithIndexEvents.generateMapping()).toEqual(`\
|
|
200
200
|
import {
|
|
201
201
|
ExampleEvent as ExampleEventEvent,
|
|
202
202
|
ExampleEvent1 as ExampleEvent1Event
|
|
@@ -239,8 +239,8 @@ export function handleExampleEvent1(event: ExampleEvent1Event): void {
|
|
|
239
239
|
}
|
|
240
240
|
`);
|
|
241
241
|
});
|
|
242
|
-
test('Test Files (default)', () => {
|
|
243
|
-
const files = scaffoldWithIndexEvents.generateTests();
|
|
242
|
+
test('Test Files (default)', async () => {
|
|
243
|
+
const files = await scaffoldWithIndexEvents.generateTests();
|
|
244
244
|
const testFile = files?.['contract.test.ts'];
|
|
245
245
|
const utilsFile = files?.['contract-utils.ts'];
|
|
246
246
|
expect(testFile).toEqual(`\
|
|
@@ -367,8 +367,8 @@ export function createExampleEvent1Event(a: Bytes): ExampleEvent1 {
|
|
|
367
367
|
}
|
|
368
368
|
`);
|
|
369
369
|
});
|
|
370
|
-
test('Test Files (for indexing events)', () => {
|
|
371
|
-
const files = scaffoldWithIndexEvents.generateTests();
|
|
370
|
+
test('Test Files (for indexing events)', async () => {
|
|
371
|
+
const files = await scaffoldWithIndexEvents.generateTests();
|
|
372
372
|
const testFile = files?.['contract.test.ts'];
|
|
373
373
|
const utilsFile = files?.['contract-utils.ts'];
|
|
374
374
|
expect(testFile).toEqual(`\
|
package/dist/scaffold/index.d.ts
CHANGED
|
@@ -33,25 +33,25 @@ export default class Scaffold {
|
|
|
33
33
|
[x: string]: Promise<string>;
|
|
34
34
|
} | undefined;
|
|
35
35
|
generateMapping(): Promise<string>;
|
|
36
|
-
generateABIs(): {
|
|
36
|
+
generateABIs(): Promise<{
|
|
37
37
|
[x: string]: Promise<string>;
|
|
38
|
-
} | undefined
|
|
39
|
-
generateTests(): {
|
|
40
|
-
[x: string]:
|
|
41
|
-
} | undefined
|
|
42
|
-
generate(): {
|
|
43
|
-
'subgraph.yaml':
|
|
44
|
-
'schema.graphql':
|
|
45
|
-
'package.json':
|
|
38
|
+
} | undefined>;
|
|
39
|
+
generateTests(): Promise<{
|
|
40
|
+
[x: string]: string;
|
|
41
|
+
} | undefined>;
|
|
42
|
+
generate(): Promise<{
|
|
43
|
+
'subgraph.yaml': string;
|
|
44
|
+
'schema.graphql': string;
|
|
45
|
+
'package.json': string;
|
|
46
46
|
'tsconfig.json'?: undefined;
|
|
47
47
|
src?: undefined;
|
|
48
48
|
abis?: undefined;
|
|
49
49
|
tests?: undefined;
|
|
50
50
|
} | {
|
|
51
|
-
'package.json':
|
|
52
|
-
'subgraph.yaml':
|
|
53
|
-
'schema.graphql':
|
|
54
|
-
'tsconfig.json':
|
|
51
|
+
'package.json': string;
|
|
52
|
+
'subgraph.yaml': string;
|
|
53
|
+
'schema.graphql': string;
|
|
54
|
+
'tsconfig.json': string;
|
|
55
55
|
src: {
|
|
56
56
|
[x: string]: Promise<string>;
|
|
57
57
|
} | undefined;
|
|
@@ -59,7 +59,7 @@ export default class Scaffold {
|
|
|
59
59
|
[x: string]: Promise<string>;
|
|
60
60
|
} | undefined;
|
|
61
61
|
tests: {
|
|
62
|
-
[x: string]:
|
|
62
|
+
[x: string]: string;
|
|
63
63
|
} | undefined;
|
|
64
|
-
}
|
|
64
|
+
}>;
|
|
65
65
|
}
|
package/dist/scaffold/index.js
CHANGED
|
@@ -29,7 +29,7 @@ class Scaffold {
|
|
|
29
29
|
this.node = options.node;
|
|
30
30
|
this.spkgPath = options.spkgPath;
|
|
31
31
|
}
|
|
32
|
-
generatePackageJson() {
|
|
32
|
+
async generatePackageJson() {
|
|
33
33
|
return prettier_1.default.format(JSON.stringify({
|
|
34
34
|
name: (0, subgraph_1.getSubgraphBasename)(String(this.subgraphName)),
|
|
35
35
|
license: 'UNLICENSED',
|
|
@@ -52,7 +52,7 @@ class Scaffold {
|
|
|
52
52
|
devDependencies: this.protocol.hasEvents() ? { 'matchstick-as': `0.5.0` } : undefined,
|
|
53
53
|
}), { parser: 'json' });
|
|
54
54
|
}
|
|
55
|
-
generatePackageJsonForSubstreams() {
|
|
55
|
+
async generatePackageJsonForSubstreams() {
|
|
56
56
|
return prettier_1.default.format(JSON.stringify({
|
|
57
57
|
name: (0, subgraph_1.getSubgraphBasename)(String(this.subgraphName)),
|
|
58
58
|
license: 'UNLICENSED',
|
|
@@ -72,7 +72,7 @@ class Scaffold {
|
|
|
72
72
|
},
|
|
73
73
|
}), { parser: 'json' });
|
|
74
74
|
}
|
|
75
|
-
generateManifest() {
|
|
75
|
+
async generateManifest() {
|
|
76
76
|
const protocolManifest = this.protocol.getManifestScaffold();
|
|
77
77
|
return prettier_1.default.format(`
|
|
78
78
|
specVersion: 0.0.5
|
|
@@ -86,7 +86,7 @@ dataSources:
|
|
|
86
86
|
mapping: ${protocolManifest.mapping(this)}
|
|
87
87
|
`, { parser: 'yaml' });
|
|
88
88
|
}
|
|
89
|
-
generateSchema() {
|
|
89
|
+
async generateSchema() {
|
|
90
90
|
const hasEvents = this.protocol.hasEvents();
|
|
91
91
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
92
92
|
return prettier_1.default.format(hasEvents && this.indexEvents
|
|
@@ -97,7 +97,7 @@ dataSources:
|
|
|
97
97
|
parser: 'graphql',
|
|
98
98
|
});
|
|
99
99
|
}
|
|
100
|
-
generateTsConfig() {
|
|
100
|
+
async generateTsConfig() {
|
|
101
101
|
return prettier_1.default.format(JSON.stringify({
|
|
102
102
|
extends: '@graphprotocol/graph-ts/types/tsconfig.base.json',
|
|
103
103
|
include: ['src', 'tests'],
|
|
@@ -108,7 +108,7 @@ dataSources:
|
|
|
108
108
|
? { [`${gluegun_1.strings.kebabCase(this.contractName)}.ts`]: this.generateMapping() }
|
|
109
109
|
: undefined;
|
|
110
110
|
}
|
|
111
|
-
generateMapping() {
|
|
111
|
+
async generateMapping() {
|
|
112
112
|
const hasEvents = this.protocol.hasEvents();
|
|
113
113
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
114
114
|
const protocolMapping = this.protocol.getMappingScaffold();
|
|
@@ -119,7 +119,7 @@ dataSources:
|
|
|
119
119
|
events,
|
|
120
120
|
}), { parser: 'typescript', semi: false });
|
|
121
121
|
}
|
|
122
|
-
generateABIs() {
|
|
122
|
+
async generateABIs() {
|
|
123
123
|
return this.protocol.hasABIs()
|
|
124
124
|
? {
|
|
125
125
|
[`${this.contractName}.json`]: prettier_1.default.format(JSON.stringify(this.abi?.data), {
|
|
@@ -128,29 +128,29 @@ dataSources:
|
|
|
128
128
|
}
|
|
129
129
|
: undefined;
|
|
130
130
|
}
|
|
131
|
-
generateTests() {
|
|
131
|
+
async generateTests() {
|
|
132
132
|
const hasEvents = this.protocol.hasEvents();
|
|
133
133
|
const events = hasEvents ? (0, schema_1.abiEvents)(this.abi).toJS() : [];
|
|
134
134
|
return events.length > 0
|
|
135
|
-
? (0, tests_1.generateTestsFiles)(this.contractName, events, this.indexEvents)
|
|
135
|
+
? await (0, tests_1.generateTestsFiles)(this.contractName, events, this.indexEvents)
|
|
136
136
|
: undefined;
|
|
137
137
|
}
|
|
138
|
-
generate() {
|
|
138
|
+
async generate() {
|
|
139
139
|
if (this.protocol.name === 'substreams') {
|
|
140
140
|
return {
|
|
141
|
-
'subgraph.yaml': this.generateManifest(),
|
|
142
|
-
'schema.graphql': this.generateSchema(),
|
|
143
|
-
'package.json': this.generatePackageJsonForSubstreams(),
|
|
141
|
+
'subgraph.yaml': await this.generateManifest(),
|
|
142
|
+
'schema.graphql': await this.generateSchema(),
|
|
143
|
+
'package.json': await this.generatePackageJsonForSubstreams(),
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
146
|
return {
|
|
147
|
-
'package.json': this.generatePackageJson(),
|
|
148
|
-
'subgraph.yaml': this.generateManifest(),
|
|
149
|
-
'schema.graphql': this.generateSchema(),
|
|
150
|
-
'tsconfig.json': this.generateTsConfig(),
|
|
151
|
-
src: this.generateMappings(),
|
|
152
|
-
abis: this.generateABIs(),
|
|
153
|
-
tests: this.generateTests(),
|
|
147
|
+
'package.json': await this.generatePackageJson(),
|
|
148
|
+
'subgraph.yaml': await this.generateManifest(),
|
|
149
|
+
'schema.graphql': await this.generateSchema(),
|
|
150
|
+
'tsconfig.json': await this.generateTsConfig(),
|
|
151
|
+
src: await this.generateMappings(),
|
|
152
|
+
abis: await this.generateABIs(),
|
|
153
|
+
tests: await this.generateTests(),
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
}
|
package/dist/scaffold/tests.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const generateTestsFiles: (contract: any, events: any[], indexEvents?: boolean) => {
|
|
2
|
-
[x: string]:
|
|
3
|
-
}
|
|
1
|
+
export declare const generateTestsFiles: (contract: any, events: any[], indexEvents?: boolean) => Promise<{
|
|
2
|
+
[x: string]: string;
|
|
3
|
+
}>;
|
package/dist/scaffold/tests.js
CHANGED
|
@@ -15,7 +15,7 @@ const VARIABLES_VALUES = {
|
|
|
15
15
|
string: 'Example string value',
|
|
16
16
|
bool: true,
|
|
17
17
|
};
|
|
18
|
-
const generateTestsFiles = (contract, events, indexEvents) => {
|
|
18
|
+
const generateTestsFiles = async (contract, events, indexEvents) => {
|
|
19
19
|
const eventsTypes = events
|
|
20
20
|
.flatMap(event => event.inputs.map((input) => {
|
|
21
21
|
// If the asc type is Array<T> we need to check if T is a native type or a custom graph-ts type
|
|
@@ -27,8 +27,8 @@ const generateTestsFiles = (contract, events, indexEvents) => {
|
|
|
27
27
|
.filter(type => !type.startsWith('ethereum.') && !isNativeType(type));
|
|
28
28
|
const importTypes = [...new Set(eventsTypes)].join(', ');
|
|
29
29
|
return {
|
|
30
|
-
[`${gluegun_1.strings.kebabCase(contract)}.test.ts`]: prettier_1.default.format(generateExampleTest(contract, events[0], indexEvents, importTypes), { parser: 'typescript', semi: false }),
|
|
31
|
-
[`${gluegun_1.strings.kebabCase(contract)}-utils.ts`]: prettier_1.default.format(generateTestHelper(contract, events, importTypes), { parser: 'typescript', semi: false }),
|
|
30
|
+
[`${gluegun_1.strings.kebabCase(contract)}.test.ts`]: await prettier_1.default.format(generateExampleTest(contract, events[0], indexEvents, importTypes), { parser: 'typescript', semi: false }),
|
|
31
|
+
[`${gluegun_1.strings.kebabCase(contract)}-utils.ts`]: await prettier_1.default.format(generateTestHelper(contract, events, importTypes), { parser: 'typescript', semi: false }),
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
34
|
exports.generateTestsFiles = generateTestsFiles;
|
package/dist/type-generator.js
CHANGED
|
@@ -136,7 +136,7 @@ class TypeGenerator {
|
|
|
136
136
|
return await (0, spinner_1.withSpinner)(`Generate types for GraphQL schema`, `Failed to generate types for GraphQL schema`, `Warnings while generating types for GraphQL schema`, async (spinner) => {
|
|
137
137
|
// Generate TypeScript module from schema
|
|
138
138
|
const codeGenerator = schema.codeGenerator();
|
|
139
|
-
const code = prettier_1.default.format([
|
|
139
|
+
const code = await prettier_1.default.format([
|
|
140
140
|
typescript_1.GENERATED_FILE_NOTE,
|
|
141
141
|
...codeGenerator.generateModuleImports(),
|
|
142
142
|
...codeGenerator.generateTypes(),
|
|
@@ -166,7 +166,7 @@ class TypeGenerator {
|
|
|
166
166
|
return codeSegments.concat(codeGenerator.generateTypes());
|
|
167
167
|
}, immutable_1.default.List());
|
|
168
168
|
if (!codeSegments.isEmpty()) {
|
|
169
|
-
const code = prettier_1.default.format([typescript_1.GENERATED_FILE_NOTE, ...codeSegments].join('\n'), {
|
|
169
|
+
const code = await prettier_1.default.format([typescript_1.GENERATED_FILE_NOTE, ...codeSegments].join('\n'), {
|
|
170
170
|
parser: 'typescript',
|
|
171
171
|
});
|
|
172
172
|
const outputFile = path_1.default.join(this.options.outputDir, 'templates.ts');
|
package/oclif.manifest.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphprotocol/graph-cli",
|
|
3
|
-
"version": "0.61.
|
|
3
|
+
"version": "0.61.1-alpha-20231114172419-d3c3cb4",
|
|
4
4
|
"description": "CLI for building for and deploying to The Graph",
|
|
5
5
|
"license": "(Apache-2.0 OR MIT)",
|
|
6
6
|
"engines": {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"ipfs-http-client": "55.0.0",
|
|
40
40
|
"jayson": "4.0.0",
|
|
41
41
|
"js-yaml": "3.14.1",
|
|
42
|
-
"prettier": "
|
|
42
|
+
"prettier": "3.0.3",
|
|
43
43
|
"request": "2.88.2",
|
|
44
44
|
"semver": "7.4.0",
|
|
45
45
|
"sync-request": "6.1.0",
|