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

Honor @nonreactive with useFragment and cache.watchFragment #11844

Merged
merged 9 commits into from
May 14, 2024
Prev Previous commit
Next Next commit
Minor refactor to reuse value
  • Loading branch information
jerelmiller committed May 13, 2024
commit 10d88be5b3cfc661b61214d906c4234bc5814097
6 changes: 2 additions & 4 deletions src/cache/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,23 +229,21 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
options: WatchFragmentOptions<TData, TVars>
): Observable<WatchFragmentResult<TData>> {
const { fragment, fragmentName, from, optimistic = true } = options;
const query = this.getFragmentDoc(fragment, fragmentName);

const diffOptions: Cache.DiffOptions<TData, TVars> = {
returnPartialData: true,
id: typeof from === "string" ? from : this.identify(from),
query: this.getFragmentDoc(fragment, fragmentName),
query,
optimistic,
};

let latestDiff: DataProxy.DiffResult<TData> | undefined;

return new Observable((observer) => {
const query = this.getFragmentDoc(fragment, fragmentName);

return this.watch<TData, TVars>({
...diffOptions,
immediate: true,
query,
callback(diff) {
if (
// Always ensure we deliver the first result
Expand Down