Skip to content

Commit 1c82eaf

Browse files
authored
Throw an error when using @stream without a configured incrementalDelivery handler (#12954)
1 parent c5d5630 commit 1c82eaf

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

.changeset/popular-files-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@apollo/client": patch
3+
---
4+
5+
Ensure an error is thrown when `@stream` is detected and an `incrementalDelivery` handler is not configured.

.size-limits.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44753,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39420,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33901,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27727
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44752,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39500,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33897,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27749
66
}

src/__tests__/ApolloClient.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3052,7 +3052,28 @@ describe("ApolloClient", () => {
30523052

30533053
await expect(() => client.query({ query })).rejects.toThrow(
30543054
new InvariantError(
3055-
"`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
3055+
"`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
3056+
)
3057+
);
3058+
});
3059+
3060+
test("will error when used with `@stream` in a without specifying an incremental strategy", async () => {
3061+
const client = new ApolloClient({
3062+
cache: new InMemoryCache(),
3063+
link: ApolloLink.empty(),
3064+
});
3065+
3066+
const query = gql`
3067+
query {
3068+
items @stream {
3069+
bar
3070+
}
3071+
}
3072+
`;
3073+
3074+
await expect(() => client.query({ query })).rejects.toThrow(
3075+
new InvariantError(
3076+
"`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
30563077
)
30573078
);
30583079
});

src/incremental/handlers/notImplemented.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export class NotImplementedHandler implements Incremental.Handler<never> {
2222
}
2323
prepareRequest(request: ApolloLink.Request) {
2424
invariant(
25-
!hasDirectives(["defer"], request.query),
26-
"`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
25+
!hasDirectives(["defer", "stream"], request.query),
26+
"`@defer` and `@stream` are not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor."
2727
);
2828

2929
return request;

0 commit comments

Comments
 (0)