mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 08:54:05 +00:00
Support fragments in GQL queries for subgraph watchers (#510)
* Avoid updating latest block metrics on RPC errors * Handle fragments in subgraph GQL queries * Upgrade package versions * Move private method in util graph database --------- Co-authored-by: Prathamesh Musale <prathamesh.musale0@gmail.com>
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "@cerc-io/graph-node",
|
||||
"version": "0.2.88",
|
||||
"version": "0.2.89",
|
||||
"main": "dist/index.js",
|
||||
"license": "AGPL-3.0",
|
||||
"devDependencies": {
|
||||
"@cerc-io/solidity-mapper": "^0.2.88",
|
||||
"@cerc-io/solidity-mapper": "^0.2.89",
|
||||
"@ethersproject/providers": "^5.4.4",
|
||||
"@graphprotocol/graph-ts": "^0.22.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||
@@ -51,9 +51,9 @@
|
||||
"dependencies": {
|
||||
"@apollo/client": "^3.3.19",
|
||||
"@cerc-io/assemblyscript": "0.19.10-watcher-ts-0.1.2",
|
||||
"@cerc-io/cache": "^0.2.88",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.88",
|
||||
"@cerc-io/util": "^0.2.88",
|
||||
"@cerc-io/cache": "^0.2.89",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.89",
|
||||
"@cerc-io/util": "^0.2.89",
|
||||
"@types/json-diff": "^0.5.2",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"bn.js": "^4.11.9",
|
||||
|
||||
@@ -8,7 +8,7 @@ import debug from 'debug';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { ContractInterface, utils, providers } from 'ethers';
|
||||
import { SelectionNode } from 'graphql';
|
||||
import { GraphQLResolveInfo, SelectionNode } from 'graphql';
|
||||
|
||||
import { ResultObject } from '@cerc-io/assemblyscript/lib/loader';
|
||||
import {
|
||||
@@ -321,13 +321,15 @@ export class GraphWatcher {
|
||||
id: string,
|
||||
relationsMap: Map<any, { [key: string]: any }>,
|
||||
block: BlockHeight,
|
||||
selections: ReadonlyArray<SelectionNode> = []
|
||||
queryInfo: GraphQLResolveInfo
|
||||
): Promise<any> {
|
||||
const dbTx = await this._database.createTransactionRunner();
|
||||
|
||||
try {
|
||||
const selections = this._getSelectionsFromGQLInfo(queryInfo);
|
||||
|
||||
// Get entity from the database.
|
||||
const result = await this._database.getEntityWithRelations(dbTx, entity, id, relationsMap, block, selections);
|
||||
const result = await this._database.getEntityWithRelations(dbTx, entity, id, relationsMap, block, selections, queryInfo);
|
||||
await dbTx.commitTransaction();
|
||||
|
||||
// Resolve any field name conflicts in the entity result.
|
||||
@@ -346,7 +348,7 @@ export class GraphWatcher {
|
||||
block: BlockHeight,
|
||||
where: { [key: string]: any } = {},
|
||||
queryOptions: QueryOptions,
|
||||
selections: ReadonlyArray<SelectionNode> = []
|
||||
queryInfo: GraphQLResolveInfo
|
||||
): Promise<any> {
|
||||
const dbTx = await this._database.createTransactionRunner();
|
||||
|
||||
@@ -357,8 +359,10 @@ export class GraphWatcher {
|
||||
queryOptions.limit = DEFAULT_LIMIT;
|
||||
}
|
||||
|
||||
const selections = this._getSelectionsFromGQLInfo(queryInfo);
|
||||
|
||||
// Get entities from the database.
|
||||
const entities = await this._database.getEntities(dbTx, entity, relationsMap, block, where, queryOptions, selections);
|
||||
const entities = await this._database.getEntities(dbTx, entity, relationsMap, block, where, queryOptions, selections, queryInfo);
|
||||
await dbTx.commitTransaction();
|
||||
|
||||
return entities;
|
||||
@@ -553,6 +557,14 @@ export class GraphWatcher {
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
_getSelectionsFromGQLInfo (queryInfo: GraphQLResolveInfo): readonly SelectionNode[] {
|
||||
const [fieldNode] = queryInfo.fieldNodes;
|
||||
const selectionSet = fieldNode.selectionSet;
|
||||
assert(selectionSet, `selectionSet not present in GQL fieldNode ${fieldNode.name}`);
|
||||
|
||||
return selectionSet.selections;
|
||||
}
|
||||
}
|
||||
|
||||
export const getGraphDbAndWatcher = async (
|
||||
|
||||
Reference in New Issue
Block a user