Major Changes
-
#12559
49ace0e
Thanks @jerelmiller! -ObservableQuery.variables
can now be reset back to empty when callingreobserve
withvariables: undefined
. Previously thevariables
key would be ignored sovariables
would remain unchanged. -
#12559
49ace0e
Thanks @jerelmiller! -never
is no longer supported as a validTVariables
generic argument for APIs that requirevariables
as part of its type. UseRecord<string, never>
instead. -
#12559
49ace0e
Thanks @jerelmiller! - When passing avariables
key with the valueundefined
, the value will be replaced by the default value in the query, if it is provided, rather than leave it asundefined
.// given this query const query = gql` query PaginatedQuery($limit: Int! = 10, $offset: Int) { list(limit: $limit, offset: $offset) { id } } `; const observable = client.query({ query, variables: { limit: 5, offset: 0 }, }); console.log(observable.variables); // => { limit: 5, offset: 0 } observable.reobserve({ variables: { limit: undefined, offset: 10 } }); // limit is now `10`. This would previously be `undefined` console.log(observable.variables); // => { limit: 10, offset: 10 }
-
#12562
90bf0e6
Thanks @jerelmiller! -client.query
no longer supports afetchPolicy
ofstandby
.standby
does not fetch and did not returndata
.standby
is meant for watched queries where fetching should be on hold.
Minor Changes
-
#12557
51d26ae
Thanks @jerelmiller! - Add ability to specify message formatter forCombinedGraphQLErrors
andCombinedProtocolErrors
. To provide your own message formatter, override the staticformatMessage
property on these classes.CombinedGraphQLErrors.formatMessage = ( errors, { result, defaultFormatMessage } ) => { return "Some formatted message"; }; CombinedProtocolErrors.formatMessage = (errors, { defaultFormatMessage }) => { return "Some formatted message"; };
-
#12546
5dffbbe
Thanks @jerelmiller! - Add a staticis
method to error types defined by Apollo Client.is
makes it simpler to determine whether an error is a specific type, which can be helpful in cases where you'd like to narrow the error type in order to use specific properties from that error.This change applies to the following error types:
CombinedGraphQLErrors
CombinedProtocolErrors
ServerError
ServerParseError
UnconventionalError
Example
import { CombinedGraphQLErrors } from "@apollo/client"; if (CombinedGraphQLErrors.is(error)) { console.log(error.message); error.errors.forEach((graphQLError) => console.log(graphQLError.message)); }
-
#12561
99d72bf
Thanks @jerelmiller! - Add the ability to detect if an error was an error was emitted from the link chain. This is useful if your application throws custom errors in other areas of the application and you'd like to differentiate them from errors emitted by the link chain itself.To detect if an error was emitted from the link chain, use
LinkError.is
.import { LinkError } from "@apollo/client"; client.query({ query }).catch((error) => { if (LinkError.is(error)) { // This error originated from the link chain } });
Patch Changes
-
#12559
49ace0e
Thanks @jerelmiller! - Thevariables
option used with various APIs are now enforced more consistently across the client whenTVariables
contains required variables. If requiredvariables
are not provided, TypeScript will now complain that it requires avariables
option.This change affects the following APIs:
client.query
client.mutate
client.subscribe
client.watchQuery
useBackgroundQuery
useQuery
useSubscription
useSuspenseQuery
-
#12559
49ace0e
Thanks @jerelmiller! - Fix type ofvariables
returned fromuseLazyQuery
. Whencalled
isfalse
,variables
is nowPartial<TVariables>
instead ofTVariables
. -
#12562
90bf0e6
Thanks @jerelmiller! -client.query
no longer supportsnotifyOnNetworkStatusChange
in options. An error will be thrown if this option is set. The effects of this option were not observable byclient.query
sinceclient.query
emits a single result. -
#12557
51d26ae
Thanks @jerelmiller! - Update format of the error message forCombinedGraphQLErrors
andCombinedProtocolErrors
to be more like v3.x.console.log(error.message); - `The GraphQL server returned with errors: - - Email not found - - Username already in use` + `Email not found + Username already in use`
-
#12559
49ace0e
Thanks @jerelmiller! -ObservableQuery.variables
has been updated to returnTVariables
rather thanTVariables | undefined
. This is more consistent with the runtime value where an empty object ({}
) will be returned when thevariables
option is not provided.