Repository: graphprotocol/graph-tooling
Pull request #1816 (2024-12-11 05:48:12)

chore: remove redundant words in comment

changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: d599e90fef209f86da424c9223b0a427661ec052

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/depthlending/graph-tooling/new/main?filename=.changeset/poor-bears-train.md&value=---%0A%22%40graphprotocol%2Fgraph-cli%22%3A%20patch%0A---%0A%0Achore%3A%20remove%20redundant%20words%20in%20comment%0A)



Patch:
diff --git a/.changeset/short-keys-boil.md b/.changeset/short-keys-boil.md
new file mode 100644
index 00000000..f10fd68f
--- /dev/null
+++ b/.changeset/short-keys-boil.md
@@ -0,0 +1,5 @@
+---
+'@graphprotocol/graph-cli': patch
+---
+
+fix bug with clashing \_id field name in schema
diff --git a/packages/cli/src/scaffold/mapping.ts b/packages/cli/src/scaffold/mapping.ts
index 56c50dce..60244a92 100644
--- a/packages/cli/src/scaffold/mapping.ts
+++ b/packages/cli/src/scaffold/mapping.ts
@@ -13,29 +13,23 @@ export const generateFieldAssignments = ({ index, input }: { index: number; inpu
         [input.name || `param${index}`],
       );
 
-type BlacklistDictionary = Record<string, string>;
-
 /**
  * Map of input names that are reserved so we do not use them as field names to avoid conflicts
+ * see https://github.com/graphprotocol/graph-tooling/issues/710
+ * name => mappedName
  */
-export const INPUT_NAMES_BLACKLIST = {
-  /** Related to https://github.com/graphprotocol/graph-tooling/issues/710 */
-  id: 'id',
+const NAMES_REMAP_DICTIONARY: Record<string, string> = {
+  id: 'internal_id',
+  _id: 'internal__id',
 } as const;
 
-export const renameInput = (name: string, subgraphName: string) => {
-  const inputMap: BlacklistDictionary = {
-    [INPUT_NAMES_BLACKLIST.id]: `${subgraphName}_id`,
-  };
-
-  return inputMap?.[name] ?? name;
+export const renameNameIfNeeded = (name: string) => {
+  return NAMES_REMAP_DICTIONARY[name] ?? name;
 };
 
-export const generateEventFieldAssignments = (event: any, contractName: string) =>
+export const generateEventFieldAssignments = (event: any, _contractName: string) =>
   event.inputs.reduce((acc: any[], input: any, index: number) => {
-    if (Object.values(INPUT_NAMES_BLACKLIST).includes(input.name)) {
-      input.mappedName = renameInput(input.name, contractName ?? 'contract');
-    }
+    input.mappedName = renameNameIfNeeded(input.name);
     return acc.concat(generateFieldAssignments({ input, index }));
   }, []);
 
diff --git a/packages/cli/src/scaffold/schema.ts b/packages/cli/src/scaffold/schema.ts
index 8f2d4c82..e3b00b9b 100644
--- a/packages/cli/src/scaffold/schema.ts
+++ b/packages/cli/src/scaffold/schema.ts
@@ -2,7 +2,7 @@ import immutable from 'immutable';
 import { ascTypeForProtocol, valueTypeForAsc } from '../codegen/types/index.js';
 import * as util from '../codegen/util.js';
 import Protocol from '../protocols/index.js';
-import { INPUT_NAMES_BLACKLIST, renameInput } from './mapping.js';
+import { renameNameIfNeeded } from './mapping.js';
 
 export function abiEvents(abi: { data: immutable.Collection<any, any> }) {
   return util.disambiguateNames({
@@ -73,9 +73,7 @@ export const generateEventType = (
         id: Bytes!
         ${event.inputs
           .reduce((acc: any[], input: any, index: number) => {
-            if (Object.values(INPUT_NAMES_BLACKLIST).includes(input.name)) {
-              input.name = renameInput(input.name, contractName ?? 'contract');
-            }
+            input.name = renameNameIfNeeded(input.name);
             return acc.concat(generateEventFields({ input, index, protocolName }));
           }, [])
           .join('\n')}
diff --git a/packages/cli/src/validation/schema.ts b/packages/cli/src/validation/schema.ts
index c057f97f..b62cf0bd 100644
--- a/packages/cli/src/validation/schema.ts
+++ b/packages/cli/src/validation/schema.ts
@@ -679,7 +679,7 @@ const validateFulltextArgumentIncludeFields = (def: any, directive: any, field:
         loc: directive.name.loc,
         entity: def.name.value,
         directive: fulltextDirectiveName(directive),
-        message: `@fulltext argument 'include > ${field.name.value}' must be be one of: entity, fields`,
+        message: `@fulltext argument 'include > ${field.name.value}' must be one of: entity, fields`,
       }),
     ]);
   }


Test patch:
diff --git a/packages/cli/src/command-helpers/contracts.test.ts b/packages/cli/src/command-helpers/contracts.test.ts
index f2fced55..c650a181 100644
--- a/packages/cli/src/command-helpers/contracts.test.ts
+++ b/packages/cli/src/command-helpers/contracts.test.ts
@@ -22,18 +22,19 @@ const TEST_CONTRACT_START_BLOCKS = {
   moonbeam: {
     '0x011E52E4E40CF9498c79273329E8827b21E2e581': 505_060,
   },
-  moonriver: {
-    '0x3dB01570D97631f69bbb0ba39796865456Cf89A5': 800_950,
-  },
   optimism: {
     '0xc35DADB65012eC5796536bD9864eD8773aBc74C4': 7_019_815,
   },
-  celo: {
-    '0x8084936982D089130e001b470eDf58faCA445008': 10_186_627,
-  },
   gnosis: {
     '0xdDCbf776dF3dE60163066A5ddDF2277cB445E0F3': 16_655_565,
   },
+  // not stable RPCs
+  // moonriver: {
+  //   '0x3dB01570D97631f69bbb0ba39796865456Cf89A5': 800_950,
+  // },
+  // celo: {
+  //   '0x8084936982D089130e001b470eDf58faCA445008': 10_186_627,
+  // },
 
   // Skipping these networks for now because they do not support the latest etherscan contracts API or is blockScout based
 
diff --git a/packages/cli/src/scaffold/ethereum.test.ts b/packages/cli/src/scaffold/ethereum.test.ts
index 1f84f8e0..9c9eb2a6 100644
--- a/packages/cli/src/scaffold/ethereum.test.ts
+++ b/packages/cli/src/scaffold/ethereum.test.ts
@@ -26,6 +26,7 @@ const TEST_EVENT = {
       ],
     },
     { name: 'd', type: 'string', indexed: true },
+    { name: 'id', type: 'string' },
   ],
 };
 
@@ -106,7 +107,7 @@ dataSources:
         - name: Contract
           file: ./abis/Contract.json
       eventHandlers:
-        - event: ExampleEvent(indexed uint256,bytes[4],string,(uint256,bytes32,string,(uint96,string,bytes32)),indexed string)
+        - event: ExampleEvent(indexed uint256,bytes[4],string,(uint256,bytes32,string,(uint96,string,bytes32)),indexed string,string)
           handler: handleExampleEvent
         - event: ExampleEvent(bytes32)
           handler: handleExampleEvent1
@@ -139,6 +140,7 @@ type ExampleEvent @entity(immutable: true) {
   c_c3_value1: String! # string
   c_c3_value2: Bytes! # bytes32
   d: String! # string
+  internal_id: String! # string
   blockNumber: BigInt!
   blockTimestamp: BigInt!
   transactionHash: Bytes!
@@ -233,6 +235,7 @@ export function handleExampleEvent(event: ExampleEventEvent): void {
   entity.c_c3_value1 = event.params.c.c3.value1
   entity.c_c3_value2 = event.params.c.c3.value2
   entity.d = event.params.d
+  entity.internal_id = event.params.id
 
   entity.blockNumber = event.block.number
   entity.blockTimestamp = event.block.timestamp
@@ -285,7 +288,8 @@ describe("Describe entity assertions", () => {
     let param2 = "Example string value"
     let c = "ethereum.Tuple Not implemented"
     let d = "Example string value"
-    let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d)
+    let id = "Example string value"
+    let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d, id)
     handleExampleEvent(newExampleEventEvent)
   })
 
@@ -346,7 +350,8 @@ export function createExampleEventEvent(
   b: Array<Bytes>,
   param2: string,
   c: ethereum.Tuple,
-  d: string
+  d: string,
+  id: string
 ): ExampleEvent {
   let exampleEventEvent = changetype<ExampleEvent>(newMockEvent())
 
@@ -367,6 +372,9 @@ export function createExampleEventEvent(
   exampleEventEvent.parameters.push(
     new ethereum.EventParam("d", ethereum.Value.fromString(d))
   )
+  exampleEventEvent.parameters.push(
+    new ethereum.EventParam("id", ethereum.Value.fromString(id))
+  )
 
   return exampleEventEvent
 }
@@ -415,7 +423,8 @@ describe("Describe entity assertions", () => {
     let param2 = "Example string value"
     let c = "ethereum.Tuple Not implemented"
     let d = "Example string value"
-    let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d)
+    let id = "Example string value"
+    let newExampleEventEvent = createExampleEventEvent(a, b, param2, c, d, id)
     handleExampleEvent(newExampleEventEvent)
   })
 
@@ -476,7 +485,8 @@ export function createExampleEventEvent(
   b: Array<Bytes>,
   param2: string,
   c: ethereum.Tuple,
-  d: string
+  d: string,
+  id: string
 ): ExampleEvent {
   let exampleEventEvent = changetype<ExampleEvent>(newMockEvent())
 
@@ -497,6 +507,9 @@ export function createExampleEventEvent(
   exampleEventEvent.parameters.push(
     new ethereum.EventParam("d", ethereum.Value.fromString(d))
   )
+  exampleEventEvent.parameters.push(
+    new ethereum.EventParam("id", ethereum.Value.fromString(id))
+  )
 
   return exampleEventEvent
 }
diff --git a/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap b/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap
index a17f746c..2fbee61b 100644
--- a/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap
+++ b/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap
@@ -471,7 +471,7 @@ exports[`Validation > Invalid @fulltext directive 1`] = `
     IncludeMissingEntityField:
     - @fulltext argument include must have two fields, 'entity' and 'fields'
     InvalidIncludeArgumentOther:
-    - @fulltext argument 'include > other' must be be one of: entity, fields
+    - @fulltext argument 'include > other' must be one of: entity, fields
     IncludeFieldsMustBeList:
     - @fulltext argument 'include > fields' must be a list
     Other:
diff --git a/packages/cli/tests/cli/validation/invalid-fulltext-directive.stderr b/packages/cli/tests/cli/validation/invalid-fulltext-directive.stderr
index 8fe71283..f7fa7d41 100644
--- a/packages/cli/tests/cli/validation/invalid-fulltext-directive.stderr
+++ b/packages/cli/tests/cli/validation/invalid-fulltext-directive.stderr
@@ -25,7 +25,7 @@
     IncludeMissingEntityField:
     - @fulltext argument include must have two fields, 'entity' and 'fields'
     InvalidIncludeArgumentOther:
-    - @fulltext argument 'include > other' must be be one of: entity, fields
+    - @fulltext argument 'include > other' must be one of: entity, fields
     IncludeFieldsMustBeList:
     - @fulltext argument 'include > fields' must be a list
     Other: