From 1df2e1bf065fb2040827bd4c693ac83e9f7ced76 Mon Sep 17 00:00:00 2001 From: Alessia Bellisario Date: Fri, 12 Jan 2024 15:19:32 -0500 Subject: [PATCH] wip --- src/__tests__/ApolloClient.ts | 26 +++++++++++++++----------- src/cache/core/cache.ts | 3 +-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index 6facc5d160d..c6b7a3cae35 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -14,7 +14,7 @@ import { ApolloLink } from "../link/core"; import { HttpLink } from "../link/http"; import { InMemoryCache } from "../cache"; import { concatPagination } from "../utilities"; -import { itAsync } from "../testing"; +import { itAsync, wait } from "../testing"; import { spyOnConsole } from "../testing/internal"; import { TypedDocumentNode } from "@graphql-typed-document-node/core"; import { invariant } from "../utilities/globals"; @@ -2182,7 +2182,7 @@ describe("ApolloClient", () => { text?: string; }; - it("if all data is available, `complete` is `true`", async () => { + it.only("if all data is available, `complete` is `true`", async () => { const cache = new InMemoryCache(); const client = new ApolloClient({ cache, @@ -2195,6 +2195,15 @@ describe("ApolloClient", () => { } `; + cache.writeFragment({ + fragment: ItemFragment, + data: { + __typename: "Item", + id: 5, + text: "Item #5", + }, + }); + const observable = client.watchFragment({ fragment: ItemFragment, from: { __typename: "Item", id: 5 }, @@ -2204,16 +2213,10 @@ describe("ApolloClient", () => { observable.subscribe(handleNext); - cache.writeFragment({ - fragment: ItemFragment, - data: { - __typename: "Item", - id: 5, - text: "Item #5", - }, - }); + await wait(0); // need to wait a tick expect(handleNext).toHaveBeenCalledTimes(1); + expect(handleNext).toHaveBeenLastCalledWith({ data: { __typename: "Item", @@ -2259,6 +2262,7 @@ describe("ApolloClient", () => { } expect(handleNext).toHaveBeenCalledTimes(1); + expect(handleNext).toHaveBeenLastCalledWith({ data: { __typename: "Item", @@ -2410,7 +2414,7 @@ describe("ApolloClient", () => { link: ApolloLink.empty(), }); - const observable = client.watchQuery({ + const queryObs = client.watchQuery({ query, }); diff --git a/src/cache/core/cache.ts b/src/cache/core/cache.ts index 1fa039d8bf3..566add47d61 100644 --- a/src/cache/core/cache.ts +++ b/src/cache/core/cache.ts @@ -186,7 +186,7 @@ export abstract class ApolloCache implements DataProxy { optimistic, }; - let latestDiff = this.diff(diffOptions); + let latestDiff: DataProxy.DiffResult | undefined = undefined; return new Observable((observer) => { return this.watch({ @@ -204,7 +204,6 @@ export abstract class ApolloCache implements DataProxy { diff.missing.map((error) => error.missing) ); } - if (!equal(diff, latestDiff)) { latestDiff = diff; observer.next(result);