From 9f4b665d60d5bc880c4402b8577ff00e5d620740 Mon Sep 17 00:00:00 2001 From: Nicolas Charpentier Date: Wed, 18 Dec 2024 14:58:46 -0500 Subject: [PATCH] Compare `DocumentNode` as strings via `print` --- src/core/QueryManager.ts | 12 +++++------- src/core/__tests__/QueryManager/index.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/core/QueryManager.ts b/src/core/QueryManager.ts index e61e123c5f2..f71d386840d 100644 --- a/src/core/QueryManager.ts +++ b/src/core/QueryManager.ts @@ -899,7 +899,7 @@ export class QueryManager { include: InternalRefetchQueriesInclude = "active" ) { const queries = new Map>(); - const queryNamesAndDocs = new Map(); + const queryNamesAndDocs = new Map(); const legacyQueryOptions = new Set(); if (Array.isArray(include)) { @@ -907,7 +907,7 @@ export class QueryManager { if (typeof desc === "string") { queryNamesAndDocs.set(desc, false); } else if (isDocumentNode(desc)) { - queryNamesAndDocs.set(this.transform(desc), false); + queryNamesAndDocs.set(print(this.transform(desc)), false); } else if (isNonNullObject(desc) && desc.query) { legacyQueryOptions.add(desc); } @@ -936,11 +936,11 @@ export class QueryManager { if ( include === "active" || (queryName && queryNamesAndDocs.has(queryName)) || - (document && queryNamesAndDocs.has(document)) + (document && queryNamesAndDocs.has(print(document))) ) { queries.set(queryId, oq); if (queryName) queryNamesAndDocs.set(queryName, true); - if (document) queryNamesAndDocs.set(document, true); + if (document) queryNamesAndDocs.set(print(document), true); } } }); @@ -973,9 +973,7 @@ export class QueryManager { queryNamesAndDocs.forEach((included, nameOrDoc) => { if (!included) { invariant.warn( - typeof nameOrDoc === "string" ? - `Unknown query named "%s" requested in refetchQueries options.include array` - : `Unknown query %o requested in refetchQueries options.include array`, + `Unknown query %s requested in refetchQueries options.include array`, nameOrDoc ); } diff --git a/src/core/__tests__/QueryManager/index.ts b/src/core/__tests__/QueryManager/index.ts index fb5511fac1e..eaf3c5fb405 100644 --- a/src/core/__tests__/QueryManager/index.ts +++ b/src/core/__tests__/QueryManager/index.ts @@ -5075,7 +5075,7 @@ describe("QueryManager", () => { (result) => { expect(result.data).toEqual(secondReqData); expect(consoleWarnSpy).toHaveBeenLastCalledWith( - 'Unknown query named "%s" requested in refetchQueries options.include array', + 'Unknown query %s requested in refetchQueries options.include array', "fakeQuery" ); } @@ -5148,7 +5148,7 @@ describe("QueryManager", () => { }) .then(() => { expect(consoleWarnSpy).toHaveBeenLastCalledWith( - 'Unknown query named "%s" requested in refetchQueries options.include array', + 'Unknown query %s requested in refetchQueries options.include array', "getAuthors" ); })