Releases: apollographql/apollo-client
v4.0.0-alpha.3
Major Changes
-
#12457
32e85ea
Thanks @jerelmiller! - Network errors triggered by queries now adhere to theerrorPolicy
. This means that GraphQL errors and network errors now behave the same way. Previously promise-based APIs, such asclient.query
, would reject the promise with the network error even iferrorPolicy
was set toignore
. The promise is now resolved with theerror
property set to the network error instead. -
#12464
0595f39
Thanks @jerelmiller! - Remove thecalled
property fromuseQuery
.
v3.13.5
v4.0.0-alpha.2
Major Changes
-
#12450
876d070
Thanks @jerelmiller! - RemoveTSerialized
generic argument toApolloCache
. TheApolloCache
base cache abstraction now returnsunknown
forcache.extract
which can be overridden by a cache subclass. -
#12450
876d070
Thanks @jerelmiller! - Remove theTCacheShape
generic argument toApolloClient
.client.extract()
now returnsunknown
by default. You will either need to type-cast this to the expected serialized shape, or use thecache.extract()
directly from the subclass to get more specific types. -
#12446
ab920d2
Thanks @jerelmiller! - Removes thedefaultOptions
option fromuseQuery
. Use options directly or use the globalApolloClient
defaultOptions
. -
#12442
c5ead08
Thanks @jerelmiller! - Remove the deprecatedcanonizeResults
option. It was prone to memory leaks. As such, some results that were referentially equal whencanonizeResults
option was set totrue
no longer retain the same object identity. -
#12442
c5ead08
Thanks @jerelmiller! - RemoveresetResultIdentities
option fromInMemoryCache.gc()
. This affected object canonization which has been removed. -
#12451
77e1b13
Thanks @jerelmiller! - Default theTData
generic type tounknown
in all APIs that use aTData
generic argument such asuseQuery
,client.query
, etc.
Patch Changes
v4.0.0-alpha.1
Major Changes
-
#12433
b86e50b
Thanks @phryneas! - Remove workarounds for streaming with non-WhatWG response bodies to reduce bundle size.This removes support for
fetch
implementations that return Node Streams, Async Iterators or Blob instances asResponse.body
.In the WhatWG Fetch specification,
Response.body
is specified as a WhatWG ReadableStream.At this point in time, this is natively supported in browsers,
node
and React Native (via react-native-fetch-api, see our setup instructions for React Native).If you are using an older
fetch
polyfill that deviates from the spec, this might not be compatible - for example, node-fetch returns a nodeReadable
instead of aReadableStream
.
In those cases, please switch to a compatible alternative such as thenode
-nativefetch
, orundici
.
Minor Changes
-
#12438
5089516
Thanks @phryneas! - Droprehackt
dependency.
We can now directly import fromreact
without causing build errors in RSC. -
#12437
4779dc7
Thanks @phryneas! - Remove polyfills for Object.freeze,seal and preventExtensions in React NativeThese polyfills were only necessary until React Native 0.59, which
patched the problem on
the React Native side.With React Native 0.61, the
Map
function was completely replaced
with a native implementation that never had the problems we guarded against. -
#12438
5089516
Thanks @phryneas! - Addreact-server
entry point with stubs for normal exports.
v4.0.0-alpha.0
Major Changes
-
#12384
6aa6fd3
Thanks @jerelmiller! - Remove theasyncMap
utility function. Instead use one of the RxJS operators that creates Observables from promises, such asfrom
. -
#12398
8cf5077
Thanks @jerelmiller! - Removes theisApolloError
utility function to check if the error object is anApolloError
instance. Useinstanceof
to check for more specific error types that replaceApolloError
. -
#12379
ef892b4
Thanks @jerelmiller! - Removes theaddTypename
option fromInMemoryCache
andMockedProvider
.__typename
is now always added to the outgoing query document when usingInMemoryCache
and cannot be disabled.If you are using
<MockedProvider />
withaddTypename={false}
, ensure that your mocked responses include a__typename
field. This will ensure cache normalization kicks in and behaves more like production. -
#12396
00f3d0a
Thanks @jerelmiller! - Remove the deprecatederrors
property fromuseQuery
anduseLazyQuery
. Read errors from theerror
property instead. -
#12222
d1a9054
Thanks @jerelmiller! - Drop support for React 16. -
#12376
a0c996a
Thanks @jerelmiller! - Remove deprecatedignoreResults
option fromuseMutation
. If you don't want to synchronize component state with the mutation, useuseApolloClient
to access your client instance and useclient.mutate
directly. -
#12384
6aa6fd3
Thanks @jerelmiller! - Unusubscribing fromObservableQuery
while a request is in flight will no longer terminate the request by unsubscribing from the link observable. -
#12367
e6af35e
Thanks @jerelmiller! - ThepreviousData
property onuseLazyQuery
will now change only whendata
changes. PreviouslypreviousData
would change to the same value asdata
while the query was loading. -
#12224
51e6c0f
Thanks @jerelmiller! - Remove deprecatedpartialRefetch
option. -
#12407
8b1390b
Thanks @jerelmiller! - Callingrefetch
with new variables will now set thenetworkStatus
torefetch
instead ofsetVariables
. -
#12384
6aa6fd3
Thanks @jerelmiller! - Remove theiterateObserversSafely
utility function. -
#12398
8cf5077
Thanks @jerelmiller! - Apollo Client no longer wraps errors inApolloError
.ApolloError
has been replaced with separate error classes depending on the cause of the error. As such, APIs that return anerror
property have been updated to use the genericError
type. Useinstanceof
to check for more specific error types.Migration guide
ApolloError
encapsulated 4 main error properties. The type of error would determine which property was set:graphqlErrors
- Errors returned from theerrors
field by the GraphQL servernetworkError
- Any non-GraphQL error that caused the query to failprotocolErrors
- Transport-level errors that occur during multipart HTTP subscriptionsclientErrors
- A space to define custom errors. Mostly unused.
These errors were mutally exclusive, meaning both
networkError
andgraphqlErrors
were never set simultaneously. The following replaces each of these fields fromApolloError
.graphqlErrors
GraphQL errors are now encapsulated in a
CombinedGraphQLErrors
instance. You can access the raw GraphQL errors via theerrors
property.import { CombinedGraphQLErrors } from "@apollo/client"; // ... const { error } = useQuery(query); if (error && error instanceof CombinedGraphQLErrors) { console.log(error.errors); }
networkError
Network errors are no longer wrapped and are instead passed through directly.
const client = new ApolloClient({ link: new ApolloLink(() => { return new Observable((observer) => { observer.error(new Error("Test error")); }); }), }); // ... const { error } = useQuery(query); // error is `new Error('Test error')`;
protocolErrors
Protocol errors are now encapsulated in a
CombinedProtocolErrors
instance. You can access the raw protocol errors via theerrors
property.import { CombinedProtocolErrors } from "@apollo/client"; // ... const { error } = useSubscription(subscription); if (error && error instanceof CombinedProtocolErrors) { console.log(error.errors); }
clientErrors
These were unused by the client and have no replacement. Any non-GraphQL or non-protocol errors are now passed through unwrapped.
Strings as errors
If the link sends a string error, Apollo Client will wrap this in an
Error
instance. This ensureserror
properties are guaranteed to be of typeError
.const client = new ApolloClient({ link: new ApolloLink(() => { return new Observable((observer) => { // Oops we sent a string instead of wrapping it in an `Error` observer.error("Test error"); }); }), }); // ... const { error } = useQuery(query); // The error string is wrapped and returned as `new Error('Test error')`;
Non-error types
If the link chain sends any other object type as an error, Apollo Client will wrap this in an
UnknownError
instance with thecause
set to the original object. This ensureserror
properties are guaranteed to be of typeError
.const client = new ApolloClient({ link: new ApolloLink(() => { return new Observable((observer) => { observer.error({ message: "Not a proper error type" }); }); }), }); // ... const { error } = useQuery(query); // error is an `UnknownError` instance. error.cause returns the original object.
-
#12384
6aa6fd3
Thanks @jerelmiller! - RemovefromError
utility function. UsethrowError
instead. -
#12211
c2736db
Thanks @jerelmiller! - Remove the deprecatedgraphql
,withQuery
,withMutation
,withSubscription
, andwithApollo
hoc components. Use the provided React hooks instead. -
#12262
10ef733
Thanks @jerelmiller! - RemoveitAsync
test utility. -
#12398
8cf5077
Thanks @jerelmiller! - Updates theServerError
andServerParseError
types to be properError
subclasses. Perviously these were plainError
intances with additional properties added at runtime. All properties are retained, butinstanceof
checks now work correctly.import { ServerError, ServerParseError } from "@apollo/client"; if (error instanceof ServerError) { // ... } if (error instanceof ServerParseError) { // ....
v3.13.4
Patch Changes
- #12420
fee9368
Thanks @jorenbroekema! - Use import star fromrehackt
to prevent issues with importing named exports from external CJS modules.
v3.13.3
Patch Changes
-
#12362
f6d387c
Thanks @jerelmiller! - Fixes an issue where callingobservableQuery.getCurrentResult()
when theerrorPolicy
was set toall
would return thenetworkStatus
asNetworkStatus.ready
when there were errors returned in the result. This has been corrected to reportNetworkStatus.error
.This bug also affected the
useQuery
anduseLazyQuery
hooks and may affect you if you check fornetworkStatus
in your component.
v3.13.2
Patch Changes
-
#12409
6aa2f3e
Thanks @phryneas! - To mitigate problems when Apollo Client ends up more than once in the bundle, some unique symbols were converted intoSymbol.for
calls. -
#12392
644bb26
Thanks @Joja81! - Fixes an issue where the DeepOmit type would turn optional properties into required properties. This should only affect you if you were using the omitDeep or stripTypename utilities exported by Apollo Client. -
#12404
4332b88
Thanks @jerelmiller! - ShowNaN
rather than converting tonull
in debug messages fromMockLink
for unmatchedvariables
values.
v3.13.1
v3.13.0
Apollo Client v3.13.0 introduces a new hook, useSuspenseFragment
, as a drop-in replacement for useFragment
in apps that are using React Suspense. This is the “last” React hook we are introducing in 3.x - we think this rounds out the “big concepts” in our React Suspense and GraphQL fragment story. See the docs for information on this and our other Suspense-supporting hooks. There are some TypeScript quality-of-life improvements shipped in this release for observableQuery.updateQuery
and subscribeToMore
. Additionally, the return type of updateQuery
now includes undefined
to allow an early exit from updates. This was always supported at runtime, but was missed on the TypeScript side. On the runtime side, we’ve fixed query deduplication behavior for multipart responses and corrected the error handling in useMutation
callbacks. onCompleted
and onError
in useQuery
and useLazyQuery
have been deprecated for multiple reasons. See below for full details 👀
Minor Changes
-
#12066
c01da5d
Thanks @jerelmiller! - Adds a newuseSuspenseFragment
hook.useSuspenseFragment
suspends untildata
is complete. It is a drop-in replacement foruseFragment
when you prefer to use Suspense to control the loading state of a fragment. See the documentation for more details. -
#12174
ba5cc33
Thanks @jerelmiller! - Ensure errors thrown in theonCompleted
callback fromuseMutation
don't callonError
. -
#12340
716d02e
Thanks @phryneas! - Deprecate theonCompleted
andonError
callbacks ofuseQuery
anduseLazyQuery
.
For more context, please see the related issue on GitHub. -
#12276
670f112
Thanks @Cellule! - Provide a more type-safe option for the previous data value passed toobservableQuery.updateQuery
. Using it could result in crashes at runtime as this callback could be called with partial data even though its type reported the value as a complete result.The
updateQuery
callback function is now called with a new type-safepreviousData
property and a newcomplete
property in the 2nd argument that determines whetherpreviousData
is a complete or partial result.As a result of this change, it is recommended to use the
previousData
property passed to the 2nd argument of the callback rather than using the previous data value from the first argument since that value is not type-safe. The first argument is now deprecated and will be removed in a future version of Apollo Client.observableQuery.updateQuery( (unsafePreviousData, { previousData, complete }) => { previousData; // ^? TData | DeepPartial<TData> | undefined if (complete) { previousData; // ^? TData } else { previousData; // ^? DeepPartial<TData> | undefined } } );
-
#12174
ba5cc33
Thanks @jerelmiller! - Reject the mutation promise if errors are thrown in theonCompleted
callback ofuseMutation
.
Patch Changes
-
#12276
670f112
Thanks @Cellule! - Fix the return type of theupdateQuery
function to allow forundefined
.updateQuery
had the ability to bail out of the update by returning a falsey value, but the return type enforced a query value.observableQuery.updateQuery( (unsafePreviousData, { previousData, complete }) => { if (!complete) { // Bail out of the update by returning early return; } // ... } );
-
#12296
2422df2
Thanks @Cellule! - Deprecate optionignoreResults
inuseMutation
.
Once this option is removed, existing code still using it might see increase in re-renders.
If you don't want to synchronize your component state with the mutation, please useuseApolloClient
to get your ApolloClient instance and callclient.mutate
directly. -
#12338
67c16c9
Thanks @phryneas! - In case of a multipart response (e.g. with@defer
), query deduplication will
now keep going until the final chunk has been received. -
#12276
670f112
Thanks @Cellule! - Fix the type of thevariables
property passed as the 2nd argument to thesubscribeToMore
callback. This was previously reported as thevariables
type for the subscription itself, but is now properly typed as the queryvariables
.