Releases: apollographql/apollo-client
v4.0.0-alpha.4
Major Changes
-
#12463
3868df8
Thanks @jerelmiller! -ObservableQuery.setOptions
has been removed as it was an alias ofreobserve
. Prefer usingreobserve
directly instead.const observable = client.watchQuery(options); // Use reobserve to set new options and reevaluate the query - observable.setOptions(newOptions); + observable.reobserve(newOptions);
As a result of this change,
reobserve
has been marked for public use and is no longer considered an internal API. ThenewNetworkStatus
argument has been removed to facilitate this change. -
#12470
d32902f
Thanks @phryneas! -ssrMode
,ssrForceFetchDelay
anddisableNetworkFetches
have been reworked:Previously, a
ObservableQuery
created byclient.query
orclient.watchQuery
while one of those were active would permanently be changed from afetchPolicy
of"network-only"
or"cache-and-network"
to"cache-first"
, and stay that way
even long afterdisableNetworkFetches
would have been deactivated.Now, the
ObservableQuery
will keep their originalfetchPolicy
, but queries
made duringdisableNetworkFetches
will just apply thefetchPolicy
replacement
at request time, just for that one request.ApolloClient.disableNetworkFetches
has been renamed toApolloClient.prioritizeCacheValues
to better reflect this behaviour. -
#12465
a132163
Thanks @jerelmiller! - Flatten out React hook types. As a result, the base types have been removed. Prefer using the hook types instead. Removed types include:BaseMutationOptions
BaseQueryOptions
BaseSubscriptionOptions
ObservableQueryFields
MutationSharedOptions
QueryFunctionOptions
-
#12463
3868df8
Thanks @jerelmiller! -useQuery
no longer returnsreobserve
as part of its result. It was possible to usereobserve
to set new options on the underlyingObservableQuery
instance which differed from the options passed to the hook. This could result in unexpected results. Instead prefer to rerender the hook with new options.
Patch Changes
- #12465
a132163
Thanks @jerelmiller! - Rename all React hook result types and options. These types have all moved under a namespace that matches the hook name. For example,useQuery
exportsuseQuery.Options
anduseQuery.Result
types. As such, the old hook types have been deprecated and will be removed in v5.
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.