Skip to content

Commit

Permalink
fix: support skip query arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Oct 18, 2024
1 parent 5c3f129 commit c4db0f1
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/query/src/createQuery/createQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const createQueryObj = (args: {
name: string;
alias?: string;
first?: number;
skip?: number;
orderBy?: string;
orderDirection?: string;
where?: WhereStatements;
Expand All @@ -45,6 +46,12 @@ const createQueryObj = (args: {
first: limit,
});
},
skip: (limit: number) => {
return createQueryObj({
...args,
skip: limit,
});
},
orderBy: (field: any) => {
return createQueryObj({ ...args, orderBy: field });
},
Expand Down
1 change: 1 addition & 0 deletions packages/query/src/createQuery/queryTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type QuerySingle<QName extends Index<QDef>, QDef> = {

type QueryList<QName extends Index<QDef>, QDef extends Array<any>> = {
first(limit: number): Query<QName, QDef>;
skip(limit: number): Query<QName, QDef>;
orderBy<K extends keyof QDef[0]>(field: K): Query<QName, QDef>;
orderDirection(direction: 'asc' | 'desc'): Query<QName, QDef>;
} & QueryCommon<QName, QDef, QDef[0]>;
Expand Down
13 changes: 12 additions & 1 deletion packages/query/src/createQuery/stringifyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const stringifyQuery = (args: {
name: string;
alias?: string;
first?: number;
skip?: number;
orderBy?: string;
orderDirection?: string;
where?: WhereStatements;
Expand All @@ -27,11 +28,21 @@ const stringifyQuery = (args: {
output.push(args.name, ' ');
const w = args.where && stringifyWhere(args.where);
// Filters
if (args.first || args.orderBy || args.orderDirection || w || args.id) {
if (
args.first ||
args.skip ||
args.orderBy ||
args.orderDirection ||
w ||
args.id
) {
output.push('(\n');
if (args.first) {
output.push('first: ', `${args.first}`, '\n');
}
if (args.skip) {
output.push('skip: ', `${args.skip}`, '\n');
}
if (args.orderBy) {
output.push('orderBy: ', args.orderBy, '\n');
}
Expand Down
2 changes: 2 additions & 0 deletions packages/subgraph/src/__tests__/createQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@ it('prettifies the result', () => {
const g = createQuery<Query>();
const query = g.pools
.first(100)
.skip(100)
.orderBy('liquidity')
.orderDirection('desc')
.where((w) => [
Expand All @@ -955,6 +956,7 @@ it('prettifies the result', () => {
const expected = `{
pools (
first: 100
skip: 100
orderBy: liquidity
orderDirection: desc
where: {
Expand Down

0 comments on commit c4db0f1

Please sign in to comment.