Skip to content

Commit 2b7f2c1

Browse files
authored
Add support for the new incremental format in GraphQL 17.0.0-alpha.9 (#12926)
1 parent f1b483d commit 2b7f2c1

42 files changed

Lines changed: 13541 additions & 5443 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.api-reports/api-report-incremental.api.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,102 @@ class DeferRequest<TData extends Record<string, unknown>> implements Incremental
8080
hasNext: boolean;
8181
}
8282

83+
// @public (undocumented)
84+
export namespace GraphQL17Alpha9Handler {
85+
// (undocumented)
86+
export type Chunk<TData> = InitialResult<TData> | SubsequentResult<TData>;
87+
// (undocumented)
88+
export interface CompletedResult {
89+
// (undocumented)
90+
errors?: ReadonlyArray<GraphQLFormattedError>;
91+
// (undocumented)
92+
id: string;
93+
}
94+
// (undocumented)
95+
export interface GraphQL17Alpha9Result extends HKT {
96+
// (undocumented)
97+
arg1: unknown;
98+
// (undocumented)
99+
arg2: unknown;
100+
// (undocumented)
101+
return: GraphQL17Alpha9Handler.Chunk<Record<string, unknown>>;
102+
}
103+
// (undocumented)
104+
export interface IncrementalDeferResult<TData = Record<string, unknown>> {
105+
// (undocumented)
106+
data: TData;
107+
// (undocumented)
108+
errors?: ReadonlyArray<GraphQLFormattedError>;
109+
// (undocumented)
110+
extensions?: Record<string, unknown>;
111+
// (undocumented)
112+
id: string;
113+
// (undocumented)
114+
subPath?: Incremental.Path;
115+
}
116+
// (undocumented)
117+
export type IncrementalResult<TData = unknown> = IncrementalDeferResult<TData> | IncrementalStreamResult<TData>;
118+
// (undocumented)
119+
export interface IncrementalStreamResult<TData = ReadonlyArray<unknown>> {
120+
// (undocumented)
121+
errors?: ReadonlyArray<GraphQLFormattedError>;
122+
// (undocumented)
123+
extensions?: Record<string, unknown>;
124+
// (undocumented)
125+
id: string;
126+
// (undocumented)
127+
items: TData;
128+
// (undocumented)
129+
subPath?: Incremental.Path;
130+
}
131+
// (undocumented)
132+
export type InitialResult<TData = Record<string, unknown>> = {
133+
data: TData;
134+
errors?: ReadonlyArray<GraphQLFormattedError>;
135+
pending: ReadonlyArray<PendingResult>;
136+
hasNext: boolean;
137+
extensions?: Record<string, unknown>;
138+
};
139+
// (undocumented)
140+
export interface PendingResult {
141+
// (undocumented)
142+
id: string;
143+
// (undocumented)
144+
label?: string;
145+
// (undocumented)
146+
path: Incremental.Path;
147+
}
148+
// (undocumented)
149+
export type SubsequentResult<TData = unknown> = {
150+
hasNext: boolean;
151+
pending?: ReadonlyArray<PendingResult>;
152+
incremental?: ReadonlyArray<IncrementalResult<TData>>;
153+
completed?: ReadonlyArray<CompletedResult>;
154+
extensions?: Record<string, unknown>;
155+
};
156+
// (undocumented)
157+
export interface TypeOverrides {
158+
// (undocumented)
159+
AdditionalApolloLinkResultTypes: GraphQL17Alpha9Result;
160+
}
161+
}
162+
163+
// @public
164+
export class GraphQL17Alpha9Handler implements Incremental.Handler<GraphQL17Alpha9Handler.Chunk<any>> {
165+
// @internal @deprecated (undocumented)
166+
extractErrors(result: ApolloLink.Result<any>): GraphQLFormattedError[] | undefined;
167+
// @internal @deprecated (undocumented)
168+
isIncrementalResult(result: ApolloLink.Result<any>): result is GraphQL17Alpha9Handler.InitialResult | GraphQL17Alpha9Handler.SubsequentResult;
169+
// @internal @deprecated (undocumented)
170+
prepareRequest(request: ApolloLink.Request): ApolloLink.Request;
171+
// Warning: (ae-forgotten-export) The symbol "IncrementalRequest" needs to be exported by the entry point index.d.ts
172+
//
173+
// @internal @deprecated (undocumented)
174+
startRequest<TData>(_: {
175+
query: DocumentNode;
176+
}): IncrementalRequest<TData>;
177+
}
178+
83179
// @public (undocumented)
84180
export namespace Incremental {
85181
// @internal @deprecated (undocumented)
@@ -106,6 +202,14 @@ export namespace Incremental {
106202
export type Path = ReadonlyArray<string | number>;
107203
}
108204

205+
// @public (undocumented)
206+
class IncrementalRequest<TData> implements Incremental.IncrementalRequest<GraphQL17Alpha9Handler.Chunk<TData>, TData> {
207+
// (undocumented)
208+
handle(cacheData: TData | DeepPartial<TData> | null | undefined, chunk: GraphQL17Alpha9Handler.Chunk<TData>): FormattedExecutionResult<TData>;
209+
// (undocumented)
210+
hasNext: boolean;
211+
}
212+
109213
// @public (undocumented)
110214
export namespace NotImplementedHandler {
111215
// (undocumented)

.changeset/little-yaks-decide.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"@apollo/client": minor
3+
---
4+
5+
Support the newer incremental delivery format for the `@defer` directive implemented in `graphql@17.0.0-alpha.9`. Import the `GraphQL17Alpha9Handler` to use the newer incremental delivery format with `@defer`.
6+
7+
```ts
8+
import { GraphQL17Alpha9Handler } from "@apollo/client/incremental";
9+
10+
const client = new ApolloClient({
11+
// ...
12+
incrementalHandler: new GraphQL17Alpha9Handler(),
13+
});
14+
```
15+
16+
> [!NOTE]
17+
> In order to use the `GraphQL17Alpha9Handler`, the GraphQL server MUST implement the newer incremental delivery format. You may see errors or unusual behavior if you use the wrong handler. If you are using Apollo Router, continue to use the `Defer20220824Handler` because Apollo Router does not yet support the newer incremental delivery format.

.prettierrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
"parser": "typescript-with-jsdoc"
1818
}
1919
},
20+
{
21+
"files": ["**/__tests__/**/*.ts", "**/__tests__/**/*.tsx"],
22+
"options": {
23+
"parser": "typescript"
24+
}
25+
},
2026
{
2127
"files": ["*.mdx"],
2228
"options": {

.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)": 43857,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38699,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33415,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27498
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44206,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39060,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33462,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27490
66
}

config/jest.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ const react17TestFileIgnoreList = [
4949
"src/testing/experimental/__tests__/createTestSchema.test.tsx",
5050
"src/react/hooks/__tests__/useSuspenseFragment.test.tsx",
5151
"src/react/hooks/__tests__/useSuspenseQuery.test.tsx",
52+
"src/react/hooks/__tests__/useSuspenseQuery/*",
5253
"src/react/hooks/__tests__/useBackgroundQuery.test.tsx",
54+
"src/react/hooks/__tests__/useBackgroundQuery/*",
5355
"src/react/hooks/__tests__/useLoadableQuery.test.tsx",
56+
"src/react/hooks/__tests__/useLoadableQuery/*",
5457
"src/react/hooks/__tests__/useQueryRefHandlers.test.tsx",
5558
"src/react/query-preloader/__tests__/createQueryPreloader.test.tsx",
5659
"src/react/ssr/__tests__/prerenderStatic.test.tsx",

package-lock.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
"globals": "15.14.0",
215215
"graphql": "16.9.0",
216216
"graphql-17-alpha2": "npm:graphql@17.0.0-alpha.2",
217+
"graphql-17-alpha9": "npm:graphql@17.0.0-alpha.9",
217218
"graphql-ws": "6.0.3",
218219
"jest": "29.7.0",
219220
"jest-environment-jsdom": "29.7.0",
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/node_modules/graphql-17-alpha9/execution/types.d.ts b/node_modules/graphql-17-alpha9/execution/types.d.ts
2+
index 48ef2e9..6ef2ab3 100644
3+
--- a/node_modules/graphql-17-alpha9/execution/types.d.ts
4+
+++ b/node_modules/graphql-17-alpha9/execution/types.d.ts
5+
@@ -95,9 +95,8 @@ export interface CompletedResult {
6+
errors?: ReadonlyArray<GraphQLError>;
7+
}
8+
export interface FormattedCompletedResult {
9+
- path: ReadonlyArray<string | number>;
10+
- label?: string;
11+
- errors?: ReadonlyArray<GraphQLError>;
12+
+ id: string;
13+
+ errors?: ReadonlyArray<GraphQLFormattedError>;
14+
}
15+
export declare function isPendingExecutionGroup(incrementalDataRecord: IncrementalDataRecord): incrementalDataRecord is PendingExecutionGroup;
16+
export type CompletedExecutionGroup = SuccessfulExecutionGroup | FailedExecutionGroup;

src/__tests__/__snapshots__/exports.ts.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ exports[`exports of public entry points @apollo/client/incremental 1`] = `
145145
Array [
146146
"Defer20220824Handler",
147147
"GraphQL17Alpha2Handler",
148+
"GraphQL17Alpha9Handler",
148149
"NotImplementedHandler",
149150
]
150151
`;
@@ -362,7 +363,8 @@ Array [
362363
"enableFakeTimers",
363364
"executeWithDefaultContext",
364365
"markAsStreaming",
365-
"mockDeferStream",
366+
"mockDefer20220824",
367+
"mockDeferStreamGraphQL17Alpha9",
366368
"mockMultipartSubscriptionStream",
367369
"renderAsync",
368370
"renderHookAsync",

src/__tests__/fetchMore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Defer20220824Handler } from "@apollo/client/incremental";
1919
import { MockLink, MockSubscriptionLink } from "@apollo/client/testing";
2020
import {
2121
markAsStreaming,
22-
mockDeferStream,
22+
mockDefer20220824,
2323
ObservableStream,
2424
setupPaginatedCase,
2525
} from "@apollo/client/testing/internal";
@@ -2478,7 +2478,7 @@ test("uses updateQuery to update the result of the query with no-cache queries",
24782478
});
24792479

24802480
test("calling `fetchMore` on an ObservableQuery that hasn't finished deferring yet will not put it into completed state", async () => {
2481-
const defer = mockDeferStream();
2481+
const defer = mockDefer20220824();
24822482
const baseLink = new MockSubscriptionLink();
24832483

24842484
const client = new ApolloClient({

0 commit comments

Comments
 (0)