From c4db0f181580214e98846627ee8a30befcfa9a36 Mon Sep 17 00:00:00 2001 From: Jack Ellis Date: Fri, 18 Oct 2024 13:01:35 +0100 Subject: [PATCH] fix: support skip query arg --- packages/query/src/createQuery/createQuery.ts | 7 +++++++ packages/query/src/createQuery/queryTypes.ts | 1 + packages/query/src/createQuery/stringifyQuery.ts | 13 ++++++++++++- packages/subgraph/src/__tests__/createQuery.test.ts | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/query/src/createQuery/createQuery.ts b/packages/query/src/createQuery/createQuery.ts index 984d5e2..d988204 100644 --- a/packages/query/src/createQuery/createQuery.ts +++ b/packages/query/src/createQuery/createQuery.ts @@ -32,6 +32,7 @@ const createQueryObj = (args: { name: string; alias?: string; first?: number; + skip?: number; orderBy?: string; orderDirection?: string; where?: WhereStatements; @@ -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 }); }, diff --git a/packages/query/src/createQuery/queryTypes.ts b/packages/query/src/createQuery/queryTypes.ts index c9380ee..a1c344d 100644 --- a/packages/query/src/createQuery/queryTypes.ts +++ b/packages/query/src/createQuery/queryTypes.ts @@ -34,6 +34,7 @@ type QuerySingle, QDef> = { type QueryList, QDef extends Array> = { first(limit: number): Query; + skip(limit: number): Query; orderBy(field: K): Query; orderDirection(direction: 'asc' | 'desc'): Query; } & QueryCommon; diff --git a/packages/query/src/createQuery/stringifyQuery.ts b/packages/query/src/createQuery/stringifyQuery.ts index 5b75cf0..13b0847 100644 --- a/packages/query/src/createQuery/stringifyQuery.ts +++ b/packages/query/src/createQuery/stringifyQuery.ts @@ -8,6 +8,7 @@ const stringifyQuery = (args: { name: string; alias?: string; first?: number; + skip?: number; orderBy?: string; orderDirection?: string; where?: WhereStatements; @@ -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'); } diff --git a/packages/subgraph/src/__tests__/createQuery.test.ts b/packages/subgraph/src/__tests__/createQuery.test.ts index 566e13f..a6eaf32 100644 --- a/packages/subgraph/src/__tests__/createQuery.test.ts +++ b/packages/subgraph/src/__tests__/createQuery.test.ts @@ -930,6 +930,7 @@ it('prettifies the result', () => { const g = createQuery(); const query = g.pools .first(100) + .skip(100) .orderBy('liquidity') .orderDirection('desc') .where((w) => [ @@ -955,6 +956,7 @@ it('prettifies the result', () => { const expected = `{ pools ( first: 100 + skip: 100 orderBy: liquidity orderDirection: desc where: {