Skip to content

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Sep 17, 2025

Fixes #12245

Adds support for using the @defer directive with the new incremental delivery format as implemented in [email protected].

Copy link

changeset-bot bot commented Sep 17, 2025

🦋 Changeset detected

Latest commit: 14e5a98

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@apollo-librarian
Copy link

apollo-librarian bot commented Sep 17, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: 2721fb02f556da014fcc07d7
Build Logs: View logs

Copy link

pkg-pr-new bot commented Sep 17, 2025

npm i https://pkg.pr.new/apollographql/apollo-client/@apollo/client@12926

commit: 14e5a98

Copy link
Contributor

size-limit report 📦

Path Size
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (CJS) 43.17 KB (+0.8% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) (CJS) 38.14 KB (+0.94% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" 32.68 KB (+0.15% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "@apollo/client" (production) 26.85 KB (-0.03% 🔽)
import { ApolloProvider } from "@apollo/client/react" 5.97 KB (+1.03% 🔺)
import { ApolloProvider } from "@apollo/client/react" (production) 994 B (0%)
import { useQuery } from "@apollo/client/react" 7.4 KB (+0.7% 🔺)
import { useQuery } from "@apollo/client/react" (production) 2.39 KB (0%)
import { useLazyQuery } from "@apollo/client/react" 7.15 KB (+0.51% 🔺)
import { useLazyQuery } from "@apollo/client/react" (production) 2.16 KB (0%)
import { useMutation } from "@apollo/client/react" 6.53 KB (+0.96% 🔺)
import { useMutation } from "@apollo/client/react" (production) 1.52 KB (0%)
import { useSubscription } from "@apollo/client/react" 6.85 KB (+0.87% 🔺)
import { useSubscription } from "@apollo/client/react" (production) 1.81 KB (0%)
import { useSuspenseQuery } from "@apollo/client/react" 8.62 KB (+0.77% 🔺)
import { useSuspenseQuery } from "@apollo/client/react" (production) 3.63 KB (0%)
import { useBackgroundQuery } from "@apollo/client/react" 8.38 KB (+0.45% 🔺)
import { useBackgroundQuery } from "@apollo/client/react" (production) 3.4 KB (0%)
import { useLoadableQuery } from "@apollo/client/react" 8.35 KB (+0.68% 🔺)
import { useLoadableQuery } from "@apollo/client/react" (production) 3.39 KB (0%)
import { useReadQuery } from "@apollo/client/react" 6.64 KB (+0.73% 🔺)
import { useReadQuery } from "@apollo/client/react" (production) 1.65 KB (0%)
import { useFragment } from "@apollo/client/react" 6.71 KB (+0.77% 🔺)
import { useFragment } from "@apollo/client/react" (production) 1.71 KB (0%)

if (hasDirectives(["defer"], request.query)) {
const context = request.context ?? {};
const http = (context.http ??= {});
http.accept = ["multipart/mixed", ...(http.accept || [])];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A previous comment asked if we should also have a deferSpec identifier here, and the thinking is yes, since that version of the protocol still isn’t guaranteed to end up as the final version.

We were thinking of using 20230621 as the identifier (as a reference to this doc)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests weren't actually testing defer but a regular query that emitted multiple values. To be honest, I'm not sure how useful these tests are given this should theoretically never happen in a real application (at least for queries). That said, I just removed the @defer in the queries for now since it was misleading since it wasn't actually testing defer payloads.

).toBeUndefined();
});

it("deduplicates queries as long as a query still has deferred chunks", async () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved @defer tests to their own subfolders. This test still exists in src/core/__tests__/client.watchQuery/defer20220824.test.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants