Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make generated list children non-nullable #1197

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/small-foxes-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': patch
---

make generated list children non-nullable
9 changes: 8 additions & 1 deletion packages/cli/src/scaffold/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ export function abiEvents(abi: { data: immutable.Collection<any, any> }) {

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 = ({
Expand Down
25 changes: 25 additions & 0 deletions packages/cli/tests/cli/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
[
Expand Down
27 changes: 27 additions & 0 deletions packages/cli/tests/cli/init/ethereum/abis/Airdropped.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
Original file line number Diff line number Diff line change
@@ -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.