@graphprotocol/graph-cli 0.64.0-alpha-20231211223332-0384bb9 → 0.64.0-alpha-20231213180901-055b47e
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 +1 -1
- package/dist/codegen/schema.test.js +22 -23
- package/dist/codegen/types/index.test.js +430 -431
- package/dist/codegen/util.test.js +10 -11
- package/dist/command-helpers/abi.test.js +3 -4
- package/dist/command-helpers/compiler.test.js +15 -16
- package/dist/command-helpers/network.test.js +15 -16
- package/dist/command-helpers/version.test.js +52 -45
- package/dist/protocols/ethereum/codegen/abi.test.js +32 -33
- package/dist/scaffold/cosmos.test.js +7 -8
- package/dist/scaffold/ethereum.test.js +17 -18
- package/dist/scaffold/near.test.js +7 -8
- package/dist/subgraph.d.ts +1 -1
- package/dist/subgraph.js +3 -3
- package/dist/validation/schema.d.ts +1 -1
- package/dist/validation/schema.js +34 -6
- package/dist/validation/schema.test.js +25 -26
- package/oclif.manifest.json +1 -1
- package/package.json +12 -7
package/CHANGELOG.md
CHANGED
|
@@ -29,7 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
const assert_1 = __importDefault(require("assert"));
|
|
30
30
|
const graphql = __importStar(require("graphql/language"));
|
|
31
31
|
const prettier_1 = __importDefault(require("prettier"));
|
|
32
|
-
const vitest_1 = require("vitest");
|
|
33
32
|
const schema_1 = __importDefault(require("../schema"));
|
|
34
33
|
const schema_2 = __importDefault(require("./schema"));
|
|
35
34
|
const typescript_1 = require("./typescript");
|
|
@@ -37,25 +36,25 @@ const formatTS = (code) => prettier_1.default.format(code, { parser: 'typescript
|
|
|
37
36
|
const createSchemaCodeGen = (schema) => new schema_2.default(new schema_1.default('', schema, graphql.parse(schema)));
|
|
38
37
|
const testEntity = (generatedTypes, expectedEntity) => {
|
|
39
38
|
const entity = generatedTypes.find(type => type.name === expectedEntity.name);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
expect(entity instanceof typescript_1.Class).toBe(true);
|
|
40
|
+
expect(entity.extends).toBe('Entity');
|
|
41
|
+
expect(entity.export).toBe(true);
|
|
43
42
|
const { members, methods } = entity;
|
|
44
|
-
|
|
43
|
+
expect(members).toStrictEqual(expectedEntity.members);
|
|
45
44
|
for (const expectedMethod of expectedEntity.methods) {
|
|
46
45
|
const method = methods.find((method) => method.name === expectedMethod.name);
|
|
47
46
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
48
47
|
expectedMethod.static
|
|
49
|
-
?
|
|
50
|
-
:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
? expect(method instanceof typescript_1.StaticMethod).toBe(true)
|
|
49
|
+
: expect(method instanceof typescript_1.Method).toBe(true);
|
|
50
|
+
expect(method.params).toStrictEqual(expectedMethod.params);
|
|
51
|
+
expect(method.returnType).toStrictEqual(expectedMethod.returnType);
|
|
52
|
+
expect(formatTS(method.body)).toBe(formatTS(expectedMethod.body));
|
|
54
53
|
}
|
|
55
|
-
|
|
54
|
+
expect(methods.length).toBe(expectedEntity.methods.length);
|
|
56
55
|
};
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
describe('Schema code generator', () => {
|
|
57
|
+
test('Should generate nothing for non entity types', () => {
|
|
59
58
|
const codegen = createSchemaCodeGen(`
|
|
60
59
|
type Foo {
|
|
61
60
|
foobar: Int
|
|
@@ -65,9 +64,9 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
65
64
|
barfoo: Int
|
|
66
65
|
}
|
|
67
66
|
`);
|
|
68
|
-
|
|
67
|
+
expect(codegen.generateTypes().length).toBe(0);
|
|
69
68
|
});
|
|
70
|
-
|
|
69
|
+
describe('Should generate correct classes for each entity', () => {
|
|
71
70
|
const codegen = createSchemaCodeGen(`
|
|
72
71
|
# just to be sure nothing will be generated from non-entity types alongside regular ones
|
|
73
72
|
type Foo {
|
|
@@ -100,13 +99,13 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
100
99
|
}
|
|
101
100
|
`);
|
|
102
101
|
const generatedTypes = codegen.generateTypes();
|
|
103
|
-
|
|
102
|
+
test('Foo is NOT an entity', () => {
|
|
104
103
|
const foo = generatedTypes.find((type) => type.name === 'Foo');
|
|
105
|
-
|
|
104
|
+
expect(foo).toBe(undefined);
|
|
106
105
|
// Account and Wallet
|
|
107
|
-
|
|
106
|
+
expect(generatedTypes.length).toBe(2);
|
|
108
107
|
});
|
|
109
|
-
|
|
108
|
+
test('Account is an entity with the correct methods', () => {
|
|
110
109
|
testEntity(generatedTypes, {
|
|
111
110
|
name: 'Account',
|
|
112
111
|
members: [],
|
|
@@ -309,7 +308,7 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
309
308
|
],
|
|
310
309
|
});
|
|
311
310
|
});
|
|
312
|
-
|
|
311
|
+
test('Wallet is an entity with the correct methods', () => {
|
|
313
312
|
testEntity(generatedTypes, {
|
|
314
313
|
name: 'Wallet',
|
|
315
314
|
members: [],
|
|
@@ -420,7 +419,7 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
420
419
|
});
|
|
421
420
|
});
|
|
422
421
|
});
|
|
423
|
-
|
|
422
|
+
test('Should handle references with Bytes id types', () => {
|
|
424
423
|
const codegen = createSchemaCodeGen(`
|
|
425
424
|
interface Employee {
|
|
426
425
|
id: Bytes!
|
|
@@ -543,7 +542,7 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
543
542
|
],
|
|
544
543
|
});
|
|
545
544
|
});
|
|
546
|
-
|
|
545
|
+
test('get related method for WithBytes entity', () => {
|
|
547
546
|
const codegen = createSchemaCodeGen(`
|
|
548
547
|
type WithBytes @entity {
|
|
549
548
|
id: Bytes!
|
|
@@ -623,7 +622,7 @@ vitest_1.describe.concurrent('Schema code generator', () => {
|
|
|
623
622
|
],
|
|
624
623
|
});
|
|
625
624
|
});
|
|
626
|
-
|
|
625
|
+
test('no derived loader for interface', () => {
|
|
627
626
|
const codegen = createSchemaCodeGen(`
|
|
628
627
|
interface IExample {
|
|
629
628
|
id: ID!
|