Skip to content

Commit

Permalink
Merge branch 'main' into ms/update-discord-to-discourse
Browse files Browse the repository at this point in the history
  • Loading branch information
Meschreiber authored Dec 19, 2024
2 parents b41a6ae + 4334d30 commit e795832
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 21 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-sheep-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix an issue with `refetchQueries` where comparing `DocumentNode`s internally by references could lead to an unknown query, even though the `DocumentNode` was indeed an active query—with a different reference.
38 changes: 38 additions & 0 deletions .github/workflows/scheduled-test-canary.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# a GitHub Action that once a day runs all tests from `main` and `release-*` branches
# with the latest `canary` and `experimental` release of `react` and `react-dom`
name: Scheduled React Canary Test
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
inputs:
branches:
description: "Branches to test"
required: true
default: '["main", "release-3.13", "release-4.0"]'
tags:
description: "React and React-DOM versions"
required: true
default: '["canary", "experimental"]'
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
tag: ${{ fromJson(github.event_name == 'workflow_dispatch' && inputs.tags || '["canary", "experimental"]') }}
branch: ${{ fromJson(github.event_name == 'workflow_dispatch' && inputs.branches || '["main", "release-3.13", "release-4.0"]') }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ matrix.branch }}
- uses: actions/setup-node@v4
with:
node-version: 22.x
- uses: bahmutov/npm-install@v1
- run: |
npm install react@${{ matrix.tag }} react-dom@${{ matrix.tag }}
# tests can be flaky, this runs only once a day and we want to minimize false negatives - retry up to three times
- run: |
node -e 'console.log("\n\nReact %s, React-DOM %s\n\n", require("react").version, require("react-dom").version)'
parallel --line-buffer -j 1 --retries 3 'npm test -- --logHeapUsage --selectProjects ' ::: 'ReactDOM 19'
4 changes: 2 additions & 2 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 41615,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34349
"dist/apollo-client.min.cjs": 41639,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34381
}
40 changes: 25 additions & 15 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,15 +899,19 @@ export class QueryManager<TStore> {
include: InternalRefetchQueriesInclude = "active"
) {
const queries = new Map<string, ObservableQuery<any>>();
const queryNamesAndDocs = new Map<string | DocumentNode, boolean>();
const queryNames = new Map<string, string | null>();
const queryNamesAndQueryStrings = new Map<string, boolean>();
const legacyQueryOptions = new Set<QueryOptions>();

if (Array.isArray(include)) {
include.forEach((desc) => {
if (typeof desc === "string") {
queryNamesAndDocs.set(desc, false);
queryNames.set(desc, desc);
queryNamesAndQueryStrings.set(desc, false);
} else if (isDocumentNode(desc)) {
queryNamesAndDocs.set(this.transform(desc), false);
const queryString = print(this.transform(desc));
queryNames.set(queryString, getOperationName(desc));
queryNamesAndQueryStrings.set(queryString, false);
} else if (isNonNullObject(desc) && desc.query) {
legacyQueryOptions.add(desc);
}
Expand Down Expand Up @@ -935,12 +939,12 @@ export class QueryManager<TStore> {

if (
include === "active" ||
(queryName && queryNamesAndDocs.has(queryName)) ||
(document && queryNamesAndDocs.has(document))
(queryName && queryNamesAndQueryStrings.has(queryName)) ||
(document && queryNamesAndQueryStrings.has(print(document)))
) {
queries.set(queryId, oq);
if (queryName) queryNamesAndDocs.set(queryName, true);
if (document) queryNamesAndDocs.set(document, true);
if (queryName) queryNamesAndQueryStrings.set(queryName, true);
if (document) queryNamesAndQueryStrings.set(print(document), true);
}
}
});
Expand Down Expand Up @@ -969,15 +973,21 @@ export class QueryManager<TStore> {
});
}

if (__DEV__ && queryNamesAndDocs.size) {
queryNamesAndDocs.forEach((included, nameOrDoc) => {
if (__DEV__ && queryNamesAndQueryStrings.size) {
queryNamesAndQueryStrings.forEach((included, nameOrQueryString) => {
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`,
nameOrDoc
);
const queryName = queryNames.get(nameOrQueryString);

if (queryName) {
invariant.warn(
`Unknown query named "%s" requested in refetchQueries options.include array`,
queryName
);
} else {
invariant.warn(
`Unknown anonymous query requested in refetchQueries options.include array`
);
}
}
});
}
Expand Down
Loading

0 comments on commit e795832

Please sign in to comment.