Skip to content

Commit

Permalink
Handle bigint values for filters in db query
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Oct 30, 2023
1 parent 91794ab commit 611a93f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions packages/codegen/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export class Schema {
}
};

// TODO: Add query type filter (subgraphType_filter) (input)
// Add plural query

// Create the subgraphType_orderBy enum type
Expand All @@ -219,8 +218,9 @@ export class Schema {
// Get type composer object for return type from the schema composer.
type: this._composer.getAnyTC(subgraphType).NonNull.List.NonNull,
args: {
// where: Staker_filter,
block: BlockHeight,
// TODO: Create input type for where clause
// where: subgraphType_filter,
orderBy: subgraphTypeOrderByEnum,
orderDirection: OrderDirection,
first: { type: GraphQLInt, defaultValue: 100 },
Expand Down
20 changes: 17 additions & 3 deletions packages/util/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,10 @@ export class Database {

whereClause += `${OPERATOR_MAP[operator]} `;

value = this._transformBigIntValues(value);
if (operator === 'in') {
whereClause += '(:...';
} else {
// Convert to string type value as bigint type throws error in query.
value = value.toString();

whereClause += ':';
}

Expand Down Expand Up @@ -900,4 +898,20 @@ export class Database {

eventCount.set(res);
}

_transformBigIntValues (value: any): any {
if (Array.isArray(value)) {
if (value.length > 0 && typeof value[0] === 'bigint') {
return value.map(val => {
return val.toString();
});
}

return value;
}

if (typeof value === 'bigint') {
return value.toString();
}
}
}

0 comments on commit 611a93f

Please sign in to comment.