Releases: apollographql/apollo-client
@apollo/client@4.1.2
Patch Changes
-
#13105
8b62263Thanks @phryneas! -ssrMode,ssrForceFetchDelayorprioritizeCacheValuesshould not overridefetchPolicy: 'cache-only',fetchPolicy: 'no-cache',fetchPolicy: 'standby',skip: true, orskipTokenwhen reading the initial value of anObservableQuery. -
#13105
8b62263Thanks @phryneas! - FixskipTokeninuseQuerywithprerenderStaticand related SSR functions. -
#13105
8b62263Thanks @phryneas! - Avoid fetches withfetchPolicy: no-cacheinuseQuerywithprerenderStaticand related SSR functions.
@apollo/client@4.1.1
Patch Changes
- #13103
dee7dcfThanks @jerelmiller! - Ensure@clientfields that are children of aliased server fields are resolved correctly.
@apollo/client@4.1.0
Minor Changes
-
#13043
65e66caThanks @jerelmiller! - Supportheaderstransport for enhanced client awareness. -
#12927
785e223Thanks @jerelmiller! - You can now provide a callback function as thecontextoption 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 }), }); } // ... }
-
#12923
94ea3e3Thanks @jerelmiller! - 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. -
#12927
96b531fThanks @jerelmiller! - 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. -
#12927
45ebb52Thanks @jerelmiller! - Add support forfrom: nullinclient.watchFragmentandcache.watchFragment. Whenfromisnull, the emitted result is:{ data: null, dataState: "complete", complete: true, }
-
#12926
2b7f2c1Thanks @jerelmiller! - 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 theGraphQL17Alpha9Handler, 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. -
#12927
45ebb52Thanks @jerelmiller! - Add support for arrays withuseFragment,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 } }
-
#12927
45ebb52Thanks @jerelmiller! - Add agetCurrentResultfunction 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, // }
-
#13038
109efe7Thanks @jerelmiller! - Add thefromoption toreadFragment,watchFragment, andupdateFragment. -
#12918
2e224b9Thanks @jerelmiller! - 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. -
#13056
b224efcThanks @jerelmiller! -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. -
#13058
121a2cbThanks @jerelmiller! - Add anextensionsoption 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. -
#12927
96b531fThanks @jerelmiller! - Add an abstractresolvesClientFieldfunction 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. -
#13078
bf1e0dcThanks @phryneas! - 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
-
#12884
d329790Thanks @phryneas! - Ensure thatPreloadedQueryRefinstances are unsubscribed when garbage collected -
#13086
1a1d408Thanks @phryneas! - Change the returned value fromnullto{}when all fields in a query were skipped.This also fixes a bug where
useSuspenseQuerywould suspend indefinitely when all fields were skipped. -
#13010
7627000Thanks @jerelmiller! - Fix an issue where errors parsed from incremental chunks inErrorLinkmight throw when using theGraphQL17Alpha9Handler. -
#12927
45ebb52Thanks [@jerelmiller](https...
@apollo/client@4.0.13
Patch Changes
-
#13094
9cbe2c2Thanks @phryneas! - Ensure thatcompactandmergeOptionspreserve symbol keys.This fixes an issue where the change introduced in 4.0.11 via #13049 would not
be applied ifdefaultOptionsforwatchQuerywere declared.Please note that
compactandmergeOptionsare considered internal utilities
and they might have similar behavior changes in future releases.
Do not use them in your application code - a change like this is not considered
breaking and will not be announced as such.
@apollo/client@4.0.12
@apollo/client@4.1.0-rc.1
Patch Changes
-
#13086
1a1d408Thanks @phryneas! - Change the returned value fromnullto{}when all fields in a query were skipped.This also fixes a bug where
useSuspenseQuerywould suspend indefinitely when all fields were skipped. -
#13071
99ffe9aThanks @phryneas! -prerenderStatic: Expose return value ofrenderFunctionto userland, fixabortedproperty.This enables usage of
resumeAndPrerenderwith React 19.2.
@apollo/client@4.1.0-rc.0
Minor Changes
- #13078
bf1e0dcThanks @phryneas! - 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
-
#13083
f3c2be1Thanks @phryneas! - Expose theExtensionsWithStreamInfotype forextensionsinCache.writeQuery,Cache.writeandCache.updateso other cache implementations also can correctly access them. -
#13082
c257418Thanks @phryneas! - PassstreamInfothrough result extensions as aWeakRef. -
#13081
1e06ad7Thanks @jerelmiller! - Avoid callingmergefunctions more than once for the same incremental chunk.
@apollo/client@4.0.12-beta.0
@apollo/client@4.1.0-alpha.9
Minor Changes
-
#13056
b224efcThanks @jerelmiller! -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. -
#13058
121a2cbThanks @jerelmiller! - Add anextensionsoption 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.
Patch Changes
@apollo/client@4.0.11
Patch Changes
-
#13050
8020829Thanks @phryneas! - Replace usage offindLastwith more backwards-compatible methods. -
#13049
05638deThanks @phryneas! - Fixes an issue where queries starting withskipTokenor lazy queries fromuseLazyQuerywere included inclient.refetchQueries()before they had been executed for the first time. While generally queries with astandbyfetchPolicyshould be included in refetch, these queries never hadvariablespassed in, so they should be excluded until they have run once and received their actual variables.These queries are now properly excluded from refetch operations until after their initial execution.
This change adds a new hidden option to
client.watchQuery,[variablesUnknownSymbol], which may be settruefor queries starting with afetchPolicyofstandby. It will only be applied when creating theObservableQueryinstance and cannot be changed later. This flag indicates that the query's variables are not yet known, and thus it should be excluded from refetch operations until they are.
This option is not meant for everyday use and is intended for framework integrations only.