mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-08-01 04:12:06 +00:00
Add GQL query for sync status (#159)
* Add sync status GQL query * Add sync status GQL query in codegen
This commit is contained in:
parent
5077abc90f
commit
bc1c267813
@ -95,6 +95,9 @@ export class Schema {
|
|||||||
// Add a mutation for watching a contract.
|
// Add a mutation for watching a contract.
|
||||||
this._addWatchContractMutation();
|
this._addWatchContractMutation();
|
||||||
|
|
||||||
|
// Add type and query for SyncStatus.
|
||||||
|
this._addSyncStatus();
|
||||||
|
|
||||||
// Add IPLDBlock type and queries.
|
// Add IPLDBlock type and queries.
|
||||||
this._addIPLDType();
|
this._addIPLDType();
|
||||||
this._addIPLDQuery();
|
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 {
|
_addIPLDType (): void {
|
||||||
const typeComposer = this._composer.createObjectTC({
|
const typeComposer = this._composer.createObjectTC({
|
||||||
name: 'ResultIPLDBlock',
|
name: 'ResultIPLDBlock',
|
||||||
|
@ -114,12 +114,18 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
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);
|
log('getState', blockHash, contractAddress, kind);
|
||||||
|
|
||||||
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
||||||
|
|
||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -217,12 +217,18 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
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);
|
log('getState', blockHash, contractAddress, kind);
|
||||||
|
|
||||||
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
||||||
|
|
||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -211,6 +211,13 @@ type ResultIPLDBlock {
|
|||||||
data: String!
|
data: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncStatus {
|
||||||
|
latestIndexedBlockHash: String!
|
||||||
|
latestIndexedBlockNumber: Int!
|
||||||
|
latestCanonicalBlockHash: String!
|
||||||
|
latestCanonicalBlockNumber: Int!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
||||||
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
||||||
@ -234,6 +241,7 @@ type Query {
|
|||||||
account(id: String!, block: Block_height): Account!
|
account(id: String!, block: Block_height): Account!
|
||||||
getStateByCID(cid: String!): ResultIPLDBlock
|
getStateByCID(cid: String!): ResultIPLDBlock
|
||||||
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
||||||
|
getSyncStatus: SyncStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
type Producer {
|
type Producer {
|
||||||
|
@ -97,6 +97,12 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
|
|
||||||
const events = await indexer.getEventsInRange(fromBlockNumber, toBlockNumber);
|
const events = await indexer.getEventsInRange(fromBlockNumber, toBlockNumber);
|
||||||
return events.map(event => indexer.getResultEvent(event));
|
return events.map(event => indexer.getResultEvent(event));
|
||||||
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -72,6 +72,13 @@ type WatchedEvent {
|
|||||||
event: ResultEvent!
|
event: ResultEvent!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncStatus {
|
||||||
|
latestIndexedBlockHash: String!
|
||||||
|
latestIndexedBlockNumber: Int!
|
||||||
|
latestCanonicalBlockHash: String!
|
||||||
|
latestCanonicalBlockNumber: Int!
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Queries
|
# Queries
|
||||||
#
|
#
|
||||||
@ -139,6 +146,8 @@ type Query {
|
|||||||
fromBlockNumber: Int!
|
fromBlockNumber: Int!
|
||||||
toBlockNumber: Int!
|
toBlockNumber: Int!
|
||||||
): [ResultEvent!]
|
): [ResultEvent!]
|
||||||
|
|
||||||
|
getSyncStatus: SyncStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -166,12 +166,18 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
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);
|
log('getState', blockHash, contractAddress, kind);
|
||||||
|
|
||||||
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
||||||
|
|
||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -85,6 +85,13 @@ type ResultIPLDBlock {
|
|||||||
data: String!
|
data: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncStatus {
|
||||||
|
latestIndexedBlockHash: String!
|
||||||
|
latestIndexedBlockNumber: Int!
|
||||||
|
latestCanonicalBlockHash: String!
|
||||||
|
latestCanonicalBlockNumber: Int!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
||||||
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
||||||
@ -104,6 +111,7 @@ type Query {
|
|||||||
_operatorApprovals(blockHash: String!, contractAddress: String!, key0: String!, key1: String!): ResultBoolean!
|
_operatorApprovals(blockHash: String!, contractAddress: String!, key0: String!, key1: String!): ResultBoolean!
|
||||||
getStateByCID(cid: String!): ResultIPLDBlock
|
getStateByCID(cid: String!): ResultIPLDBlock
|
||||||
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
||||||
|
getSyncStatus: SyncStatus
|
||||||
transferCount(id: String!, block: Block_height): TransferCount!
|
transferCount(id: String!, block: Block_height): TransferCount!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,12 +122,18 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
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);
|
log('getState', blockHash, contractAddress, kind);
|
||||||
|
|
||||||
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
||||||
|
|
||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -86,6 +86,13 @@ type ResultIPLDBlock {
|
|||||||
data: String!
|
data: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncStatus {
|
||||||
|
latestIndexedBlockHash: String!
|
||||||
|
latestIndexedBlockNumber: Int!
|
||||||
|
latestCanonicalBlockHash: String!
|
||||||
|
latestCanonicalBlockNumber: Int!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
||||||
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
||||||
@ -96,6 +103,7 @@ type Query {
|
|||||||
category(id: String!, block: Block_height): Category!
|
category(id: String!, block: Block_height): Category!
|
||||||
getStateByCID(cid: String!): ResultIPLDBlock
|
getStateByCID(cid: String!): ResultIPLDBlock
|
||||||
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
||||||
|
getSyncStatus: SyncStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
enum BlogKind {
|
enum BlogKind {
|
||||||
|
@ -110,7 +110,7 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
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);
|
log('getState', blockHash, contractAddress, kind);
|
||||||
|
|
||||||
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
const ipldBlock = await indexer.getPrevIPLDBlock(blockHash, contractAddress, kind);
|
||||||
@ -118,6 +118,12 @@ export const createResolvers = async (indexer: Indexer, eventWatcher: EventWatch
|
|||||||
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
return ipldBlock && ipldBlock.block.isComplete ? indexer.getResultIPLDBlock(ipldBlock) : undefined;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getSyncStatus: async () => {
|
||||||
|
log('getSyncStatus');
|
||||||
|
|
||||||
|
return indexer.getSyncStatus();
|
||||||
|
},
|
||||||
|
|
||||||
latestBlock: async () => {
|
latestBlock: async () => {
|
||||||
log('latestBlock');
|
log('latestBlock');
|
||||||
|
|
||||||
|
@ -87,6 +87,13 @@ type ResultIPLDBlock {
|
|||||||
data: String!
|
data: String!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncStatus {
|
||||||
|
latestIndexedBlockHash: String!
|
||||||
|
latestIndexedBlockNumber: Int!
|
||||||
|
latestCanonicalBlockHash: String!
|
||||||
|
latestCanonicalBlockNumber: Int!
|
||||||
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
events(blockHash: String!, contractAddress: String!, name: String): [ResultEvent!]
|
||||||
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
eventsInRange(fromBlockNumber: Int!, toBlockNumber: Int!): [ResultEvent!]
|
||||||
@ -97,6 +104,7 @@ type Query {
|
|||||||
isMember(blockHash: String!, contractAddress: String!, key0: String!): ResultBoolean!
|
isMember(blockHash: String!, contractAddress: String!, key0: String!): ResultBoolean!
|
||||||
getStateByCID(cid: String!): ResultIPLDBlock
|
getStateByCID(cid: String!): ResultIPLDBlock
|
||||||
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
getState(blockHash: String!, contractAddress: String!, kind: String): ResultIPLDBlock
|
||||||
|
getSyncStatus: SyncStatus
|
||||||
latestBlock: Block_height
|
latestBlock: Block_height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user