@apollo/client
4.3.5 · 19 Oct 2026MIT5.3M / weekRepositoryHomepagenpmAtom feed
Upgrading @apollo/client from 3.3.21 to 3.4.0
1 release in betweenevery note read
Release by release
- new
Refetching queries with
client.refetchQueries. - new
InMemoryCachenow guarantees that any two result objects returned by the cache (fromreadQuery,readFragment, etc.) will be referentially equal (===) if they are deeply equal. Previously,===equality was often achievable for results for the same query, on a best-effort basis. Now, equivalent result objects will be automatically shared among the result trees of completely different queries. This guarantee is important for taking full advantage of optimistic updates that correctly guess the final data, and for "pure" UI components that can skip re-rendering when their input data are unchanged. - new
Mutations now accept an optional callback function called
onQueryUpdated, which will be passed theObservableQueryandCache.DiffResultobjects for any queries invalidated by cache writes performed by the mutation's finalupdatefunction. UsingonQueryUpdated, you can override the defaultFetchPolicyof the query, by (for example) callingObservableQuerymethods likerefetchto force a network request. This automatic detection of invalidated queries provides an alternative to manually enumerating queries using therefetchQueriesmutation option. Also, if you return aPromisefromonQueryUpdated, the mutation will automatically await thatPromise, rendering theawaitRefetchQueriesoption unnecessary. - new
Support
client.refetchQueriesas an imperative way to refetch queries, without having to passoptions.refetchQueriestoclient.mutate.
- new
8 other lines we could not sort, mostly version bumps
- 3.4.0
To avoid retaining sensitive information from mutation root field arguments, Apollo Client v3.4 automatically clears any
ROOT_MUTATIONfields from the cache after each mutation finishes. If you need this information to remain in the cache, you can prevent the removal by passing thekeepRootFields: trueoption toclient.mutate.ROOT_MUTATIONresult data are also passed to the mutationupdatefunction, so we recommend obtaining the results that way, rather than usingkeepRootFields: true, if possible. - 3.4.0
Internally, Apollo Client now controls the execution of development-only code using the
__DEV__global variable, rather thanprocess.env.NODE_ENV. While this change should not cause any visible differences in behavior, it will increase your minified+gzip bundle size by more than 3.5kB, unless you configure your minifier to replace__DEV__with atrueorfalseconstant, the same way you already replaceprocess.env.NODE_ENVwith a string literal like"development"or"production". For an example of configuring a Create React App project without ejecting, see this pull request for our React Apollo reproduction template. - 3.4.0
Internally, Apollo Client now uses namespace syntax (e.g.
import * as React from "react") for imports whose types are re-exported (and thus may appear in.d.tsfiles). This change should remove any need to configureesModuleInteroporallowSyntheticDefaultImportsintsconfig.json, but might require updating bundler configurations that specify named exports of thereactandprop-typespackages, to include exports likecreateContextandcreateElement(example). - 3.4.0
Respect
no-cachefetch policy (by not reading anydatafrom the cache) forloading: trueresults triggered bynotifyOnNetworkStatusChange: true. - 3.4.0
The TypeScript return types of the
getLastResultandgetLastErrormethods ofObservableQuerynow correctly include the possibility of returningundefined. If you happen to be calling either of these methods directly, you may need to adjust how the calling code handles the methods' possibly-undefinedresults. - 3.4.0
Log non-fatal
invariant.errormessage when fields are missing from result objects written intoInMemoryCache, rather than throwing an exception. While this change relaxes an exception to be merely an error message, which is usually a backwards-compatible change, the error messages are logged in more cases now than the exception was previously thrown, and those new error messages may be worth investigating to discover potential problems in your application. The errors are not displayed for@client-only fields, so adding@clientis one way to handle/hide the errors for local-only fields. Another general strategy is to use a more precise query to write specific subsets of data into the cache, rather than reusing a larger query that contains fields not present in the writtendata. - 3.4.0
The
nextFetchPolicyoption forclient.watchQueryanduseQuerywill no longer be removed from theoptionsobject after it has been applied, and instead will continue to be applied any timeoptions.fetchPolicyis reset to another value, until/unless theoptions.nextFetchPolicyproperty is removed fromoptions. - 3.4.0