@apollo/client
4.3.5 · 19 Oct 2026MIT5.3M / weekRepositoryHomepagenpmAtom feed
3.14.1 is the newest release of 3.x.
In short
18 new10 fixed8 changed
Release note
Apollo Client 3.4.0
New documentation
Refetching queries with
client.refetchQueries.
@StephenBarlow and @benjamn in #8265
Improvements
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.
@benjamn in #7439Mutations 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.
@benjamn in #7827Support
client.refetchQueriesas an imperative way to refetch queries, without having to passoptions.refetchQueriestoclient.mutate.
@dannycochran in #7431Improve standalone
client.refetchQueriesmethod to support automatic detection of queries needing to be refetched.
@benjamn in #8000Fix remaining barriers to loading
@apollo/client/coreas native ECMAScript modules from a CDN like esm.run. Importing@apollo/clientfrom a CDN will become possible once we move all React-related dependencies into@apollo/client/reactin Apollo Client 4.
@benjamn in #8266InMemoryCachesupports a new method calledbatch, which is similar toperformTransactionbut takes named options rather than positional parameters. One of these named options is anonDirty(watch, diff)callback, which can be used to determine which watched queries were invalidated by thebatchoperation.
@benjamn in #7819Allow
merge: truefield policy to mergeReferenceobjects with non-normalized objects, and vice-versa.
@benjamn in #7778Allow identical subscriptions to be deduplicated by default, like queries.
@jkossis in #6910Always use
POSTrequest when falling back to sending full query with@apollo/client/link/persisted-queries.
@rieset in #7456The
FetchMoreQueryOptionstype now takes two instead of three type parameters (<TVariables, TData>), thanks to usingPartial<TVariables>instead ofK extends typeof TVariablesandPick<TVariables, K>.
@ArnaudBarre in #7476Pass
variablesandcontextto a mutation'supdatefunction. Note: The type of theupdatefunction is now namedMutationUpdaterFunctionrather thanMutationUpdaterFn, since the older type was broken beyond repair. If you are usingMutationUpdaterFnin your own code, please useMutationUpdaterFunctioninstead.
@jcreighton in #7902A
resultCacheMaxSizeoption may be passed to theInMemoryCacheconstructor to limit the number of result objects that will be retained in memory (to speed up repeated reads), and callingcache.reset()now releases all such memory.
@SofianHn in #8107Fully remove result cache entries from LRU dependency system when the corresponding entities are removed from
InMemoryCacheby eviction, or by any other means.
@sofianhn and @benjamn in #8147Add expected/received
variablestoNo more mocked responses...error messages generated byMockLink.
@markneub in #8340The
InMemoryCacheversion of thecache.gcmethod now supports additional options for removing non-essential (recomputable) result caching data.
@benjamn in #8421Suppress noisy
Missing cache result fields...warnings by default unlesssetLogVerbosity("debug")called.
@benjamn in #8489Improve interaction between React hooks and React Fast Refresh in development.
@andreialecu in #7952
Potentially disruptive changes
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.
@benjamn in #8280Internally, 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.
@benjamn in #8347Internally, 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).
@devrelm in #7742Respect
no-cachefetch policy (by not reading anydatafrom the cache) forloading: trueresults triggered bynotifyOnNetworkStatusChange: true.
@jcreighton in #7761The 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.
@benjamn in #8394Log 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.
@benjamn in #8416The
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.
@benjamn in #8465The
fetchMore,subscribeToMore, andupdateQueryfunctions returned from theuseQueryhook may now return undefined in edge cases where the functions are called when the component is unmounted @noghartt in #7980.
Bug fixes
In Apollo Client 2.x, a
refetchoperation would always replace existing data in the cache. With the introduction of field policymergefunctions in Apollo Client 3, existing field values could be inappropriately combined with incoming field values by a custommergefunction that does not realize arefetchhas happened.To give you more control over this behavior, we have introduced an
overwrite?: boolean = falseoption forcache.writeQueryandcache.writeFragment, and an option calledrefetchWritePolicy?: "merge" | "overwrite"forclient.watchQuery,useQuery, and other functions that acceptWatchQueryOptions. You can use these options to make sure anymergefunctions involved in cache writes forrefetchoperations get invoked withundefinedas their first argument, which simulates the absence of any existing data, while still giving themergefunction a chance to determine the internal representation of the incoming data.The default behaviors are
overwrite: trueandrefetchWritePolicy: "overwrite", which restores the Apollo Client 2.x behavior, but (if this change causes any problems for your application) you can easily recover the previous merging behavior by setting a default value forrefetchWritePolicyindefaultOptions.watchQuery:new ApolloClient({ defaultOptions: { watchQuery: { refetchWritePolicy: "merge", }, }, });Make sure the
MockedResponseResultFunctiontype is re-exported.
@hwillson in #8315InMemoryCachenow coalescesEntityStoreupdates to guarantee only onestore.merge(id, fields)call peridper cache write.
@benjamn in #8372Fix polling when used with
<React.StrictMode>.
@brainkim in #8414Fix the React integration logging
Warning: Can't perform a React state update on an unmounted component.
@wuarmin in #7745Make
ObservableQuery#getCurrentResultalways callqueryInfo.getDiff().
@benjamn in #8422Make
readFielddefault to reading from current object only when thefromoption/argument is actually omitted, not whenfromis passed toreadFieldwith an undefined value. A warning will be printed when this situation occurs.
@benjamn in #8508The
fetchMore,subscribeToMore, andupdateQueryfunctions no longer throwundefinederrors @noghartt in #7980.