From 22224559f69ca463d9d62870427af45c94ad239e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 2 Oct 2025 15:54:52 -0600 Subject: [PATCH 1/4] Detect stream and throw if no incremental handler --- src/__tests__/ApolloClient.ts | 23 +++++++++++++++++++++- src/incremental/handlers/notImplemented.ts | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index b491ae75741..ec991d7a48c 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -3052,7 +3052,28 @@ describe("ApolloClient", () => { await expect(() => client.query({ query })).rejects.toThrow( new InvariantError( - "`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + ) + ); + }); + + test("will error when used with `@stream` in a without specifying an incremental strategy", async () => { + const client = new ApolloClient({ + cache: new InMemoryCache(), + link: ApolloLink.empty(), + }); + + const query = gql` + query { + items @stream { + bar + } + } + `; + + await expect(() => client.query({ query })).rejects.toThrow( + new InvariantError( + "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." ) ); }); diff --git a/src/incremental/handlers/notImplemented.ts b/src/incremental/handlers/notImplemented.ts index f4c02545c57..b772a9c7cf5 100644 --- a/src/incremental/handlers/notImplemented.ts +++ b/src/incremental/handlers/notImplemented.ts @@ -22,8 +22,8 @@ export class NotImplementedHandler implements Incremental.Handler { } prepareRequest(request: ApolloLink.Request) { invariant( - !hasDirectives(["defer"], request.query), - "`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + !hasDirectives(["defer", "stream"], request.query), + "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." ); return request; From 4f5ef8a20cfdd72861210b3cecd69cf5c34a8b64 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 2 Oct 2025 15:56:08 -0600 Subject: [PATCH 2/4] Add changeset --- .changeset/popular-files-glow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/popular-files-glow.md diff --git a/.changeset/popular-files-glow.md b/.changeset/popular-files-glow.md new file mode 100644 index 00000000000..53955edd598 --- /dev/null +++ b/.changeset/popular-files-glow.md @@ -0,0 +1,5 @@ +--- +"@apollo/client": patch +--- + +Ensure an error is thrown when `@stream` is detected and an `incrementalDelivery` handler is not configured. From 88ec2247bfbbb385a16af37bd4b13f9301b18f8b Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 2 Oct 2025 15:57:37 -0600 Subject: [PATCH 3/4] Update size limits --- .size-limits.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 7bfe2604146..99d2b7b0ae7 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,6 +1,6 @@ { - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44753, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39420, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33901, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27727 + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44769, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39500, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33880, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27749 } From e47daa551688d7e87f25e0971445604f54a3d48e Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Thu, 2 Oct 2025 15:59:27 -0600 Subject: [PATCH 4/4] Grammar --- .size-limits.json | 4 ++-- src/__tests__/ApolloClient.ts | 4 ++-- src/incremental/handlers/notImplemented.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.size-limits.json b/.size-limits.json index 99d2b7b0ae7..e214463c49d 100644 --- a/.size-limits.json +++ b/.size-limits.json @@ -1,6 +1,6 @@ { - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44769, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44752, "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39500, - "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33880, + "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33897, "import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27749 } diff --git a/src/__tests__/ApolloClient.ts b/src/__tests__/ApolloClient.ts index ec991d7a48c..a0381c9daef 100644 --- a/src/__tests__/ApolloClient.ts +++ b/src/__tests__/ApolloClient.ts @@ -3052,7 +3052,7 @@ describe("ApolloClient", () => { await expect(() => client.query({ query })).rejects.toThrow( new InvariantError( - "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + "`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." ) ); }); @@ -3073,7 +3073,7 @@ describe("ApolloClient", () => { await expect(() => client.query({ query })).rejects.toThrow( new InvariantError( - "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + "`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." ) ); }); diff --git a/src/incremental/handlers/notImplemented.ts b/src/incremental/handlers/notImplemented.ts index b772a9c7cf5..ce7f287ac00 100644 --- a/src/incremental/handlers/notImplemented.ts +++ b/src/incremental/handlers/notImplemented.ts @@ -23,7 +23,7 @@ export class NotImplementedHandler implements Incremental.Handler { prepareRequest(request: ApolloLink.Request) { invariant( !hasDirectives(["defer", "stream"], request.query), - "`@defer` and `@stream` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." + "`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor." ); return request;