From a3c26e33c19cd6d7e370578af9f618925525354d Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 26 Aug 2024 08:45:06 -0600 Subject: [PATCH 1/2] Add some tests for `watchFragment` for nested fragments and the fragment registry (#12015) --- src/__tests__/ApolloClient.ts | 116 +++++++++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index bcf9978ef90..2eb82151380 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -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"; @@ -2515,6 +2515,120 @@ describe("ApolloClient", () => { }); } }); + + it("works with nested fragments", async () => { + const cache = new InMemoryCache(); + const client = new ApolloClient({ + cache, + link: ApolloLink.empty(), + }); + + const ItemNestedFragment = gql` + fragment ItemNestedFragment on Item { + complete + } + `; + + const ItemFragment = gql` + fragment ItemFragment on Item { + id + text + ...ItemNestedFragment + } + + ${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, + }); + } + }); + + 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", () => { From 4210ab15f2686da598d2cf3699bdaa18bdcbc947 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Mon, 26 Aug 2024 09:17:00 -0600 Subject: [PATCH 2/2] Update ROADMAP.md --- ROADMAP.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 913c5584cf3..a51d49f01b6 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,6 @@ # 🔮 Apollo Client Ecosystem Roadmap -**Last updated: 2024-08-12** +**Last updated: 2024-08-26** For up to date release notes, refer to the project's [Changelog](https://github.com/apollographql/apollo-client/blob/main/CHANGELOG.md). @@ -48,7 +48,7 @@ _no work in progress_ ### Apollo Client DevTools -_no work in progress_ +- Ongoing work with fixing error messages shown in devtools ### Apollo Client NextJS