Skip to content

Commit b533f6d

Browse files
committed
fix id conflict
1 parent 7faa309 commit b533f6d

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

packages/cli/src/scaffold/mapping.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,23 @@ export const generateFieldAssignments = ({ index, input }: { index: number; inpu
1313
[input.name || `param${index}`],
1414
);
1515

16-
type BlacklistDictionary = Record<string, string>;
17-
1816
/**
1917
* Map of input names that are reserved so we do not use them as field names to avoid conflicts
18+
* see https://github.com/graphprotocol/graph-tooling/issues/710
19+
* name => mappedName
2020
*/
21-
export const INPUT_NAMES_BLACKLIST = {
22-
/** Related to https://github.com/graphprotocol/graph-tooling/issues/710 */
23-
id: 'id',
21+
const NAMES_REMAP_DICTIONARY: Record<string, string> = {
22+
id: 'internal_id',
23+
_id: 'internal__id',
2424
} as const;
2525

26-
export const renameInput = (name: string, subgraphName: string) => {
27-
const inputMap: BlacklistDictionary = {
28-
[INPUT_NAMES_BLACKLIST.id]: `${subgraphName}_id`,
29-
};
30-
31-
return inputMap?.[name] ?? name;
26+
export const renameNameIfNeeded = (name: string) => {
27+
return NAMES_REMAP_DICTIONARY[name] ?? name;
3228
};
3329

34-
export const generateEventFieldAssignments = (event: any, contractName: string) =>
30+
export const generateEventFieldAssignments = (event: any, _contractName: string) =>
3531
event.inputs.reduce((acc: any[], input: any, index: number) => {
36-
if (Object.values(INPUT_NAMES_BLACKLIST).includes(input.name)) {
37-
input.mappedName = renameInput(input.name, contractName ?? 'contract');
38-
}
32+
input.mappedName = renameNameIfNeeded(input.name);
3933
return acc.concat(generateFieldAssignments({ input, index }));
4034
}, []);
4135

packages/cli/src/scaffold/schema.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import immutable from 'immutable';
22
import { ascTypeForProtocol, valueTypeForAsc } from '../codegen/types/index.js';
33
import * as util from '../codegen/util.js';
44
import Protocol from '../protocols/index.js';
5-
import { INPUT_NAMES_BLACKLIST, renameInput } from './mapping.js';
5+
import { renameNameIfNeeded } from './mapping.js';
66

77
export function abiEvents(abi: { data: immutable.Collection<any, any> }) {
88
return util.disambiguateNames({
@@ -73,9 +73,7 @@ export const generateEventType = (
7373
id: Bytes!
7474
${event.inputs
7575
.reduce((acc: any[], input: any, index: number) => {
76-
if (Object.values(INPUT_NAMES_BLACKLIST).includes(input.name)) {
77-
input.name = renameInput(input.name, contractName ?? 'contract');
78-
}
76+
input.name = renameNameIfNeeded(input.name);
7977
return acc.concat(generateEventFields({ input, index, protocolName }));
8078
}, [])
8179
.join('\n')}

0 commit comments

Comments
 (0)