@apollo/client
4.3.5 · 19 Oct 2026MIT5.3M / weekRepositoryHomepagenpmAtom feed
4.3.5 is the newest release of 4.x.
In short
15 new24 fixed
Release note
Minor Changes
Support
headerstransport for enhanced client awareness.You can now provide a callback function as the
contextoption on themutatefunction returned byuseMutation. The callback function is called with the value of thecontextoption provided to theuseMutationhook. This is useful if you'd like to merge the context object provided to theuseMutationhook with a value provided to themutatefunction.function MyComponent() { const [mutate, result] = useMutation(MUTATION, { context: { foo: true }, }); async function runMutation() { await mutate({ // sends context as { foo: true, bar: true } context: (hookContext) => ({ ...hookContext, bar: true }), }); } // ... }Fix an issue where deferred payloads that returned arrays with fewer items than the original cached array would retain items from the cached array. This change includes
@streamarrays where stream arrays replace the cached arrays.Don't set the fallback value of a
@clientfield tonullwhen areadfunction is defined. Instead thereadfunction will be called with anexistingvalue ofundefinedto allow default arguments to be used to set the returned value.When a
readfunction is not defined nor is there a defined resolver for the field, warn and set the value tonullonly in that instance.Add support for
from: nullinclient.watchFragmentandcache.watchFragment. Whenfromisnull, the emitted result is:{ data: null, dataState: "complete", complete: true, }Support the newer incremental delivery format for the
@deferdirective implemented ingraphql@17.0.0-alpha.9. Import theGraphQL17Alpha9Handlerto use the newer incremental delivery format with@defer.import { GraphQL17Alpha9Handler } from "@apollo/client/incremental"; const client = new ApolloClient({ // ... incrementalHandler: new GraphQL17Alpha9Handler(), });Note
In order to use the
GraphQL17Alpha9Handler, the GraphQL server MUST implement the newer incremental delivery format. You may see errors or unusual behavior if you use the wrong handler. If you are using Apollo Router, continue to use theDefer20220824Handlerbecause Apollo Router does not yet support the newer incremental delivery format.Add support for arrays with
useFragment,useSuspenseFragment, andclient.watchFragment. This allows the ability to use a fragment to watch multiple entities in the cache. Passing an array tofromwill returndataas an array where each array index corresponds to the index in thefromarray.function MyComponent() { const result = useFragment({ fragment, from: [item1, item2, item3], }); // `data` is an array with 3 items console.log(result); // { data: [{...}, {...}, {...}], dataState: "complete", complete: true } }Add a
getCurrentResultfunction to the observable returned byclient.watchFragmentandcache.watchFragmentthat returns the current value for the watched fragment.const observable = client.watchFragment({ fragment, from: { __typename: "Item", id: 1 }, }); console.log(observable.getCurrentResult()); // { // data: {...}, // dataState: "complete", // complete: true, // }Add the
fromoption toreadFragment,watchFragment, andupdateFragment.Add support for the
@streamdirective on both theDefer20220824Handlerand theGraphQL17Alpha2Handler.Note
The implementations of
@streamdiffer in the delivery of incremental results between the different GraphQL spec versions. If you upgrading from the older format to the newer format, expect the timing of some incremental results to change.InMemoryCacheno longer filters out explicitly returnedundefineditems fromreadfunctions for array fields. This now makes it possible to createreadfunctions on array fields that return partial data and trigger a fetch for the full list.Add an
extensionsoption tocache.write,cache.writeQuery, andclient.writeQuery. This makesextensionsavailable in cachemergefunctions which can be accessed with the other merge function options.As a result of this change, any
extensionsreturned in GraphQL operations are now available inmergein the cache writes for these operations.Add an abstract
resolvesClientFieldfunction toApolloCachethat can be used by caches to tellLocalStateif it can resolve a@clientfield when a local resolver is not defined.LocalStatewill emit a warning and set a fallback value ofnullwhen no local resolver is defined andresolvesClientFieldreturnsfalse, or isn't defined. ReturningtruefromresolvesClientFieldsignals that a mechanism in the cache will set the field value. In this case,LocalStatewon't set the field value.Use the default stream merge function for
@streamfields only if stream info is present. This change means that using the olderDefer20220824Handlerwill not use the default stream merge function and will instead truncate the streamed array on the first chunk.
Patch Changes
Ensure that
PreloadedQueryRefinstances are unsubscribed when garbage collectedChange the returned value from
nullto{}when all fields in a query were skipped.This also fixes a bug where
useSuspenseQuerywould suspend indefinitely when all fields were skipped.Fix an issue where errors parsed from incremental chunks in
ErrorLinkmight throw when using theGraphQL17Alpha9Handler.Deduplicate watches created by
useFragment,client.watchFragment, andcache.watchFragmentthat contain the same fragment, variables, and identifier. This should improve performance in situations where auseFragmentor aclient.watchFragmentis used to watch the same object in multiple places of an application.Allow
FragmentTypenot only to be called asFragmentType<TData>, but also asFragmentType<TypedDocumentNode>.Fix an issue where calling
fetchMorewith@deferor@streamwould not rerender incremental results as they were streamed.Truncate
@streamarrays only on last chunk by default.Expose the
ExtensionsWithStreamInfotype forextensionsinCache.writeQuery,Cache.writeandCache.updateso other cache implementations also can correctly access them.Improve the cache data loss warning message when
existingorincomingis an array.Ignore top-level
datavalues on subsequent chunks in incremental responses.Create mechanism to add experimental features to Apollo Client
Ensure
LocalStatedoesn't try to read from the cache when using ano-cachefetch policy.Ensure an error is thrown when
@streamis detected and anincrementalDeliveryhandler is not configured.Use memoized observable mapping when using
watchFragment,useFragmentoruseSuspenseFragment.Add helper type
QueryRef.ForQuery<TypedDocumentNode>Pass
streamInfothrough result extensions as aWeakRef.Fix the
Defer20220824Handler.SubsequentResulttype to match theFormattedSubsequentIncrementalExecutionResulttype ingraphql@17.0.0-alpha.2.Warn when using a
no-cachefetch policy without a local resolver defined.no-cachequeries do not read or write to the cache which meantno-cachequeries are silently incomplete when the@clientfield value was handled by a cachereadfunction.Update the
acceptheader used with theGraphQL17Alpha9Handlertomultipart/mixed;incrementalSpec=v0.2to ensure the newest incremental delivery format is requested.DeepPartial<Array<TData>>now returnsArray<DeepPartial<TData>>instead ofArray<DeepPartial<TData | undefined>>.prerenderStatic: Expose return value ofrenderFunctionto userland, fixabortedproperty.This enables usage of
resumeAndPrerenderwith React 19.2.Reduce the number of observables created by
watchFragmentby reusing existing observables as much as possible. This should improve performance when watching the same item in the cache multiple times after a cache update occurs.Handle
@streampayloads that send multiple items in the same chunk when using theDefer20220824Handler.Handle an edge case with the
Defer20220824Handlerwhere an error for a@streamitem that bubbles to the@streamboundary (such as an item returningnullfor a non-null array item) would write items from future chunks to the wrong array index. In these cases, the@streamfield is no longer processed and future updates to the field are ignored. This prevents runtime errors that TypeScript would otherwise not be able to catch.Avoid calling
mergefunctions more than once for the same incremental chunk.