From c5b6671853941bd8fa00fa2c313f41860ec8fdbf Mon Sep 17 00:00:00 2001 From: Jan Bevers <12234016+janb87@users.noreply.github.com> Date: Fri, 31 Oct 2025 10:47:26 +0100 Subject: [PATCH 1/3] Skip non-list requests for fetchAll-only parents --- sdk/thegraph/src/utils/pagination.test.ts | 21 ++++++++++++ sdk/thegraph/src/utils/pagination.ts | 40 +++++++++++++++++++---- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/sdk/thegraph/src/utils/pagination.test.ts b/sdk/thegraph/src/utils/pagination.test.ts index 66e74c9b7..2bf2078fb 100644 --- a/sdk/thegraph/src/utils/pagination.test.ts +++ b/sdk/thegraph/src/utils/pagination.test.ts @@ -353,6 +353,27 @@ describe("createTheGraphClientWithPagination", () => { }); }); + it("should return token if only @fetchAll field is requested", async () => { + const result = await client.query( + theGraphGraphql(` + query($name: String) { + token(name: $name) { + holders @fetchAll { + name + } + } + }`), + { + name: "Token 100", + }, + ); + + expect(result.token).toEqual({ + holders: TEST_HOLDERS, + }); + expect(requestMock).toHaveBeenCalledTimes(3); + }); + it("should allow multiple queries in a single request", async () => { const result = await client.query( theGraphGraphql(` diff --git a/sdk/thegraph/src/utils/pagination.ts b/sdk/thegraph/src/utils/pagination.ts index 0d56c04b1..44f2273c4 100644 --- a/sdk/thegraph/src/utils/pagination.ts +++ b/sdk/thegraph/src/utils/pagination.ts @@ -1,7 +1,7 @@ import { sortBy } from "es-toolkit"; import { get, isArray, isEmpty, set } from "es-toolkit/compat"; import type { TadaDocumentNode } from "gql.tada"; -import { type ArgumentNode, type DocumentNode, Kind, parse, visit } from "graphql"; +import { type ArgumentNode, type DocumentNode, type FieldNode, Kind, parse, visit } from "graphql"; import type { GraphQLClient, RequestDocument, RequestOptions, Variables } from "graphql-request"; // Constants for TheGraph limits @@ -244,7 +244,6 @@ function createSingleFieldQuery( // Create query without list fields function createNonListQuery(document: DocumentNode, listFields: ListFieldWithFetchAllDirective[]): DocumentNode | null { - let hasFields = false; const pathStack: string[] = []; const filtered = visit(document, { @@ -263,17 +262,35 @@ function createNonListQuery(document: DocumentNode, listFields: ListFieldWithFet pathStack.pop(); return null; } - - hasFields = true; return undefined; }, - leave: () => { + leave: (node: FieldNode) => { pathStack.pop(); + if (node.selectionSet && node.selectionSet.selections.length === 0) { + return null; + } + return undefined; }, }, }); - return hasFields ? filtered : null; + return filtered; +} + +function countExecutableFields(document: DocumentNode): number { + let fieldCount = 0; + + visit(document, { + Field: (node) => { + if (!node.name.value.startsWith("__")) { + if (!node.selectionSet || node.selectionSet.selections.length > 0) { + fieldCount += 1; + } + } + }, + }); + + return fieldCount; } // Filter variables to only include used ones @@ -409,6 +426,14 @@ export function createTheGraphClientWithPagination(theGraphClient: Pick 1) { + const parentPath = field.path.slice(0, -1); + const existingParent = get(result, parentPath); + + if (!existingParent || typeof existingParent !== "object" || isArray(existingParent)) { + set(result, parentPath, {}); + } + } set(result, field.path, data); } @@ -416,6 +441,9 @@ export function createTheGraphClientWithPagination(theGraphClient: Pick Date: Fri, 31 Oct 2025 15:36:29 +0100 Subject: [PATCH 2/3] cleanup --- sdk/thegraph/src/utils/pagination.test.ts | 6 ++++-- sdk/thegraph/src/utils/pagination.ts | 9 --------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/sdk/thegraph/src/utils/pagination.test.ts b/sdk/thegraph/src/utils/pagination.test.ts index 2bf2078fb..35f42ff94 100644 --- a/sdk/thegraph/src/utils/pagination.test.ts +++ b/sdk/thegraph/src/utils/pagination.test.ts @@ -368,8 +368,10 @@ describe("createTheGraphClientWithPagination", () => { }, ); - expect(result.token).toEqual({ - holders: TEST_HOLDERS, + expect(result).toEqual({ + token: { + holders: TEST_HOLDERS, + }, }); expect(requestMock).toHaveBeenCalledTimes(3); }); diff --git a/sdk/thegraph/src/utils/pagination.ts b/sdk/thegraph/src/utils/pagination.ts index 44f2273c4..17315724f 100644 --- a/sdk/thegraph/src/utils/pagination.ts +++ b/sdk/thegraph/src/utils/pagination.ts @@ -425,15 +425,6 @@ export function createTheGraphClientWithPagination(theGraphClient: Pick 1) { - const parentPath = field.path.slice(0, -1); - const existingParent = get(result, parentPath); - - if (!existingParent || typeof existingParent !== "object" || isArray(existingParent)) { - set(result, parentPath, {}); - } - } set(result, field.path, data); } From 95573b2f272a32acf887307e3f9f316c784b0260 Mon Sep 17 00:00:00 2001 From: Jan Bevers Date: Fri, 31 Oct 2025 15:37:32 +0100 Subject: [PATCH 3/3] u --- sdk/thegraph/src/utils/pagination.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/thegraph/src/utils/pagination.ts b/sdk/thegraph/src/utils/pagination.ts index 17315724f..03e1bffbd 100644 --- a/sdk/thegraph/src/utils/pagination.ts +++ b/sdk/thegraph/src/utils/pagination.ts @@ -425,6 +425,7 @@ export function createTheGraphClientWithPagination(theGraphClient: Pick