Add support for meta query in watcher GQL API (#453)

* Add a method to get meta data for watcher indexing status

* Add a flag indicating indexing error to sync status

* Codegen changes

* Clear indexing error on job-runner startup

* Fix lint errors
This commit is contained in:
prathamesh0
2023-11-07 14:37:05 +05:30
committed by GitHub
parent 8547876764
commit 5efab298a3
12 changed files with 220 additions and 53 deletions
@@ -49,6 +49,13 @@ columns:
pgType: integer
tsType: number
columnType: Column
- name: hasIndexingError
pgType: boolean
tsType: boolean
columnType: Column
columnOptions:
- option: default
value: false
imports:
- toImport:
- Entity
+30 -5
View File
@@ -3,7 +3,7 @@
//
import assert from 'assert';
import { GraphQLSchema, parse, printSchema, print, GraphQLDirective, GraphQLInt, GraphQLBoolean, GraphQLEnumType, DefinitionNode } from 'graphql';
import { GraphQLSchema, parse, printSchema, print, GraphQLDirective, GraphQLInt, GraphQLBoolean, GraphQLEnumType, DefinitionNode, GraphQLString, GraphQLNonNull } from 'graphql';
import { ObjectTypeComposer, NonNullComposer, ObjectTypeComposerDefinition, ObjectTypeComposerFieldConfigMapDefinition, SchemaComposer } from 'graphql-compose';
import { Writable } from 'stream';
import { utils } from 'ethers';
@@ -98,13 +98,16 @@ export class Schema {
// Add a mutation for watching a contract.
this._addWatchContractMutation();
// Add type and query for SyncStatus.
this._addSyncStatus();
// Add State type and queries.
this._addStateType();
this._addStateQuery();
// Add type and query for SyncStatus.
this._addSyncStatus();
// Add type and query for meta data
this._addMeta();
// Build the schema.
return this._composer.buildSchema();
}
@@ -269,7 +272,7 @@ export class Schema {
typeComposer = this._composer.createObjectTC({
name: '_Block_',
fields: {
cid: 'String!',
cid: 'String',
hash: 'String!',
number: 'Int!',
timestamp: 'Int!',
@@ -456,6 +459,28 @@ export class Schema {
});
}
_addMeta (): void {
const typeComposer = this._composer.createObjectTC({
name: '_Meta_',
fields: {
block: this._composer.getOTC('_Block_').NonNull,
deployment: { type: new GraphQLNonNull(GraphQLString) },
hasIndexingErrors: { type: new GraphQLNonNull(GraphQLBoolean) }
}
});
this._composer.addSchemaMustHaveType(typeComposer);
this._composer.Query.addFields({
_meta: {
type: this._composer.getOTC('_Meta_'),
args: {
block: BlockHeight
}
}
});
}
_addStateType (): void {
const typeComposer = this._composer.createObjectTC({
name: 'ResultState',
@@ -259,6 +259,12 @@ export class Database implements DatabaseInterface {
return this._baseDatabase.forceUpdateSyncStatus(repo, blockHash, blockNumber);
}
async updateSyncStatusIndexingError (queryRunner: QueryRunner, hasIndexingError: boolean): Promise<SyncStatus> {
const repo = queryRunner.manager.getRepository(SyncStatus);
return this._baseDatabase.updateSyncStatusIndexingError(repo, hasIndexingError);
}
async getSyncStatus (queryRunner: QueryRunner): Promise<SyncStatus | undefined> {
const repo = queryRunner.manager.getRepository(SyncStatus);
@@ -43,7 +43,8 @@ import {
DatabaseInterface,
Clients,
EthClient,
UpstreamConfig
UpstreamConfig,
ResultMeta
} from '@cerc-io/util';
{{#if (subgraphPath)}}
import { GraphWatcher } from '@cerc-io/graph-node';
@@ -197,6 +198,10 @@ export class Indexer implements IndexerInterface {
await this._baseIndexer.fetchStateStatus();
}
async getMetaData (block: BlockHeight): Promise<ResultMeta | null> {
return this._baseIndexer.getMetaData(block);
}
getResultEvent (event: Event): ResultEvent {
return getResultEvent(event);
}
@@ -660,6 +665,10 @@ export class Indexer implements IndexerInterface {
return this._baseIndexer.forceUpdateSyncStatus(blockHash, blockNumber);
}
async updateSyncStatusIndexingError (hasIndexingError: boolean): Promise<SyncStatus> {
return this._baseIndexer.updateSyncStatusIndexingError(hasIndexingError);
}
async getEvent (id: string): Promise<Event | undefined> {
return this._baseIndexer.getEvent(id);
}
@@ -168,6 +168,17 @@ export const createResolvers = async (indexerArg: IndexerInterface, eventWatcher
gqlQueryCount.labels('getSyncStatus').inc(1);
return indexer.getSyncStatus();
},
_meta: async (
_: any,
{ block = {} }: { block: BlockHeight }
) => {
log('_meta');
gqlTotalQueryCount.inc(1);
gqlQueryCount.labels('_meta').inc(1);
return indexer.getMetaData(block);
}
}
};