Skip to content

Commit

Permalink
Add support for indexerHints in manifest (#1561)
Browse files Browse the repository at this point in the history
* Add support for indexerHints in manifest

* add changeset

* fix tests for indexer hints

* add StringOrBigInt union type for prune field

* default indexerHints.prune to auto

* update snapshot

* update snapshot

* update snapshot

---------

Co-authored-by: Saihajpreet Singh <[email protected]>
  • Loading branch information
incrypto32 and saihaj authored Jan 16, 2024
1 parent 5b05396 commit 39d5dbf
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-humans-scream.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphprotocol/graph-cli': minor
---

Add support for indexerHints in manifest
7 changes: 7 additions & 0 deletions packages/cli/src/protocols/arweave/manifest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@ scalar File
scalar BigInt
scalar JSON

union StringOrBigInt = String | BigInt

type SubgraphManifest {
specVersion: String!
schema: Schema!
description: String
repository: String
graft: Graft
dataSources: [DataSource!]!
indexerHints: IndexerHints
}

type Schema {
file: File!
}

type IndexerHints {
prune: StringOrBigInt
}

type DataSource {
kind: String!
name: String!
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/protocols/cosmos/manifest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ scalar File
scalar BigInt
scalar JSON

union StringOrBigInt = String | BigInt

type SubgraphManifest {
specVersion: String!
features: [String!]
Expand All @@ -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!
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/protocols/ethereum/manifest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ scalar BigInt
scalar Boolean
scalar JSON

union StringOrBigInt = String | BigInt

type SubgraphManifest {
specVersion: String!
features: [String!]
Expand All @@ -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!
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/src/protocols/near/manifest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ scalar File
scalar BigInt
scalar JSON

union StringOrBigInt = String | BigInt

type SubgraphManifest {
specVersion: String!
features: [String!]
Expand All @@ -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!
Expand Down
6 changes: 6 additions & 0 deletions packages/cli/src/protocols/substreams/manifest.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ scalar String
scalar File
scalar BigInt

union StringOrBigInt = String | BigInt
type SubgraphManifest {
specVersion: String!
features: [String!]
Expand All @@ -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!
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scaffold/cosmos.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scaffold/ethereum.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scaffold/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion packages/cli/src/scaffold/near.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
43 changes: 40 additions & 3 deletions packages/cli/tests/cli/__snapshots__/validation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -787,6 +784,9 @@ exports[`Validation > Invalid subgraph manifest 1`] = `
Path: templates
Expected list, found map:
field: foo
Path: specVersion
No value provided
"
`;
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/tests/cli/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ describe.concurrent(
exitCode: 1,
},
);

cliTest(
'Should parse indexerHints',
['codegen', '--skip-migrations'],
'validation/indexer-hints',
{
exitCode: 0,
},
);
},
{
timeout: 60_000,
Expand Down
7 changes: 7 additions & 0 deletions packages/cli/tests/cli/validation/indexer-hints/Abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"type": "event",
"name": "ExampleEvent",
"inputs": [{ "type": "string" }]
}
]
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type MyEntity @entity {
id: ID!
x: BigDecimal!
}
26 changes: 26 additions & 0 deletions packages/cli/tests/cli/validation/indexer-hints/subgraph.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 39d5dbf

Please sign in to comment.