@graphprotocol/graph-cli 0.60.1-alpha-20231103131932-a02eb0c → 0.61.0-alpha-20231106135106-bbe3519

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,14 +1,13 @@
1
1
  # @graphprotocol/graph-cli
2
2
 
3
- ## 0.60.1-alpha-20231103131932-a02eb0c
3
+ ## 0.61.0-alpha-20231106135106-bbe3519
4
4
 
5
- ### Patch Changes
5
+ ### Minor Changes
6
6
 
7
- - [#1490](https://github.com/graphprotocol/graph-tooling/pull/1490)
8
- [`a02eb0c`](https://github.com/graphprotocol/graph-tooling/commit/a02eb0c4070500e5c8d018741c4f4c16bbd0c6c6)
9
- Thanks [@mangas](https://github.com/mangas)! - 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`)
7
+ - [#1493](https://github.com/graphprotocol/graph-tooling/pull/1493)
8
+ [`bbe3519`](https://github.com/graphprotocol/graph-tooling/commit/bbe3519799a3b848af22f6f118e9a5b1e7da115f)
9
+ Thanks [@incrypto32](https://github.com/incrypto32)! - Fix codegen issues when using derived
10
+ loaders with Bytes as ID's
12
11
 
13
12
  ## 0.60.0
14
13
 
@@ -267,7 +267,7 @@ class SchemaCodeGenerator {
267
267
  return null;
268
268
  }
269
269
  schemaCodeGeneratorDebug.extend('_generateDerivedFieldGetter')("Found object type definition for derived field's base type: %M", obj);
270
- const idf = IdField.fromTypeDef(obj);
270
+ const idf = IdField.fromTypeDef(entityDef);
271
271
  const idIsBytes = idf.typeName() == 'Bytes';
272
272
  const toValueString = idIsBytes ? '.toBytes().toHexString()' : '.toString()';
273
273
  return tsCodegen.method(`get ${name}`, [], returnType, `
@@ -542,6 +542,86 @@ describe('Schema code generator', () => {
542
542
  ],
543
543
  });
544
544
  });
545
+ test('get related method for WithBytes entity', () => {
546
+ const codegen = createSchemaCodeGen(`
547
+ type WithBytes @entity {
548
+ id: Bytes!
549
+ related: [RelatedBytes!]! @derivedFrom(field: "related")
550
+ }
551
+
552
+ type RelatedBytes @entity {
553
+ id: ID!
554
+ related: WithBytes!
555
+ }
556
+ `);
557
+ const generatedTypes = codegen.generateTypes();
558
+ testEntity(generatedTypes, {
559
+ name: 'WithBytes',
560
+ members: [],
561
+ methods: [
562
+ {
563
+ name: 'constructor',
564
+ params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
565
+ returnType: undefined,
566
+ body: `
567
+ super()
568
+ this.set('id', Value.fromBytes(id));`,
569
+ },
570
+ {
571
+ name: 'save',
572
+ params: [],
573
+ returnType: new typescript_1.NamedType('void'),
574
+ body: `
575
+ let id = this.get('id');
576
+ assert(id != null, 'Cannot save WithBytes entity without an ID');
577
+ if (id) {
578
+ assert(id.kind == ValueKind.BYTES, \`Entities of type WithBytes must have an ID of type Bytes but the id '\${id.displayData()}' is of type \${id.displayKind()}\`);
579
+ store.set('WithBytes', id.toBytes().toHexString(), this);
580
+ }
581
+ `,
582
+ },
583
+ {
584
+ name: 'load',
585
+ static: true,
586
+ params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
587
+ returnType: new typescript_1.NullableType(new typescript_1.NamedType('WithBytes')),
588
+ body: `return changetype<WithBytes | null>(store.get('WithBytes', id.toHexString()));`,
589
+ },
590
+ {
591
+ name: 'loadInBlock',
592
+ static: true,
593
+ params: [new typescript_1.Param('id', new typescript_1.NamedType('Bytes'))],
594
+ returnType: new typescript_1.NullableType(new typescript_1.NamedType('WithBytes')),
595
+ body: `return changetype<WithBytes | null>(store.get_in_block('WithBytes', id.toHexString()));`,
596
+ },
597
+ {
598
+ name: 'get id',
599
+ params: [],
600
+ returnType: new typescript_1.NamedType('Bytes'),
601
+ body: `let value = this.get("id")
602
+ if (!value || value.kind == ValueKind.NULL) {
603
+ throw new Error("Cannot return null for a required field.")
604
+ } else {
605
+ return value.toBytes()
606
+ }
607
+ `,
608
+ },
609
+ {
610
+ name: 'set id',
611
+ params: [new typescript_1.Param('value', new typescript_1.NamedType('Bytes'))],
612
+ returnType: undefined,
613
+ body: `this.set('id', Value.fromBytes(value));`,
614
+ },
615
+ {
616
+ name: 'get related',
617
+ params: [],
618
+ returnType: new typescript_1.NamedType('RelatedBytesLoader'),
619
+ body: `return new RelatedBytesLoader('WithBytes', this.get('id')!.toBytes().toHexString(), 'related');`,
620
+ },
621
+ // Add any additional getters and setters for other fields if necessary
622
+ ],
623
+ });
624
+ });
545
625
  test('no derived loader for interface', () => {
546
626
  const codegen = createSchemaCodeGen(`
547
627
  interface IExample {
@@ -50,9 +50,9 @@ class Compiler {
50
50
  this.libsDirs = [];
51
51
  this.protocol = this.options.protocol;
52
52
  this.ABI = this.protocol.getABI();
53
- // if (options.protocol.name === 'substreams') {
54
- // return;
55
- // }
53
+ if (options.protocol.name === 'substreams') {
54
+ return;
55
+ }
56
56
  for (let dir = path_1.default.resolve(this.sourceDir);
57
57
  // Terminate after the root dir or when we have found node_modules
58
58
  dir !== undefined;
@@ -245,7 +245,7 @@ class Compiler {
245
245
  return missingHandlers;
246
246
  }
247
247
  _compileDataSourceMapping(protocol, dataSource, mappingPath, compiledFiles, spinner, validate = false) {
248
- if (protocol.name == 'substreams' && !dataSource.getIn(["mapping", "file"])) {
248
+ if (protocol.name == 'substreams') {
249
249
  return;
250
250
  }
251
251
  try {
@@ -382,9 +382,6 @@ class Compiler {
382
382
  const packageContent = fs_extra_1.default.readFileSync(packageFile);
383
383
  return path_1.default.relative(this.options.outputDir, this._writeSubgraphFile(packageFile, packageContent, this.sourceDir, this.subgraphDir(this.options.outputDir, dataSource), spinner));
384
384
  }));
385
- if (updatedDataSource.getIn(["mapping", "file"])) {
386
- updatedDataSource = updatedDataSource.updateIn(['mapping', 'file'], (mappingFile) => path_1.default.relative(this.options.outputDir, path_1.default.resolve(this.sourceDir, mappingFile)));
387
- }
388
385
  return updatedDataSource;
389
386
  }
390
387
  // The mapping file is already being written to the output
@@ -444,14 +441,6 @@ class Compiler {
444
441
  keyPath: ['dataSources', i, 'source', 'package', 'file'],
445
442
  value: await this._uploadFileToIPFS(dataSource.getIn(['source', 'package', 'file']), uploadedFiles, spinner),
446
443
  });
447
- console.log(dataSource.getIn(["mapping", "file"]));
448
- console.log(dataSource.toJS());
449
- if (dataSource.getIn(["mapping", "file"])) {
450
- updates.push({
451
- keyPath: ['dataSources', i, 'mapping', 'file'],
452
- value: await this._uploadFileToIPFS(dataSource.getIn(['mapping', 'file']), uploadedFiles, spinner),
453
- });
454
- }
455
444
  }
456
445
  }
457
446
  else {
@@ -32,18 +32,14 @@ type DataSource {
32
32
 
33
33
  type SubstreamsSource {
34
34
  package: SubstreamsPackage!
35
- startBlock: BigInt
36
35
  }
37
36
 
38
37
  type SubstreamsPackage {
39
38
  moduleName: String!
40
39
  file: String!
41
- params: String
42
40
  }
43
41
 
44
42
  type SubstreamMapping {
45
43
  apiVersion: String!
46
44
  kind: String!
47
- file: File
48
- handler: String
49
45
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.60.1-alpha-20231103131932-a02eb0c",
2
+ "version": "0.61.0-alpha-20231106135106-bbe3519",
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.60.1-alpha-20231103131932-a02eb0c",
3
+ "version": "0.61.0-alpha-20231106135106-bbe3519",
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": "3.0.3",
42
+ "prettier": "1.19.1",
43
43
  "request": "2.88.2",
44
44
  "semver": "7.4.0",
45
45
  "sync-request": "6.1.0",