mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 08:54:05 +00:00
Handle where clause on nested GQL query selections (#531)
* Handle where clause on nested GQL query selections * Handle variables for arguments on nested selections * Handle args on nested GQL query selections for plural queries * Update package versions
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
{
|
||||
"name": "@cerc-io/graph-node",
|
||||
"version": "0.2.105",
|
||||
"version": "0.2.106",
|
||||
"main": "dist/index.js",
|
||||
"license": "AGPL-3.0",
|
||||
"devDependencies": {
|
||||
"@cerc-io/solidity-mapper": "^0.2.105",
|
||||
"@cerc-io/solidity-mapper": "^0.2.106",
|
||||
"@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.105",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.105",
|
||||
"@cerc-io/util": "^0.2.105",
|
||||
"@cerc-io/cache": "^0.2.106",
|
||||
"@cerc-io/ipld-eth-client": "^0.2.106",
|
||||
"@cerc-io/util": "^0.2.106",
|
||||
"@types/json-diff": "^0.5.2",
|
||||
"@types/yargs": "^17.0.0",
|
||||
"bn.js": "^4.11.9",
|
||||
|
||||
@@ -28,10 +28,6 @@ import {
|
||||
Transaction,
|
||||
EthClient,
|
||||
DEFAULT_LIMIT,
|
||||
FILTER_CHANGE_BLOCK,
|
||||
Where,
|
||||
Filter,
|
||||
OPERATOR_MAP,
|
||||
ExtraEventData,
|
||||
EthFullTransaction
|
||||
} from '@cerc-io/util';
|
||||
@@ -379,7 +375,7 @@ export class GraphWatcher {
|
||||
const dbTx = await this._database.createTransactionRunner();
|
||||
|
||||
try {
|
||||
where = this._buildFilter(where);
|
||||
where = this._database.buildFilter(where);
|
||||
|
||||
if (!queryOptions.limit) {
|
||||
queryOptions.limit = DEFAULT_LIMIT;
|
||||
@@ -514,76 +510,6 @@ export class GraphWatcher {
|
||||
return transaction;
|
||||
}
|
||||
|
||||
_buildFilter (where: { [key: string]: any } = {}): Where {
|
||||
return Object.entries(where).reduce((acc: Where, [fieldWithSuffix, value]) => {
|
||||
if (fieldWithSuffix === FILTER_CHANGE_BLOCK) {
|
||||
assert(value.number_gte && typeof value.number_gte === 'number');
|
||||
|
||||
acc[FILTER_CHANGE_BLOCK] = [{
|
||||
value: value.number_gte,
|
||||
not: false
|
||||
}];
|
||||
|
||||
return acc;
|
||||
}
|
||||
|
||||
if (['and', 'or'].includes(fieldWithSuffix)) {
|
||||
assert(Array.isArray(value));
|
||||
|
||||
// Parse all the comibations given in the array
|
||||
acc[fieldWithSuffix] = value.map(w => {
|
||||
return this._buildFilter(w);
|
||||
});
|
||||
|
||||
return acc;
|
||||
}
|
||||
|
||||
const [field, ...suffix] = fieldWithSuffix.split('_');
|
||||
|
||||
if (!acc[field]) {
|
||||
acc[field] = [];
|
||||
}
|
||||
|
||||
let op = suffix.shift();
|
||||
|
||||
// If op is "" (different from undefined), it means it's a nested filter on a relation field
|
||||
if (op === '') {
|
||||
(acc[field] as Filter[]).push({
|
||||
// Parse nested filter value
|
||||
value: this._buildFilter(value),
|
||||
not: false,
|
||||
operator: 'nested'
|
||||
});
|
||||
|
||||
return acc;
|
||||
}
|
||||
|
||||
const filter: Filter = {
|
||||
value,
|
||||
not: false,
|
||||
operator: 'equals'
|
||||
};
|
||||
|
||||
if (op === 'not') {
|
||||
filter.not = true;
|
||||
op = suffix.shift();
|
||||
}
|
||||
|
||||
if (op) {
|
||||
filter.operator = op as keyof typeof OPERATOR_MAP;
|
||||
}
|
||||
|
||||
// If filter field ends with "nocase", use case insensitive version of the operator
|
||||
if (suffix[suffix.length - 1] === 'nocase') {
|
||||
filter.operator = `${op}_nocase` as keyof typeof OPERATOR_MAP;
|
||||
}
|
||||
|
||||
(acc[field] as Filter[]).push(filter);
|
||||
|
||||
return acc;
|
||||
}, {});
|
||||
}
|
||||
|
||||
_getSelectionsFromGQLInfo (queryInfo: GraphQLResolveInfo): readonly SelectionNode[] {
|
||||
const [fieldNode] = queryInfo.fieldNodes;
|
||||
const selectionSet = fieldNode.selectionSet;
|
||||
|
||||
Reference in New Issue
Block a user