Skip to content

Commit 93d87a8

Browse files
Fix init for events with 2d arrays as params (#1884)
* fix tests generation for [][] event params * changeset
1 parent e085e39 commit 93d87a8

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/quick-zoos-brake.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+
`graph init`: fix tests generation for events with [][] params #1878

packages/cli/src/scaffold/tests.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ const isNativeType = (type: string) => {
119119
return natives.some(rx => rx.test(type));
120120
};
121121

122-
const fetchArrayInnerType = (type: string) => type.match(/Array<(.*?)>/);
122+
// get inner type: Array<T> -> T, Array<Array<T>> -> T
123+
const fetchArrayInnerType = (type: string): RegExpMatchArray | null => {
124+
const match = type.match(/Array<(.+)>/);
125+
if (!match) return null;
126+
127+
return fetchArrayInnerType(match[1]) || match;
128+
};
123129

124130
// Generates the example test.ts file
125131
const generateExampleTest = (

0 commit comments

Comments
 (0)