Releases: apollographql/apollo-client
v3.14.0-alpha.1
Minor Changes
-
#12752
8b779b4Thanks @jerelmiller! - Add deprecations and warnings to remaining APIs changed in Apollo Client 4.0. -
#12751
567cad8Thanks @jerelmiller! - Add@deprecatedtags to all properties returned from any query API (e.g.client.query,observableQuery.refetch, etc.),client.mutate, andclient.subscribethat are no longer available in Apollo Client 4.0. -
#12751
567cad8Thanks @jerelmiller! - Warn when using astandbyfetch policy withclient.query.
@apollo/[email protected]
Major Changes
-
#12731
0198870Thanks @phryneas! - Ship React Compiler compiled React hooks in@apollo/client/react/compiled.We now ship a React-Compiler compiled version of the React hooks in
@apollo/client/react/compiled.This entry point contains everything that
@apollo/client/reactdoes,
so you can use it as a drop-in replacement in your whole application
if you choose to use the compiled hooks.
Minor Changes
- #12753
b85818dThanks @jerelmiller! - Renamedclient.reFetchObservableQueriestoclient.refetchObservableQueries.
client.reFetchObservableQueriesis still available as an alias, but is now
deprecated and will be removed in a future major version.
v3.14.0-alpha.0
Minor Changes
-
#12746
0bcd2f4Thanks @jerelmiller! - Add warnings and deprecations for options and methods for all React APIs. -
#12746
0bcd2f4Thanks @jerelmiller! - AddpreloadQuery.toPromise(queryRef)as a replacement forqueryRef.toPromise().queryRef.toPromise()has been removed in Apollo Client 4.0 in favor ofpreloadQuery.toPromiseand is now considered deprecated. -
#12736
ea89440Thanks @jerelmiller! - Add deprecations and deprecation warnings forApolloClientoptions and methods. -
#12459
1c5a031Thanks @jerelmiller! - ResetaddTypenameTransformandfragmentscaches when callingcache.gc()only whenresetResultCacheistrue. -
#12743
92ad409Thanks @jerelmiller! - Add deprecations and warnings foraddTypenameinInMemoryCacheandMockedProvider. -
#12743
92ad409Thanks @jerelmiller! - Add deprecations and warnings forcanonizeResults.
Patch Changes
@apollo/[email protected]
Major Changes
-
#12742
575bf3eThanks @jerelmiller! - The newSetContextLinkflips theprevContextandoperationarguments in the callback. ThesetContextfunction has remained unchanged.- new SetContextLink((operation, prevContext) => { + new SetContextLink((prevContext, operation) => { // ... })
-
#12742
575bf3eThanks @jerelmiller! - Theoperationargument to the callback passed toSetContextLinkis now of typeSetContextLink.SetContextOperationwhich is anOperationwithout thegetContextorsetContextfunctions. Previously the type ofoperationwasGraphQLRequestwhich had access to acontextproperty. Thecontextproperty was alwaysundefinedand could result in bugs when using it instead of theprevContextargument.This change means the
operationargument now contains an accessibleclientproperty.
Minor Changes
-
#12740
1c6e03cThanks @phryneas! - Overridable types fordataState: "complete",dataState: "streaming"and
dataState: "partial"responses.This adds the
DataValuenamespace exported from Apollo Client with the three
typesDataValue.Complete,DataValue.StreamingandDataValue.Partial.These types will be used to mark
TDatain the respective states.Completedefaults toTDataStreamingdefaults toTDataPartialdefaults toDeepPartial<TData>
All three can be overwritten, e.g. to be
DeepReadonlyusing higher kinded types
by following this pattern:import { HKT, DeepPartial } from "@apollo/client/utilities"; import { DeepReadonly } from "some-type-helper-library"; interface CompleteOverride extends HKT { return: DeepReadonly<this["arg1"]>; } interface StreamingOverride extends HKT { return: DeepReadonly<this["arg1"]>; } interface PartialOverride extends HKT { return: DeepReadonly<DeepPartial<this["arg1"]>>; } declare module "@apollo/client" { export interface TypeOverrides { Complete: CompleteOverride; Streaming: StreamingOverride; Partial: PartialOverride; } }
Patch Changes
@apollo/[email protected]
Major Changes
-
#12727
b845906Thanks @jerelmiller! - Add a codemod that renames old import locations from 3.x entrypoint to their 4.x entrypoint.Run the codemod using the following command:
npx @apollo/client-codemod-migrate-3-to-4 --parser tsx ./src/**/*.{ts,tsx}
The codemod supports
.js,.jsx,.ts, and.tsxfiles.
@apollo/[email protected]
Major Changes
-
#12735
5159880Thanks @jerelmiller! - Remove deprecatedresultCacheMaxSizeoption fromInMemoryCacheoptions. -
#12735
5159880Thanks @jerelmiller! - Remove deprecatedconnectToDevtoolsoption fromApolloClientOptions. Usedevtools.enabledinstead.
Minor Changes
-
#12725
89ac725Thanks @jerelmiller! - AddoperationTypetooperationinApolloLink. This means that determining whether aqueryis a specific operation type can now be compared with this property instead of usinggetMainDefinition.- import { getMainDefinition } from "@apollo/client/utilities"; + import { OperationTypeNode } from "graphql"; ApolloLink.split( - ({ query }) => { - const definition = getMainDefinition(query); - return ( - definition.kind === 'OperationDefinition' && - definition.operation === 'subscription' - ); - return - }, + ({ operationType }) => { + return operationType === OperationTypeNode.SUBSCRIPTION; + }, conditionTrueLink, conditionFalseLink, );
Patch Changes
-
#12728
07a0c8cThanks @jerelmiller! - Export theIgnoreModifiertype from@apollo/client/cache. -
#12735
5159880Thanks @jerelmiller! - Change theunsafePreviousDataargument onUpdateQueryMapFnandSubscribeToMoreQueryFnto aDeepPartialsince the result may contain partial data. -
#12734
037979dThanks @jerelmiller! - Don't warn about a missing resolver if a@clientdoes not have a configured resolver. It is possible the cache contains areadfunction for the field and the warning added confusion.Note that
readfunctions without a defined resolver will receive theexistingargument asnullinstead ofundefinedeven when data hasn't been written to the cache. This is becauseLocalStatesets a default value ofnullwhen a resolver is not defined to ensure that the field contains a value in case areadfunction is not defined rather than omitting the field entirely. -
#12725
89ac725Thanks @jerelmiller! - ExportgetMainDefinitionfrom@apollo/client/utilities. -
#12729
699c830Thanks @jerelmiller! - EnsureuseQueryrerenders whennotifyOnNetworkStatusChangeisfalseand arefetchthat changes variables returns a result deeply equal to previous variables.
@apollo/[email protected]
Major Changes
- #12723
1f9ed72Thanks @jerelmiller! - Version bump only for codegen to release asrc.
@apollo/[email protected]
Major Changes
- #12718
ecfc02aThanks @jerelmiller! - Version bump only to release latest asrc.
@apollo/[email protected]
Major Changes
-
#12712
bbb2b61Thanks @jerelmiller! - An error is now thrown when trying to callfetchMoreon acache-onlyquery. -
#12712
bbb2b61Thanks @jerelmiller! -cache-onlyqueries are no longer refetched when callingclient.reFetchObservableQuerieswhenincludeStandbyistrue. -
#12705
a60f411Thanks @jerelmiller! -cache-onlyqueries will now initialize withloading: falseandnetworkStatus: NetworkStatus.readywhen there is no data in the cache.This means
useQuerywill no longer render a short initial loading state before renderingloading: falseandObservableQuery.getCurrentResult()will now returnloading: falseimmediately. -
#12712
bbb2b61Thanks @jerelmiller! -cache-onlyqueries are now excluded fromclient.refetchQueriesin all situations.cache-onlyqueries affected byupdateCacheare also excluded fromrefetchQuerieswhenonQueryUpdatedis not provided. -
#12681
b181f98Thanks @jerelmiller! - Changing most options when rerenderinguseQuerywill no longer trigger areobservewhich may cause network fetches. Instead, the changed options will be applied to the next cache update or fetch.Options that now trigger a
reobservewhen changed between renders are:queryvariablesskip- Changing
fetchPolicyto or fromstandby
-
#12714
0e39469Thanks @phryneas! - Rework option handling forfetchMore.- Previously, if the
queryoption was specified, no options would be inherited
from the underlyingObservableQuery.
Now, even ifqueryis specified, all unspecified options except forvariableswill be inherited from the underlyingObservableQuery. - If
queryis not specified,variableswill still be shallowly merged with thevariablesof the underlyingObservableQuery. If aqueryoption is specified, thevariablespassed tofetchMoreare used instead. errorPolicyoffetchMorewill now always default to"none"instead of inherited from theObservableQueryoptions. This can prevent accidental cache writes of partial data for a paginated query. To opt into receive partial data that may be written to the cache, pass anerrorPolicytofetchMoreto override the default.
- Previously, if the
-
#12700
8e96e08Thanks @phryneas! - Added a newStreamingtype that will markdatain results whiledataStatus
is"streaming".Streaming<TData>defaults toTData, but can be overwritten in userland to
integrate with different codegen dialects.You can override this type globally - this example shows how to override it
withDeepPartial<TData>:import { HKT, DeepPartial } from "@apollo/client/utilities"; type StreamingOverride<TData> = DeepPartial<TData>; interface StreamingOverrideHKT extends HKT { return: StreamingOverride<this["arg1"]>; } declare module "@apollo/client" { export interface TypeOverrides { Streaming: StreamingOverrideHKT; } }
-
#12499
ce35ea2Thanks @phryneas! - Enable React compiler for hooks in ESM builds. -
#12704
45dba43Thanks @jerelmiller! - TheErrorResponseobject passed to thedisableandretrycallback options provided tocreatePersistedQueryLinkno longer provides separategraphQLErrorsandnetworkErrorproperties and instead have been combined to a singleerrorproperty of typeErrorLike.// The following also applies to the `retry` function since it has the same signature createPersistedQueryLink({ - disable: ({ graphQLErrors, networkError }) => { + disable: ({ error }) => { - if (graphQLErrors) { + if (CombinedGraphQLErrors.is(error)) { // ... handle GraphQL errors } - if (networkError) { + if (error) { // ... handle link errors } // optionally check for a specific kind of error - if (networkError) { + if (ServerError.is(error)) { // ... handle a server error } });The
responseproperty has also been renamed toresult.createPersistedQueryLink({ - disable: ({ response }) => { + disable: ({ result }) => { // ... handle GraphQL errors } } }); -
#12712
bbb2b61Thanks @jerelmiller! -cache-onlyqueries no longer poll when apollIntervalis set. Instead a warning is now emitted that polling has no effect. If thefetchPolicyis changed tocache-onlyafter polling is already active, polling is stopped. -
#12704
45dba43Thanks @jerelmiller! - Theresponseproperty inonErrorlink has been renamed toresult.- onError(({ response }) => { + onError(({ result }) => { // ... });
-
#12715
0be0b3fThanks @phryneas! - All links are now available as classes. The old creator functions have been deprecated.Please migrate these function calls to class creations:
import { - setContext + SetContextLink } from "@apollo/client/link/context" -const link = setContext(...) +const link = new SetContextLink(...)import { - createHttpLink + HttpLink } from "@apollo/client/link/http" -const link = createHttpLink(...) +const link = new HttpLink(...)import { - createPersistedQueryLink + PersistedQueryLink } from "@apollo/client/link/persisted-queries" -const link = createPersistedQueryLink(...) +const link = new PersistedQueryLink(...)import { - removeTypenameFromVariables + RemoveTypenameFromVariablesLink } from "@apollo/client/link/remove-typename" -const link = removeTypenameFromVariables(...) +const link = new RemoveTypenameFromVariablesLink(...)
Minor Changes
-
#12711
f730f83Thanks @jerelmiller! - Add anextensionsproperty toCombinedGraphQLErrorsto capture any extensions from the original response. -
#12700
8e96e08Thanks @phryneas! - The callback function that can be passed to theApolloClient.mutate
refetchQueriesoption will now receive aFormattedExecutionResultwith an
additionaldataStateoption that describes if the result is"streaming"
or"complete".
This indicates whether thedatavalue is of typeUnmasked<TData>(if"complete")Streaming<Unmasked<TData>>(if"streaming")
-
#12714
0e39469Thanks @phryneas! - Allow passingerrorPolicyoption tofetchMoreand change default value to "none". -
#12714
0e39469Thanks @phryneas! - TheFetchMoreQueryOptionstype has been inlined intoFetchMoreOptions, and
FetchMoreQueryOptionshas been removed. -
#12700 [`8e96...
@apollo/[email protected]
Major Changes
-
#12673
cee90abThanks @phryneas! - TheincludeExtensionsoption ofHttpLinkandBatchHttpLinknow defaults
totrue.If
includeExtensionsistrue, butextensionsis not set or empty, extensions
will not be included in outgoing requests. -
#12673
cee90abThanks @phryneas! - TheApolloClientconstructor optionsnameandversionthat are used to
configure the client awareness feature have moved onto aclientAwarenesskey.const client = new ApolloClient({ // .. - name: "my-app", - version: "1.0.0", + clientAwareness: { + name: "my-app", + version: "1.0.0", + }, }); -
#12690
5812759Thanks @phryneas! - Aliasing any other field to__typenameis now forbidden. -
#12690
5812759Thanks @phryneas! - Aliasing a field to an alias beginning with__ac_is now forbidden - this namespace is now reserved for internal use. -
#12673
cee90abThanks @phryneas! - Adds enhanced client awareness to the client.HttpLinkandBatchHttpLinkwill now per default send information about the
client library you are using inextensions.This could look like this:
{ "query": "query GetUser($id: ID!) { user(id: $id) { __typename id name } }", "variables": { "id": 5 }, "extensions": { "clientLibrary": { "name": "@apollo/client", "version": "4.0.0" } } }This feature can be disabled by passing
enhancedClientAwareness: { transport: false }to your
ApolloClient,HttpLinkorBatchHttpLinkconstructor options.
Minor Changes
-
#12698
be77d1aThanks @phryneas! - Adjusted the accept header for multipart requests according to the new GraphQL over HTTP spec with these changes:-multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/json +multipart/mixed;boundary=graphql;subscriptionSpec=1.0,application/graphql-response+json,application/json;q=0.9
-multipart/mixed;deferSpec=20220824,application/json +multipart/mixed;deferSpec=20220824,application/graphql-response+json,application/json;q=0.9
-
#12673
cee90abThanks @phryneas! - Add the newClientAwarenessLink.This link is already included in
HttpLinkandBatchHttpLinkto enable the
"client awareness" and "enhanced client awareness" features, but you can also use
ClientAwarenessLinkdirectly in your link chain to combine it with other
terminating links.If you want to save the bundle size that
ClientAwarenessLinkadds toHttpLink
andBatchHttpLink, you can useBaseHttpLinkorBaseBatchHttpLinkinstead.
These links come without theClientAwarenessLinkincluded.For example:
import { ApolloClient, - HttpLink, } from "@apollo/client"; +import { BaseHttpLink } from "@apollo/client/link/http"; const client = new ApolloClient({ - link: new HttpLink({ + link: new BaseHttpLink({ uri, }), cache: new InMemoryCache(), }); -
#12698
be77d1aThanks @phryneas! - Adds anacceptoption toHttpOptionsthat allows to add additionalAcceptheaders to be merged in without overriding user-specified or default accept headers.