|
1 | 1 | # @apollo/client |
2 | 2 |
|
| 3 | +## 4.0.0-alpha.10 |
| 4 | + |
| 5 | +### Major Changes |
| 6 | + |
| 7 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - `ObservableQuery.variables` can now be reset back to empty when calling `reobserve` with `variables: undefined`. Previously the `variables` key would be ignored so `variables` would remain unchanged. |
| 8 | + |
| 9 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - `never` is no longer supported as a valid `TVariables` generic argument for APIs that require `variables` as part of its type. Use `Record<string, never>` instead. |
| 10 | + |
| 11 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - When passing a `variables` key with the value `undefined`, the value will be replaced by the default value in the query, if it is provided, rather than leave it as `undefined`. |
| 12 | + |
| 13 | + ```ts |
| 14 | + // given this query |
| 15 | + const query = gql` |
| 16 | + query PaginatedQuery($limit: Int! = 10, $offset: Int) { |
| 17 | + list(limit: $limit, offset: $offset) { |
| 18 | + id |
| 19 | + } |
| 20 | + } |
| 21 | + `; |
| 22 | + |
| 23 | + const observable = client.query({ |
| 24 | + query, |
| 25 | + variables: { limit: 5, offset: 0 }, |
| 26 | + }); |
| 27 | + console.log(observable.variables); // => { limit: 5, offset: 0 } |
| 28 | + |
| 29 | + observable.reobserve({ variables: { limit: undefined, offset: 10 } }); |
| 30 | + // limit is now `10`. This would previously be `undefined` |
| 31 | + console.log(observable.variables); // => { limit: 10, offset: 10 } |
| 32 | + ``` |
| 33 | + |
| 34 | +- [#12562](https://github.com/apollographql/apollo-client/pull/12562) [`90bf0e6`](https://github.com/apollographql/apollo-client/commit/90bf0e61516a382182f212ac8ab891099e2eb009) Thanks [@jerelmiller](https://github.com/jerelmiller)! - `client.query` no longer supports a `fetchPolicy` of `standby`. `standby` does not fetch and did not return `data`. `standby` is meant for watched queries where fetching should be on hold. |
| 35 | + |
| 36 | +### Minor Changes |
| 37 | + |
| 38 | +- [#12557](https://github.com/apollographql/apollo-client/pull/12557) [`51d26ae`](https://github.com/apollographql/apollo-client/commit/51d26ae631c6631a189c98ea9357b18e77a9a876) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add ability to specify message formatter for `CombinedGraphQLErrors` and `CombinedProtocolErrors`. To provide your own message formatter, override the static `formatMessage` property on these classes. |
| 39 | + |
| 40 | + ```ts |
| 41 | + CombinedGraphQLErrors.formatMessage = ( |
| 42 | + errors, |
| 43 | + { result, defaultFormatMessage } |
| 44 | + ) => { |
| 45 | + return "Some formatted message"; |
| 46 | + }; |
| 47 | + |
| 48 | + CombinedProtocolErrors.formatMessage = (errors, { defaultFormatMessage }) => { |
| 49 | + return "Some formatted message"; |
| 50 | + }; |
| 51 | + ``` |
| 52 | + |
| 53 | +- [#12546](https://github.com/apollographql/apollo-client/pull/12546) [`5dffbbe`](https://github.com/apollographql/apollo-client/commit/5dffbbe407eb1d9adbcb0fff89f2d3a75dc1ad2b) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Add a static `is` 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. |
| 54 | + |
| 55 | + This change applies to the following error types: |
| 56 | + |
| 57 | + - `CombinedGraphQLErrors` |
| 58 | + - `CombinedProtocolErrors` |
| 59 | + - `ServerError` |
| 60 | + - `ServerParseError` |
| 61 | + - `UnconventionalError` |
| 62 | + |
| 63 | + **Example** |
| 64 | + |
| 65 | + ```ts |
| 66 | + import { CombinedGraphQLErrors } from "@apollo/client"; |
| 67 | + |
| 68 | + if (CombinedGraphQLErrors.is(error)) { |
| 69 | + console.log(error.message); |
| 70 | + error.errors.forEach((graphQLError) => console.log(graphQLError.message)); |
| 71 | + } |
| 72 | + ``` |
| 73 | + |
| 74 | +- [#12561](https://github.com/apollographql/apollo-client/pull/12561) [`99d72bf`](https://github.com/apollographql/apollo-client/commit/99d72bfdb38e3d9679f60b9acb065a84e3b42fd6) Thanks [@jerelmiller](https://github.com/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. |
| 75 | + |
| 76 | + To detect if an error was emitted from the link chain, use `LinkError.is`. |
| 77 | + |
| 78 | + ```ts |
| 79 | + import { LinkError } from "@apollo/client"; |
| 80 | + |
| 81 | + client.query({ query }).catch((error) => { |
| 82 | + if (LinkError.is(error)) { |
| 83 | + // This error originated from the link chain |
| 84 | + } |
| 85 | + }); |
| 86 | + ``` |
| 87 | + |
| 88 | +### Patch Changes |
| 89 | + |
| 90 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - The `variables` option used with various APIs are now enforced more consistently across the client when `TVariables` contains required variables. If required `variables` are not provided, TypeScript will now complain that it requires a `variables` option. |
| 91 | + |
| 92 | + This change affects the following APIs: |
| 93 | + |
| 94 | + - `client.query` |
| 95 | + - `client.mutate` |
| 96 | + - `client.subscribe` |
| 97 | + - `client.watchQuery` |
| 98 | + - `useBackgroundQuery` |
| 99 | + - `useQuery` |
| 100 | + - `useSubscription` |
| 101 | + - `useSuspenseQuery` |
| 102 | + |
| 103 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix type of `variables` returned from `useLazyQuery`. When `called` is `false`, `variables` is now `Partial<TVariables>` instead of `TVariables`. |
| 104 | + |
| 105 | +- [#12562](https://github.com/apollographql/apollo-client/pull/12562) [`90bf0e6`](https://github.com/apollographql/apollo-client/commit/90bf0e61516a382182f212ac8ab891099e2eb009) Thanks [@jerelmiller](https://github.com/jerelmiller)! - `client.query` no longer supports `notifyOnNetworkStatusChange` in options. An error will be thrown if this option is set. The effects of this option were not observable by `client.query` since `client.query` emits a single result. |
| 106 | + |
| 107 | +- [#12557](https://github.com/apollographql/apollo-client/pull/12557) [`51d26ae`](https://github.com/apollographql/apollo-client/commit/51d26ae631c6631a189c98ea9357b18e77a9a876) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Update format of the error message for `CombinedGraphQLErrors` and `CombinedProtocolErrors` to be more like v3.x. |
| 108 | + |
| 109 | + ```diff |
| 110 | + console.log(error.message); |
| 111 | + - `The GraphQL server returned with errors: |
| 112 | + - - Email not found |
| 113 | + - - Username already in use` |
| 114 | + + `Email not found |
| 115 | + + Username already in use` |
| 116 | + ``` |
| 117 | + |
| 118 | +- [#12559](https://github.com/apollographql/apollo-client/pull/12559) [`49ace0e`](https://github.com/apollographql/apollo-client/commit/49ace0e2119b7fd5997dcf051002ebd4ba2e0bc4) Thanks [@jerelmiller](https://github.com/jerelmiller)! - `ObservableQuery.variables` has been updated to return `TVariables` rather than `TVariables | undefined`. This is more consistent with the runtime value where an empty object (`{}`) will be returned when the `variables` option is not provided. |
| 119 | + |
3 | 120 | ## 4.0.0-alpha.9 |
4 | 121 |
|
5 | 122 | ### Major Changes |
|
0 commit comments