diff --git a/.changeset/poor-humans-scream.md b/.changeset/poor-humans-scream.md new file mode 100644 index 00000000..af6aa049 --- /dev/null +++ b/.changeset/poor-humans-scream.md @@ -0,0 +1,5 @@ +--- +'@graphprotocol/graph-cli': minor +--- + +Add support for indexerHints in manifest diff --git a/packages/cli/src/protocols/arweave/manifest.graphql b/packages/cli/src/protocols/arweave/manifest.graphql index c95d7b30..e86ec584 100644 --- a/packages/cli/src/protocols/arweave/manifest.graphql +++ b/packages/cli/src/protocols/arweave/manifest.graphql @@ -9,6 +9,8 @@ scalar File scalar BigInt scalar JSON +union StringOrBigInt = String | BigInt + type SubgraphManifest { specVersion: String! schema: Schema! @@ -16,12 +18,17 @@ type SubgraphManifest { repository: String graft: Graft dataSources: [DataSource!]! + indexerHints: IndexerHints } type Schema { file: File! } +type IndexerHints { + prune: StringOrBigInt +} + type DataSource { kind: String! name: String! diff --git a/packages/cli/src/protocols/cosmos/manifest.graphql b/packages/cli/src/protocols/cosmos/manifest.graphql index e8f4d40a..f390dacd 100644 --- a/packages/cli/src/protocols/cosmos/manifest.graphql +++ b/packages/cli/src/protocols/cosmos/manifest.graphql @@ -9,6 +9,8 @@ scalar File scalar BigInt scalar JSON +union StringOrBigInt = String | BigInt + type SubgraphManifest { specVersion: String! features: [String!] @@ -17,12 +19,17 @@ type SubgraphManifest { repository: String graft: Graft dataSources: [DataSource!]! + indexerHints: IndexerHints } type Schema { file: File! } +type IndexerHints { + prune: StringOrBigInt +} + type DataSource { kind: String! name: String! diff --git a/packages/cli/src/protocols/ethereum/manifest.graphql b/packages/cli/src/protocols/ethereum/manifest.graphql index c6dd0cce..a0a43cf8 100644 --- a/packages/cli/src/protocols/ethereum/manifest.graphql +++ b/packages/cli/src/protocols/ethereum/manifest.graphql @@ -10,6 +10,8 @@ scalar BigInt scalar Boolean scalar JSON +union StringOrBigInt = String | BigInt + type SubgraphManifest { specVersion: String! features: [String!] @@ -19,12 +21,17 @@ type SubgraphManifest { graft: Graft dataSources: [DataSource!]! templates: [DataSourceTemplate!] + indexerHints: IndexerHints } type Schema { file: File! } +type IndexerHints { + prune: StringOrBigInt +} + type DataSource { kind: String! name: String! diff --git a/packages/cli/src/protocols/near/manifest.graphql b/packages/cli/src/protocols/near/manifest.graphql index 2cc57201..96742bde 100644 --- a/packages/cli/src/protocols/near/manifest.graphql +++ b/packages/cli/src/protocols/near/manifest.graphql @@ -9,6 +9,8 @@ scalar File scalar BigInt scalar JSON +union StringOrBigInt = String | BigInt + type SubgraphManifest { specVersion: String! features: [String!] @@ -17,12 +19,17 @@ type SubgraphManifest { repository: String graft: Graft dataSources: [DataSource!]! + indexerHints: IndexerHints } type Schema { file: File! } +type IndexerHints { + prune: StringOrBigInt +} + type DataSource { kind: String! name: String! diff --git a/packages/cli/src/protocols/substreams/manifest.graphql b/packages/cli/src/protocols/substreams/manifest.graphql index 92ec45df..364f910e 100644 --- a/packages/cli/src/protocols/substreams/manifest.graphql +++ b/packages/cli/src/protocols/substreams/manifest.graphql @@ -8,6 +8,7 @@ scalar String scalar File scalar BigInt +union StringOrBigInt = String | BigInt type SubgraphManifest { specVersion: String! features: [String!] @@ -16,12 +17,17 @@ type SubgraphManifest { repository: String graft: Graft dataSources: [DataSource!]! + indexerHints: IndexerHints } type Schema { file: File! } +type IndexerHints { + prune: StringOrBigInt +} + type DataSource { kind: String! name: String! diff --git a/packages/cli/src/scaffold/cosmos.test.ts b/packages/cli/src/scaffold/cosmos.test.ts index 540190ec..2ade65c5 100644 --- a/packages/cli/src/scaffold/cosmos.test.ts +++ b/packages/cli/src/scaffold/cosmos.test.ts @@ -15,7 +15,9 @@ const scaffold = new Scaffold(scaffoldOptions); describe.concurrent('Cosmos subgraph scaffolding', () => { test('Manifest', async () => { expect(await scaffold.generateManifest()).toEqual(`\ -specVersion: 0.0.5 +specVersion: 1.0.0 +indexerHints: + prune: auto schema: file: ./schema.graphql dataSources: diff --git a/packages/cli/src/scaffold/ethereum.test.ts b/packages/cli/src/scaffold/ethereum.test.ts index 63b83280..6567bdff 100644 --- a/packages/cli/src/scaffold/ethereum.test.ts +++ b/packages/cli/src/scaffold/ethereum.test.ts @@ -82,7 +82,9 @@ const scaffoldWithIndexEvents = new Scaffold({ describe.concurrent('Ethereum subgraph scaffolding', () => { test('Manifest', async () => { expect(await scaffold.generateManifest()).toEqual(`\ -specVersion: 0.0.5 +specVersion: 1.0.0 +indexerHints: + prune: auto schema: file: ./schema.graphql dataSources: diff --git a/packages/cli/src/scaffold/index.ts b/packages/cli/src/scaffold/index.ts index b017f65a..94582a55 100644 --- a/packages/cli/src/scaffold/index.ts +++ b/packages/cli/src/scaffold/index.ts @@ -111,7 +111,9 @@ export default class Scaffold { return await prettier.format( ` -specVersion: 0.0.5 +specVersion: 1.0.0 +indexerHints: + prune: auto schema: file: ./schema.graphql dataSources: diff --git a/packages/cli/src/scaffold/near.test.ts b/packages/cli/src/scaffold/near.test.ts index 2634760b..12cf8abd 100644 --- a/packages/cli/src/scaffold/near.test.ts +++ b/packages/cli/src/scaffold/near.test.ts @@ -16,7 +16,9 @@ const scaffold = new Scaffold(scaffoldOptions); describe.concurrent('NEAR subgraph scaffolding', () => { test('Manifest', async () => { expect(await scaffold.generateManifest()).toEqual(`\ -specVersion: 0.0.5 +specVersion: 1.0.0 +indexerHints: + prune: auto schema: file: ./schema.graphql dataSources: diff --git a/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap b/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap index b33b9e34..a17f746c 100644 --- a/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap +++ b/packages/cli/tests/cli/__snapshots__/validation.test.ts.snap @@ -762,9 +762,6 @@ exports[`Validation > Invalid subgraph manifest 1`] = ` "- Load subgraph from subgraph.yaml ✖ Failed to load subgraph from subgraph.yaml: Error in subgraph.yaml: - Path: specVersion - No value provided - Path: schema > file File does not exist: non-existent.grapqhl @@ -787,6 +784,9 @@ exports[`Validation > Invalid subgraph manifest 1`] = ` Path: templates Expected list, found map: field: foo + + Path: specVersion + No value provided " `; @@ -895,6 +895,43 @@ Types generated successfully " `; +exports[`Validation > Should parse indexerHints 1`] = ` +"- Load subgraph from subgraph.yaml +✔ Load subgraph from subgraph.yaml +- Load contract ABIs + Load contract ABI from Abi.json +- Load contract ABIs +✔ Load contract ABIs +- Generate types for contract ABIs + Generate types for contract ABI: ExampleContract (Abi.json) +- Generate types for contract ABIs + Write types to generated/ExampleSubgraph/ExampleContract.ts +- Generate types for contract ABIs +✔ Generate types for contract ABIs +- Generate types for data source templates +✔ Generate types for data source templates +- Load data source template ABIs +✔ Load data source template ABIs +- Generate types for data source template ABIs +✔ Generate types for data source template ABIs +- Load GraphQL schema from schema.graphql +✔ Load GraphQL schema from schema.graphql +- Generate types for GraphQL schema + Write types to generated/schema.ts +- Generate types for GraphQL schema +✔ Generate types for GraphQL schema +" +`; + +exports[`Validation > Should parse indexerHints 2`] = `0`; + +exports[`Validation > Should parse indexerHints 3`] = ` +" +Types generated successfully + +" +`; + exports[`Validation > Source without address is valid 1`] = ` "- Load subgraph from subgraph.yaml ✔ Load subgraph from subgraph.yaml diff --git a/packages/cli/tests/cli/validation.test.ts b/packages/cli/tests/cli/validation.test.ts index e8c1192c..9d2bfa80 100644 --- a/packages/cli/tests/cli/validation.test.ts +++ b/packages/cli/tests/cli/validation.test.ts @@ -250,6 +250,15 @@ describe.concurrent( exitCode: 1, }, ); + + cliTest( + 'Should parse indexerHints', + ['codegen', '--skip-migrations'], + 'validation/indexer-hints', + { + exitCode: 0, + }, + ); }, { timeout: 60_000, diff --git a/packages/cli/tests/cli/validation/indexer-hints/Abi.json b/packages/cli/tests/cli/validation/indexer-hints/Abi.json new file mode 100644 index 00000000..4d05f583 --- /dev/null +++ b/packages/cli/tests/cli/validation/indexer-hints/Abi.json @@ -0,0 +1,7 @@ +[ + { + "type": "event", + "name": "ExampleEvent", + "inputs": [{ "type": "string" }] + } +] diff --git a/packages/cli/tests/cli/validation/indexer-hints/mapping.ts b/packages/cli/tests/cli/validation/indexer-hints/mapping.ts new file mode 100644 index 00000000..e69de29b diff --git a/packages/cli/tests/cli/validation/indexer-hints/schema.graphql b/packages/cli/tests/cli/validation/indexer-hints/schema.graphql new file mode 100644 index 00000000..218c5b9c --- /dev/null +++ b/packages/cli/tests/cli/validation/indexer-hints/schema.graphql @@ -0,0 +1,4 @@ +type MyEntity @entity { + id: ID! + x: BigDecimal! +} diff --git a/packages/cli/tests/cli/validation/indexer-hints/subgraph.yaml b/packages/cli/tests/cli/validation/indexer-hints/subgraph.yaml new file mode 100644 index 00000000..25558759 --- /dev/null +++ b/packages/cli/tests/cli/validation/indexer-hints/subgraph.yaml @@ -0,0 +1,26 @@ +specVersion: 0.0.1 +repository: https://github.com/graphprotocol/test-subgraph +description: Test subgraph +schema: + file: ./schema.graphql +indexerHints: + prune: 100 +dataSources: + - kind: ethereum/contract + name: ExampleSubgraph + source: + abi: ExampleContract + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + file: ./mapping.ts + entities: + - ExampleEntity + abis: + - name: ExampleContract + file: ./Abi.json + eventHandlers: + - event: ExampleEvent(string) + topic0: b74a38eb2ebca56512a2bb0283f335555a4a4dac46ab998d65fd76f9027dca70 + handler: handleExampleEvent