Skip to content

Commit

Permalink
Compare DocumentNode as strings via print
Browse files Browse the repository at this point in the history
  • Loading branch information
charpeni committed Dec 18, 2024
1 parent 19d14a7 commit 9f4b665
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
12 changes: 5 additions & 7 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,15 @@ export class QueryManager<TStore> {
include: InternalRefetchQueriesInclude = "active"
) {
const queries = new Map<string, ObservableQuery<any>>();
const queryNamesAndDocs = new Map<string | DocumentNode, boolean>();
const queryNamesAndDocs = new Map<string, boolean>();
const legacyQueryOptions = new Set<QueryOptions>();

if (Array.isArray(include)) {
include.forEach((desc) => {
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);
}
Expand Down Expand Up @@ -936,11 +936,11 @@ export class QueryManager<TStore> {
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);
}
}
});
Expand Down Expand Up @@ -973,9 +973,7 @@ export class QueryManager<TStore> {
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
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/__tests__/QueryManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}
Expand Down Expand Up @@ -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"
);
})
Expand Down

0 comments on commit 9f4b665

Please sign in to comment.