Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @defer support to useSuspenseQuery #10324

Merged
merged 17 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sixty-trains-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@apollo/client': patch
---

Add `@defer` support to `useSuspenseQuery`.
2 changes: 1 addition & 1 deletion config/bundlesize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { join } from "path";
import { gzipSync } from "zlib";
import bytes from "bytes";

const gzipBundleByteLengthLimit = bytes("32.79KB");
const gzipBundleByteLengthLimit = bytes("33.01KB");
const minFile = join("dist", "apollo-client.min.cjs");
const minPath = join(__dirname, "..", minFile);
const gzipByteLen = gzipSync(readFileSync(minPath)).byteLength;
Expand Down
23 changes: 19 additions & 4 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,10 +784,15 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);
return this.last;
}

public reobserve(
// For cases like suspense with a deferred query where we need a custom
// promise wrapped around the concast, we need access to the raw concast
// created from `reobserve`. This function provides the original `reobserve`
// functionality, but returns a concast instead of a promise. Most consumers
// should prefer `reobserve` instead of this function.
public reobserveAsConcast(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to suggest a different name for this

newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,
newNetworkStatus?: NetworkStatus,
): Promise<ApolloQueryResult<TData>> {
newNetworkStatus?: NetworkStatus
): Concast<ApolloQueryResult<TData>> {
this.isTornDown = false;

const useDisposableConcast =
Expand Down Expand Up @@ -860,7 +865,17 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`);

concast.addObserver(observer);

return concast.promise;
return concast;
}

public reobserve(
newOptions?: Partial<WatchQueryOptions<TVariables, TData>>,
newNetworkStatus?: NetworkStatus,
): Promise<ApolloQueryResult<TData>> {
return this.reobserveAsConcast(
newOptions,
newNetworkStatus
).promise
}

// (Re)deliver the current result to this.observers without applying fetch
Expand Down
Loading