diff --git a/.size-limits.json b/.size-limits.json index d842cc08273..201d3dec8a5 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,6 +1,6 @@ { - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 47873, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 42183, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 35925, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 29449 + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 47960, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 42273, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 35984, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 29491 } diff --git a/docs/source/migrating/apollo-client-4-migration.mdx b/docs/source/migrating/apollo-client-4-migration.mdx index c30e711a4af..503aa0502d1 100644 --- a/docs/source/migrating/apollo-client-4-migration.mdx +++ b/docs/source/migrating/apollo-client-4-migration.mdx @@ -995,12 +995,36 @@ As a result of this change, the definitions for _active_ and _inactive_ queries -A query is in standby if it is skipped with the `skip` option or `skipToken` in a React hook, or if the `fetchPolicy` is set to `standby`. +A query is in standby if it is skipped with the `skip` option or `skipToken` in a React hook, or if the `fetchPolicy` is set to `standby`.

This change affects the queries returned by `client.getObservableQueries` or the queries fetched by `refetchQueries` when using the `"active"` or `"all"` keywords, as these no longer include `ObservableQuery` instances without subscribers. +#### Named queries in standby are refetched + +Named queries in standby provided to `client.refetchQueries({ include: ["queryName"] })` or `client.refetchQueries({ include: [QUERY] })` were skipped in Apollo Client 3 and a warning was logged. + +Apollo Client 4 now refetches named queries in standby. If you want to keep the Apollo Client 3 behavior, use the `onQueryUpdated` option to skip queries in standby: + +```ts +client.refetchQueries({ + include: ["queryName"], + onQueryUpdated: (observableQuery) => + observableQuery.options.fetchPolicy !== "standby", +}); +``` + + + +#### `skipToken` skips refetches until variables are known + + + +Although both `skip` and `skipToken` put a query in standby, `client.refetchQueries()` handles them differently before the first execution. Queries you create with `skip: true` can still be refetched because Apollo Client already has their options, including any variables that might be needed for refetching. + +Queries you create with `skipToken` are excluded until after their first execution when variables are known. This prevents situations where refetching inactive queries that contain required variables are guaranteed to fail on the server. + ### Removal of the `canonizeResults` option The `canonizeResults` option has been removed because it caused memory leaks. If you use `canonizeResults`, you may see some changes to the object identity of some objects that were previously referentially equal.