mirror of
https://github.com/cerc-io/watcher-ts
synced 2026-09-08 08:54:05 +00:00
Implement block filter for plural queries on subgraph entities (#444)
* Fix bigint values transformation * Fix starts and ends filter operator resolution * Support case insensitive filters for string fields * Add support for global filter _change_block * Handle _change_block filter in all query types
This commit is contained in:
@@ -27,7 +27,8 @@ import {
|
||||
getSubgraphConfig,
|
||||
Transaction,
|
||||
EthClient,
|
||||
DEFAULT_LIMIT
|
||||
DEFAULT_LIMIT,
|
||||
FILTER_CHANGE_BLOCK
|
||||
} from '@cerc-io/util';
|
||||
|
||||
import { Context, GraphData, instantiate } from './loader';
|
||||
@@ -322,6 +323,17 @@ export class GraphWatcher {
|
||||
|
||||
try {
|
||||
where = Object.entries(where).reduce((acc: { [key: string]: any }, [fieldWithSuffix, value]) => {
|
||||
if (fieldWithSuffix === FILTER_CHANGE_BLOCK) {
|
||||
assert(value.number_gte && typeof value.number_gte === 'number');
|
||||
|
||||
// Maintain util.Where type
|
||||
acc[FILTER_CHANGE_BLOCK] = [{
|
||||
value: value.number_gte
|
||||
}];
|
||||
|
||||
return acc;
|
||||
}
|
||||
|
||||
const [field, ...suffix] = fieldWithSuffix.split('_');
|
||||
|
||||
if (!acc[field]) {
|
||||
@@ -345,6 +357,11 @@ export class GraphWatcher {
|
||||
filter.operator = operator;
|
||||
}
|
||||
|
||||
// If filter field ends with "nocase", use case insensitive version of the operator
|
||||
if (suffix[suffix.length - 1] === 'nocase') {
|
||||
filter.operator = `${operator}_nocase`;
|
||||
}
|
||||
|
||||
acc[field].push(filter);
|
||||
|
||||
return acc;
|
||||
|
||||
Reference in New Issue
Block a user