Skip to content

Commit 64f4569

Browse files
authored
Merge pull request #8553 from apollographql/optional-chaining-on-usequery
Optional chaining on usequery
2 parents b677262 + 67a0ecb commit 64f4569

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
- The [`nextFetchPolicy`](https://github.com/apollographql/apollo-client/pull/6893) option for `client.watchQuery` and `useQuery` will no longer be removed from the `options` object after it has been applied, and instead will continue to be applied any time `options.fetchPolicy` is reset to another value, until/unless the `options.nextFetchPolicy` property is removed from `options`. <br/>
8585
[@benjamn](https://github.com/benjamn) in [#8465](https://github.com/apollographql/apollo-client/pull/8465)
8686

87+
- The `fetchMore`, `subscribeToMore`, and `updateQuery` functions returned from the `useQuery` hook may now return undefined in edge cases where the functions are called when the component is unmounted <br/> [@noghartt](https://github.com/noghartt) in [#7980](https://github.com/apollographql/apollo-client/pull/7980).
88+
8789
### Bug fixes
8890

8991
- In Apollo Client 2.x, a `refetch` operation would always replace existing data in the cache. With the introduction of field policy `merge` functions in Apollo Client 3, existing field values could be inappropriately combined with incoming field values by a custom `merge` function that does not realize a `refetch` has happened.
@@ -123,6 +125,8 @@
123125
- Make `readField` default to reading from current object only when the `from` option/argument is actually omitted, not when `from` is passed to `readField` with an undefined value. A warning will be printed when this situation occurs. <br/>
124126
[@benjamn](https://github.com/benjamn) in [#8508](https://github.com/apollographql/apollo-client/pull/8508)
125127

128+
- The `fetchMore`, `subscribeToMore`, and `updateQuery` functions no longer throw `undefined` errors <br/> [@noghartt](https://github.com/noghartt) in [#7980](https://github.com/apollographql/apollo-client/pull/7980).
129+
126130
## Apollo Client 3.3.21
127131

128132
### Bug fixes

src/react/data/QueryData.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,14 +495,14 @@ export class QueryData<TData, TVariables> extends OperationData<
495495
private obsFetchMore = (
496496
fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &
497497
FetchMoreOptions<TData, TVariables>
498-
) => this.currentObservable!.fetchMore(fetchMoreOptions);
498+
) => this.currentObservable?.fetchMore(fetchMoreOptions);
499499

500500
private obsUpdateQuery = <TVars = TVariables>(
501501
mapFn: (
502502
previousQueryResult: TData,
503503
options: UpdateQueryOptions<TVars>
504504
) => TData
505-
) => this.currentObservable!.updateQuery(mapFn);
505+
) => this.currentObservable?.updateQuery(mapFn);
506506

507507
private obsStartPolling = (pollInterval: number) => {
508508
this.currentObservable?.startPolling(pollInterval);
@@ -521,7 +521,7 @@ export class QueryData<TData, TVariables> extends OperationData<
521521
TSubscriptionVariables,
522522
TSubscriptionData
523523
>
524-
) => this.currentObservable!.subscribeToMore(options);
524+
) => this.currentObservable?.subscribeToMore(options);
525525

526526
private observableQueryFields() {
527527
return {

0 commit comments

Comments
 (0)