@apollo/client@4.0.0-alpha.23
Pre-releaseMajor Changes
-
#12712
bbb2b61
Thanks @jerelmiller! - An error is now thrown when trying to callfetchMore
on acache-only
query. -
#12712
bbb2b61
Thanks @jerelmiller! -cache-only
queries are no longer refetched when callingclient.reFetchObservableQueries
whenincludeStandby
istrue
. -
#12705
a60f411
Thanks @jerelmiller! -cache-only
queries will now initialize withloading: false
andnetworkStatus: NetworkStatus.ready
when there is no data in the cache.This means
useQuery
will no longer render a short initial loading state before renderingloading: false
andObservableQuery.getCurrentResult()
will now returnloading: false
immediately. -
#12712
bbb2b61
Thanks @jerelmiller! -cache-only
queries are now excluded fromclient.refetchQueries
in all situations.cache-only
queries affected byupdateCache
are also excluded fromrefetchQueries
whenonQueryUpdated
is not provided. -
#12681
b181f98
Thanks @jerelmiller! - Changing most options when rerenderinguseQuery
will no longer trigger areobserve
which may cause network fetches. Instead, the changed options will be applied to the next cache update or fetch.Options that now trigger a
reobserve
when changed between renders are:query
variables
skip
- Changing
fetchPolicy
to or fromstandby
-
#12714
0e39469
Thanks @phryneas! - Rework option handling forfetchMore
.- Previously, if the
query
option was specified, no options would be inherited
from the underlyingObservableQuery
.
Now, even ifquery
is specified, all unspecified options except forvariables
will be inherited from the underlyingObservableQuery
. - If
query
is not specified,variables
will still be shallowly merged with thevariables
of the underlyingObservableQuery
. If aquery
option is specified, thevariables
passed tofetchMore
are used instead. errorPolicy
offetchMore
will now always default to"none"
instead of inherited from theObservableQuery
options. 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 anerrorPolicy
tofetchMore
to override the default.
- Previously, if the
-
#12700
8e96e08
Thanks @phryneas! - Added a newStreaming
type that will markdata
in 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
ce35ea2
Thanks @phryneas! - Enable React compiler for hooks in ESM builds. -
#12704
45dba43
Thanks @jerelmiller! - TheErrorResponse
object passed to thedisable
andretry
callback options provided tocreatePersistedQueryLink
no longer provides separategraphQLErrors
andnetworkError
properties and instead have been combined to a singleerror
property 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
response
property has also been renamed toresult
.createPersistedQueryLink({ - disable: ({ response }) => { + disable: ({ result }) => { // ... handle GraphQL errors } } });
-
#12712
bbb2b61
Thanks @jerelmiller! -cache-only
queries no longer poll when apollInterval
is set. Instead a warning is now emitted that polling has no effect. If thefetchPolicy
is changed tocache-only
after polling is already active, polling is stopped. -
#12704
45dba43
Thanks @jerelmiller! - Theresponse
property inonError
link has been renamed toresult
.- onError(({ response }) => { + onError(({ result }) => { // ... });
-
#12715
0be0b3f
Thanks @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
f730f83
Thanks @jerelmiller! - Add anextensions
property toCombinedGraphQLErrors
to capture any extensions from the original response. -
#12700
8e96e08
Thanks @phryneas! - The callback function that can be passed to theApolloClient.mutate
refetchQueries
option will now receive aFormattedExecutionResult
with an
additionaldataState
option that describes if the result is"streaming"
or"complete"
.
This indicates whether thedata
value is of typeUnmasked<TData>
(if"complete"
)Streaming<Unmasked<TData>>
(if"streaming"
)
-
#12714
0e39469
Thanks @phryneas! - Allow passingerrorPolicy
option tofetchMore
and change default value to "none". -
#12714
0e39469
Thanks @phryneas! - TheFetchMoreQueryOptions
type has been inlined intoFetchMoreOptions
, and
FetchMoreQueryOptions
has been removed. -
#12700
8e96e08
Thanks @phryneas! - Prioritize usage ofFormattedExecutionResult
overFetchResult
where applicable.Many APIs used
FetchResult
in place ofFormattedExecutionResult
, which could
cause inconsistencies.FetchResult
is now used to refer to an unhandled "raw" result as returned from
a link.
This can also include incremental results that use a different format.FormattedExecutionResult
from thegraphql
package is now used to represent
the execution of a standard GraphQL request without incremental results.
If your custom links access the
data
property, you might need to first check if
the result is a standard GraphQL result by using theisFormattedExecutionResult
helper from@apollo/client/utilities
. -
#12700
8e96e08
Thanks @phryneas! - ThemutationResult
option passed to theupdateQueries
callback now has an
additional property,dataState
with possible values of"complete"
and"streaming"
.
This indicates whether thedata
value is of typeUnmasked<TData>
(if"complete"
)Streaming<Unmasked<TData>>
(if"streaming"
)
Patch Changes
-
#12709
9d42e2a
Thanks @phryneas! - Remove these incremental-format-specific types:ExecutionPatchIncrementalResult
ExecutionPatchInitialResult
ExecutionPatchResult
IncrementalPayload
Path
-
#12677
94e58ed
Thanks @jerelmiller! - Downgrade minimum supportedrxjs
peer dependency version to 7.3.0. -
#12709
9d42e2a
Thanks @phryneas! - Slightly rework multipart response parsing.This removes last incremental-protocol-specific details from
HttpLink
andBatchHttpLink
. -
#12700
8e96e08
Thanks @phryneas! - The incremental delivery (@defer
support) implementation is now pluggable.ApolloClient
now per default ships without an incremental format implementation
and allows you to swap in the format that you want to use.Usage looks like this:
import { // this is the default NotImplementedHandler, // this implements the `@defer` transport format that ships with Apollo Router Defer20220824Handler, // this implements the `@defer` transport format that ships with GraphQL 17.0.0-alpha.2 GraphQL17Alpha2Handler, } from "@apollo/client/incremental"; const client = new ApolloClient({ cache: new InMemoryCache({ /*...*/ }), link: new HttpLink({ /*...*/ }), incrementalHandler: new Defer20220824Handler(), });
We will add handlers for other response formats that can be swapped this way
during the lifetime of Apollo Client 4.0.