diff --git a/.changeset/small-foxes-fix.md b/.changeset/small-foxes-fix.md new file mode 100644 index 000000000..02d5b5436 --- /dev/null +++ b/.changeset/small-foxes-fix.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': patch +--- + +make generated list children non-nullable diff --git a/packages/cli/src/scaffold/ethereum.test.ts b/packages/cli/src/scaffold/ethereum.test.ts index 2827331e1..5af1a8331 100644 --- a/packages/cli/src/scaffold/ethereum.test.ts +++ b/packages/cli/src/scaffold/ethereum.test.ts @@ -117,7 +117,7 @@ type ExampleEntity @entity { id: Bytes! count: BigInt! a: BigInt! # uint256 - b: [Bytes]! # bytes[4] + b: [Bytes!]! # bytes[4] } `); }); @@ -127,7 +127,7 @@ type ExampleEntity @entity { type ExampleEvent @entity(immutable: true) { id: Bytes! a: BigInt! # uint256 - b: [Bytes]! # bytes[4] + b: [Bytes!]! # bytes[4] param2: String! # string c_c1: BigInt! # uint256 c_value1: Bytes! # bytes32 diff --git a/packages/cli/src/scaffold/schema.ts b/packages/cli/src/scaffold/schema.ts index ab5c08485..cb4b2773a 100644 --- a/packages/cli/src/scaffold/schema.ts +++ b/packages/cli/src/scaffold/schema.ts @@ -16,7 +16,14 @@ export function abiEvents(abi: { data: immutable.Collection }) { export const protocolTypeToGraphQL = (protocol: string, name: string) => { const ascType = ascTypeForProtocol(protocol, name); - return valueTypeForAsc(ascType); + // TODO: we need to figure out how to improve types + // but for now this always is returning a string + const convertedType = valueTypeForAsc(ascType) as string; + + // TODO: this is a hack to make array type non-nullable + // We should refactor the way we convert the Values from ASC to GraphQL + // For arrays we always want non-nullable children + return convertedType.endsWith(']') ? convertedType.replace(']', '!]') : convertedType; }; export const generateField = ({ diff --git a/packages/cli/tests/cli/init.test.ts b/packages/cli/tests/cli/init.test.ts index d54de4419..c3e7a2d3b 100644 --- a/packages/cli/tests/cli/init.test.ts +++ b/packages/cli/tests/cli/init.test.ts @@ -101,6 +101,31 @@ describe('Init', () => { }, ); + cliTest( + 'From contract with list items in abi', + [ + 'init', + '--protocol', + 'ethereum', + '--studio', + '--from-contract', + '0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', + '--abi', + path.join(ethereumBaseDir, 'abis', 'Airdropped.json'), + '--network', + 'mainnet', + 'user/subgraph-from-contract-with-lists-in-abi', + path.join(ethereumBaseDir, 'from-contract-with-lists-in-abi'), + ], + path.join('init', 'ethereum', 'from-contract-with-lists-in-abi'), + { + exitCode: 0, + timeout: 100_000, + cwd: ethereumBaseDir, + deleteDir: true, + }, + ); + cliTest( 'From contract with overloaded elements', [ diff --git a/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json b/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json new file mode 100644 index 000000000..da8a6f550 --- /dev/null +++ b/packages/cli/tests/cli/init/ethereum/abis/Airdropped.json @@ -0,0 +1,27 @@ +[ + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address[]", + "name": "to", + "type": "address[]" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "quantity", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "fromTokenId", + "type": "uint256" + } + ], + "name": "Airdropped", + "type": "event" + } +] diff --git a/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout b/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout new file mode 100644 index 000000000..dda50d6d5 --- /dev/null +++ b/packages/cli/tests/cli/init/ethereum/from-contract-with-lists-in-abi.stdout @@ -0,0 +1,12 @@ + +Subgraph user/subgraph-from-contract-with-lists-in-abi created in from-contract-with-lists-in-abi + +Next steps: + + 1. Run `graph auth` to authenticate with your deploy key. + + 2. Type `cd from-contract-with-lists-in-abi` to enter the subgraph. + + 3. Run `yarn deploy` to deploy the subgraph. + +Make sure to visit the documentation on https://thegraph.com/docs/ for further information.