Skip to content

Commit

Permalink
Add support for skip option to useSuspenseQuery and `useBackgroun…
Browse files Browse the repository at this point in the history
…dQuery` (#10940)

Co-authored-by: Alessia Bellisario <[email protected]>
  • Loading branch information
jerelmiller and alessbell authored Jun 15, 2023
1 parent befc2a3 commit 1d38f12
Show file tree
Hide file tree
Showing 9 changed files with 1,094 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-tigers-thank.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/client': patch
---

Add support for the `skip` option in `useBackgroundQuery` and `useSuspenseQuery`. Setting this option to `true` will avoid a network request.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*.md

# Do not format anything automatically except files listed below
*
/*

!config/
config/*
Expand Down
2 changes: 1 addition & 1 deletion .size-limit.cjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const checks = [
{
path: "dist/apollo-client.min.cjs",
limit: "37479"
limit: "37700"
},
{
path: "dist/main.cjs",
Expand Down
15 changes: 15 additions & 0 deletions src/react/cache/QueryReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
ApolloQueryResult,
ObservableQuery,
OperationVariables,
WatchQueryOptions,
} from '../../core';
import { NetworkStatus, isNetworkRequestSettled } from '../../core';
import type { ObservableSubscription } from '../../utilities';
Expand Down Expand Up @@ -86,6 +87,10 @@ export class QueryReference<TData = unknown> {
);
}

get watchQueryOptions() {
return this.observable.options;
}

listen(listener: Listener<TData>) {
// As soon as the component listens for updates, we know it has finished
// suspending and is ready to receive updates, so we can remove the auto
Expand Down Expand Up @@ -117,6 +122,16 @@ export class QueryReference<TData = unknown> {
return promise;
}

reobserve(
watchQueryOptions: Partial<WatchQueryOptions<OperationVariables, TData>>
) {
const promise = this.observable.reobserve(watchQueryOptions);

this.promise = promise;

return promise;
}

dispose() {
this.subscription.unsubscribe();
this.onDispose();
Expand Down
Loading

0 comments on commit 1d38f12

Please sign in to comment.