Add GQL query for sync status (#159)

* Add sync status GQL query

* Add sync status GQL query in codegen
This commit is contained in:
2022-08-09 13:25:46 +05:30
committed by GitHub
parent 5077abc90f
commit bc1c267813
12 changed files with 105 additions and 5 deletions
+23
View File
@@ -95,6 +95,9 @@ export class Schema {
// Add a mutation for watching a contract.
this._addWatchContractMutation();
// Add type and query for SyncStatus.
this._addSyncStatus();
// Add IPLDBlock type and queries.
this._addIPLDType();
this._addIPLDQuery();
@@ -331,6 +334,26 @@ export class Schema {
});
}
_addSyncStatus (): void {
const typeComposer = this._composer.createObjectTC({
name: 'SyncStatus',
fields: {
latestIndexedBlockHash: 'String!',
latestIndexedBlockNumber: 'Int!',
latestCanonicalBlockHash: 'String!',
latestCanonicalBlockNumber: 'Int!'
}
});
this._composer.addSchemaMustHaveType(typeComposer);
this._composer.Query.addFields({
getSyncStatus: {
type: this._composer.getOTC('SyncStatus')
}
});
}
_addIPLDType (): void {
const typeComposer = this._composer.createObjectTC({
name: 'ResultIPLDBlock',
@@ -114,12 +114,18 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
},
getState: async (_: any, { blockHash, contractAddress, kind = StateKind.Diff }: { blockHash: string, contractAddress: string, kind: string }) => {
getState: async (_: any, { blockHash, contractAddress, kind = StateKind.Checkpoint }: { blockHash: string, contractAddress: string, kind: string }) => {
log('getState', blockHash, contractAddress, kind);
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
},
getSyncStatus: async () => {
log('getSyncStatus');
return indexer.getSyncStatus();
}
}
};