Skip to content

Commit ebf6269

Browse files
Merge branch 'main' into bugfix/add-flags-not-honored
2 parents 760d96f + 91766cd commit ebf6269

File tree

10 files changed

+755
-1463
lines changed

10 files changed

+755
-1463
lines changed

.changeset/swift-jobs-count.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphprotocol/graph-cli': patch
3+
---
4+
5+
fix generated example entity id uniqueness

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ packages/cli/tests/cli/add
88
packages/cli/config/TheGraphNetworksRegistry.json
99
pnpm-lock.yaml
1010
website/src/graphql-env.d.ts
11+
renovate.json

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"lint:fix": "pnpm lint:prettier:fix && pnpm lint:eslint:fix",
2424
"lint:prettier": "prettier -c .",
2525
"lint:prettier:fix": "prettier . --write",
26+
"lint:renovate": "npx --yes --package renovate -- renovate-config-validator",
2627
"release": "pnpm build && changeset publish",
2728
"test:cli": "pnpm --filter @graphprotocol/graph-cli test",
2829
"test:ts": "pnpm --filter @graphprotocol/graph-ts test",
@@ -32,7 +33,7 @@
3233
"@changesets/changelog-github": "^0.5.0",
3334
"@changesets/cli": "^2.27.10",
3435
"@eslint/js": "^9.16.0",
35-
"@theguild/eslint-config": "0.13.1",
36+
"@theguild/eslint-config": "0.13.2",
3637
"@theguild/prettier-config": "3.0.0",
3738
"@types/node": "^22.10.1",
3839
"eslint": "9.16.0",

packages/cli/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"@whatwg-node/fetch": "^0.10.1",
4040
"assemblyscript": "0.27.31",
4141
"binary-install": "^1.1.0",
42-
"chalk": "5.3.0",
4342
"chokidar": "4.0.1",
4443
"debug": "4.3.7",
4544
"docker-compose": "1.1.0",
@@ -52,11 +51,9 @@
5251
"js-yaml": "4.1.0",
5352
"kubo-rpc-client": "^5.0.2",
5453
"open": "10.1.0",
55-
"prettier": "3.4.2",
5654
"semver": "7.6.3",
5755
"tmp-promise": "3.0.3",
5856
"web3-eth-abi": "4.4.1",
59-
"which": "5.0.0",
6057
"yaml": "2.6.1"
6158
},
6259
"devDependencies": {

packages/cli/src/compiler/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import crypto from 'node:crypto';
22
import path from 'node:path';
3-
import chalk from 'chalk';
43
import fs from 'fs-extra';
54
import * as toolbox from 'gluegun';
65
import immutable from 'immutable';
@@ -138,7 +137,7 @@ export default class Compiler {
138137

139138
completed(ipfsHashOrPath: string) {
140139
toolbox.print.info('');
141-
toolbox.print.success(`Build completed: ${chalk.blue(ipfsHashOrPath)}`);
140+
toolbox.print.success(`Build completed: ${toolbox.print.colors.blue(ipfsHashOrPath)}`);
142141
toolbox.print.info('');
143142
}
144143

packages/cli/src/protocols/ethereum/scaffold/mapping.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const generatePlaceholderHandlers = ({
1111
contractName: string;
1212
}) =>
1313
`
14-
import { BigInt } from '@graphprotocol/graph-ts'
14+
import { BigInt, Bytes } from '@graphprotocol/graph-ts'
1515
import { ${contractName}, ${events.map(event => event._alias)} }
1616
from '../generated/${contractName}/${contractName}'
1717
import { ExampleEntity } from '../generated/schema'
@@ -21,14 +21,15 @@ export const generatePlaceholderHandlers = ({
2121
index === 0
2222
? `
2323
export function handle${event._alias}(event: ${event._alias}): void {
24-
// Entities can be loaded from the store using a string ID; this ID
24+
// Entities can be loaded from the store using an ID; this ID
2525
// needs to be unique across all entities of the same type
26-
let entity = ExampleEntity.load(event.transaction.from)
26+
const id = event.transaction.hash.concat(Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex)));
27+
let entity = ExampleEntity.load(id)
2728
2829
// Entities only exist after they have been saved to the store;
2930
// \`null\` checks allow to create entities on demand
3031
if (!entity) {
31-
entity = new ExampleEntity(event.transaction.from)
32+
entity = new ExampleEntity(id)
3233
3334
// Entity fields can be set using simple assignments
3435
entity.count = BigInt.fromI32(0)

packages/cli/src/scaffold/__snapshots__/ethereum.test.ts.snap

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dataSources:
3434
`;
3535

3636
exports[`Ethereum subgraph scaffolding > Mapping (default) 1`] = `
37-
"import { BigInt } from "@graphprotocol/graph-ts"
37+
"import { BigInt, Bytes } from "@graphprotocol/graph-ts"
3838
import {
3939
Contract,
4040
ExampleEvent,
@@ -43,14 +43,17 @@ import {
4343
import { ExampleEntity } from "../generated/schema"
4444
4545
export function handleExampleEvent(event: ExampleEvent): void {
46-
// Entities can be loaded from the store using a string ID; this ID
46+
// Entities can be loaded from the store using an ID; this ID
4747
// needs to be unique across all entities of the same type
48-
let entity = ExampleEntity.load(event.transaction.from)
48+
const id = event.transaction.hash.concat(
49+
Bytes.fromByteArray(Bytes.fromBigInt(event.logIndex))
50+
)
51+
let entity = ExampleEntity.load(id)
4952
5053
// Entities only exist after they have been saved to the store;
5154
// \`null\` checks allow to create entities on demand
5255
if (!entity) {
53-
entity = new ExampleEntity(event.transaction.from)
56+
entity = new ExampleEntity(id)
5457
5558
// Entity fields can be set using simple assignments
5659
entity.count = BigInt.fromI32(0)

0 commit comments

Comments
 (0)