Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alessbell committed Jan 12, 2024
1 parent dfa3344 commit 1df2e1b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
26 changes: 15 additions & 11 deletions src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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 },
Expand All @@ -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",
Expand Down Expand Up @@ -2259,6 +2262,7 @@ describe("ApolloClient", () => {
}

expect(handleNext).toHaveBeenCalledTimes(1);

expect(handleNext).toHaveBeenLastCalledWith({
data: {
__typename: "Item",
Expand Down Expand Up @@ -2410,7 +2414,7 @@ describe("ApolloClient", () => {
link: ApolloLink.empty(),
});

const observable = client.watchQuery({
const queryObs = client.watchQuery({
query,
});

Expand Down
3 changes: 1 addition & 2 deletions src/cache/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
optimistic,
};

let latestDiff = this.diff<TData>(diffOptions);
let latestDiff: DataProxy.DiffResult<TData> | undefined = undefined;

return new Observable((observer) => {
return this.watch<TData, TVars>({
Expand All @@ -204,7 +204,6 @@ export abstract class ApolloCache<TSerialized> implements DataProxy {
diff.missing.map((error) => error.missing)
);
}

if (!equal(diff, latestDiff)) {
latestDiff = diff;
observer.next(result);
Expand Down

0 comments on commit 1df2e1b

Please sign in to comment.