Major Changes
-
#12559
49ace0eThanks @jerelmiller! -ObservableQuery.variablescan now be reset back to empty when callingreobservewithvariables: undefined. Previously thevariableskey would be ignored sovariableswould remain unchanged. -
#12559
49ace0eThanks @jerelmiller! -neveris no longer supported as a validTVariablesgeneric argument for APIs that requirevariablesas part of its type. UseRecord<string, never>instead. -
#12559
49ace0eThanks @jerelmiller! - When passing avariableskey 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
90bf0e6Thanks @jerelmiller! -client.queryno longer supports afetchPolicyofstandby.standbydoes not fetch and did not returndata.standbyis meant for watched queries where fetching should be on hold.
Minor Changes
-
#12557
51d26aeThanks @jerelmiller! - Add ability to specify message formatter forCombinedGraphQLErrorsandCombinedProtocolErrors. To provide your own message formatter, override the staticformatMessageproperty on these classes.CombinedGraphQLErrors.formatMessage = ( errors, { result, defaultFormatMessage } ) => { return "Some formatted message"; }; CombinedProtocolErrors.formatMessage = (errors, { defaultFormatMessage }) => { return "Some formatted message"; };
-
#12546
5dffbbeThanks @jerelmiller! - Add a staticismethod to error types defined by Apollo Client.ismakes 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:
CombinedGraphQLErrorsCombinedProtocolErrorsServerErrorServerParseErrorUnconventionalError
Example
import { CombinedGraphQLErrors } from "@apollo/client"; if (CombinedGraphQLErrors.is(error)) { console.log(error.message); error.errors.forEach((graphQLError) => console.log(graphQLError.message)); }
-
#12561
99d72bfThanks @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
49ace0eThanks @jerelmiller! - Thevariablesoption used with various APIs are now enforced more consistently across the client whenTVariablescontains required variables. If requiredvariablesare not provided, TypeScript will now complain that it requires avariablesoption.This change affects the following APIs:
client.queryclient.mutateclient.subscribeclient.watchQueryuseBackgroundQueryuseQueryuseSubscriptionuseSuspenseQuery
-
#12559
49ace0eThanks @jerelmiller! - Fix type ofvariablesreturned fromuseLazyQuery. Whencalledisfalse,variablesis nowPartial<TVariables>instead ofTVariables. -
#12562
90bf0e6Thanks @jerelmiller! -client.queryno longer supportsnotifyOnNetworkStatusChangein options. An error will be thrown if this option is set. The effects of this option were not observable byclient.querysinceclient.queryemits a single result. -
#12557
51d26aeThanks @jerelmiller! - Update format of the error message forCombinedGraphQLErrorsandCombinedProtocolErrorsto 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
49ace0eThanks @jerelmiller! -ObservableQuery.variableshas been updated to returnTVariablesrather thanTVariables | undefined. This is more consistent with the runtime value where an empty object ({}) will be returned when thevariablesoption is not provided.