Skip to content

Commit

Permalink
Skip meta query generation for non-subgraph watchers (#481)
Browse files Browse the repository at this point in the history
* Skip generating meta query if non subgraph watcher

* Fix linting errors in generated watcher

* Add space for meta query

* Add meta query types after adding block height type

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
  • Loading branch information
prathamesh0 and neerajvijay1997 authored Nov 21, 2023
1 parent 7b19d38 commit d0aca37
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/codegen/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ export class Schema {
// Add type and query for SyncStatus.
this._addSyncStatus();

// Add type and query for meta data
this._addMeta();

// Build the schema.
return this._composer.buildSchema();
}
Expand Down Expand Up @@ -186,6 +183,9 @@ export class Schema {

// Add subgraph-schema entity queries to the schema composer.
this._addSubgraphSchemaQueries(subgraphTypeDefs);

// Add type and query for meta data
this._addMeta();
}

_addSubgraphSchemaQueries (subgraphTypeDefs: ReadonlyArray<DefinitionNode>): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/src/templates/config-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@
isFEVM = false

# Boolean flag to filter event logs by contracts
filterLogsByAddresses = false
filterLogsByAddresses = true
# Boolean flag to filter event logs by topics
filterLogsByTopics = false
filterLogsByTopics = true

[upstream.cache]
name = "requests"
Expand Down
7 changes: 6 additions & 1 deletion packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
{{/if}}
{{#if (subgraphPath)}}
BlockHeight,
ResultMeta,
updateSubgraphState,
dumpSubgraphState,
GraphWatcherInterface,
Expand All @@ -44,7 +45,6 @@ import {
Clients,
EthClient,
UpstreamConfig,
ResultMeta,
EthFullBlock,
EthFullTransaction,
ExtraEventData
Expand Down Expand Up @@ -153,9 +153,11 @@ export class Indexer implements IndexerInterface {
assert({{contract.contractName}}ABI);
this._abiMap.set(KIND_{{capitalize contract.contractName}}, {{contract.contractName}}ABI);

// eslint-disable-next-line prefer-const
contractInterface = new ethers.utils.Interface({{contract.contractName}}ABI);
this._contractMap.set(KIND_{{capitalize contract.contractName}}, contractInterface);

// eslint-disable-next-line prefer-const
eventSignatures = Object.values(contractInterface.events).map(value => {
return contractInterface.getEventTopic(value);
});
Expand Down Expand Up @@ -201,10 +203,12 @@ export class Indexer implements IndexerInterface {
await this._baseIndexer.fetchStateStatus();
}

{{#if (subgraphPath)}}
async getMetaData (block: BlockHeight): Promise<ResultMeta | null> {
return this._baseIndexer.getMetaData(block);
}

{{/if}}
getResultEvent (event: Event): ResultEvent {
return getResultEvent(event);
}
Expand Down Expand Up @@ -467,6 +471,7 @@ export class Indexer implements IndexerInterface {
}

{{/if}}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async triggerIndexingOnEvent (event: Event, extraData: ExtraEventData): Promise<void> {
const resultEvent = this.getResultEvent(event);

Expand Down
18 changes: 10 additions & 8 deletions packages/codegen/src/templates/resolvers-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,7 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher

return state && state.block.isComplete ? getResultState(state) : undefined;
},

getSyncStatus: async () => {
log('getSyncStatus');
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getSyncStatus').inc(1);

return indexer.getSyncStatus();
},
{{#if (subgraphPath)}}

_meta: async (
_: any,
Expand All @@ -203,6 +196,15 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
gqlQueryCount.labels('_meta').inc(1);

return indexer.getMetaData(block);
},
{{/if}}

getSyncStatus: async () => {
log('getSyncStatus');
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('getSyncStatus').inc(1);

return indexer.getSyncStatus();
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion packages/codegen/src/utils/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { loadFilesSync } from '@graphql-tools/load-files';

import { ASSET_DIR } from './constants';

const GRAPH_TS_VERSION = '0.27.0-watcher-ts-0.1.2';
const GRAPH_TS_VERSION = '0.27.0-watcher-ts-0.1.3';
const GRAPH_CLI_VERSION = '0.32.0-watcher-ts-0.1.3';

export function parseSubgraphSchema (subgraphPath: string, subgraphConfig: any): any {
Expand Down

0 comments on commit d0aca37

Please sign in to comment.