Skip to content

Commit

Permalink
Add test for using the fragment registry with watchFragment
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 21, 2024
1 parent 8c521f3 commit e1c4ee7
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Kind } from "graphql";
import { Observable } from "../utilities";
import { ApolloLink } from "../link/core";
import { HttpLink } from "../link/http";
import { InMemoryCache } from "../cache";
import { createFragmentRegistry, InMemoryCache } from "../cache";
import { itAsync } from "../testing";
import { ObservableStream, spyOnConsole } from "../testing/internal";
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
Expand Down Expand Up @@ -2572,6 +2572,63 @@ describe("ApolloClient", () => {
});
}
});

it("can use the fragment registry for nested fragments", async () => {
const fragments = createFragmentRegistry();
const cache = new InMemoryCache({ fragments });

fragments.register(gql`
fragment ItemNestedFragment on Item {
complete
}
`);

const client = new ApolloClient({
cache,
link: ApolloLink.empty(),
});

const ItemFragment = gql`
fragment ItemFragment on Item {
id
text
...ItemNestedFragment
}
`;

cache.writeFragment({
fragment: ItemFragment,
fragmentName: "ItemFragment",
data: {
__typename: "Item",
id: 5,
text: "Item #5",
complete: true,
},
});

const observable = client.watchFragment({
fragment: ItemFragment,
fragmentName: "ItemFragment",
from: { __typename: "Item", id: 5 },
});

const stream = new ObservableStream(observable);

{
const result = await stream.takeNext();

expect(result).toEqual({
data: {
__typename: "Item",
id: 5,
text: "Item #5",
complete: true,
},
complete: true,
});
}
});
});

describe("defaultOptions", () => {
Expand Down

0 comments on commit e1c4ee7

Please sign in to comment.