Skip to content

Commit 83e132a

Browse files
authored
move AdditionalApolloLinkResultTypes into TypeOverrides (#12840)
* move `AdditionalApolloLinkResultTypes` into `TypeOverrides` * chores * fix missing import * Clean up Prettier, Size-limit, and Api-Extractor --------- Co-authored-by: phryneas <4282439+phryneas@users.noreply.github.com>
1 parent 7a14c90 commit 83e132a

File tree

13 files changed

+156
-47
lines changed

13 files changed

+156
-47
lines changed

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,22 @@ import type { DeepPartial } from '@apollo/client/utilities';
99
import type { DocumentNode } from 'graphql';
1010
import type { FormattedExecutionResult } from 'graphql';
1111
import type { GraphQLFormattedError } from 'graphql';
12+
import type { HKT } from '@apollo/client/utilities';
1213

1314
// @public (undocumented)
1415
namespace Defer20220824Handler {
1516
// (undocumented)
1617
type Chunk<TData extends Record<string, unknown>> = InitialResult<TData> | SubsequentResult<TData>;
1718
// (undocumented)
19+
interface Defer20220824Result extends HKT {
20+
// (undocumented)
21+
arg1: unknown;
22+
// (undocumented)
23+
arg2: unknown;
24+
// (undocumented)
25+
return: Defer20220824Handler.Chunk<Record<string, unknown>>;
26+
}
27+
// (undocumented)
1828
type IncrementalDeferPayload<TData = Record<string, unknown>> = {
1929
data?: TData | null | undefined;
2030
errors?: ReadonlyArray<GraphQLFormattedError>;
@@ -37,6 +47,11 @@ namespace Defer20220824Handler {
3747
hasNext: boolean;
3848
incremental?: Array<IncrementalDeferPayload<TData>>;
3949
};
50+
// (undocumented)
51+
interface TypeOverrides {
52+
// (undocumented)
53+
AdditionalApolloLinkResultTypes: Defer20220824Result;
54+
}
4055
}
4156

4257
// @public
@@ -91,6 +106,24 @@ export namespace Incremental {
91106
export type Path = ReadonlyArray<string | number>;
92107
}
93108

109+
// @public (undocumented)
110+
export namespace NotImplementedHandler {
111+
// (undocumented)
112+
export interface NotImplementedResult extends HKT {
113+
// (undocumented)
114+
arg1: unknown;
115+
// (undocumented)
116+
arg2: unknown;
117+
// (undocumented)
118+
return: never;
119+
}
120+
// (undocumented)
121+
export interface TypeOverrides {
122+
// (undocumented)
123+
AdditionalApolloLinkResultTypes: NotImplementedResult;
124+
}
125+
}
126+
94127
// @public (undocumented)
95128
export class NotImplementedHandler implements Incremental.Handler<never> {
96129
// (undocumented)

.api-reports/api-report-link.api.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
```ts
66

77
import type { ApolloClient } from '@apollo/client';
8+
import type { ApplyHKTImplementationWithDefault } from '@apollo/client/utilities/internal';
89
import type { DefaultContext } from '@apollo/client';
9-
import type { DocumentNode } from 'graphql';
10+
import { DocumentNode } from 'graphql';
1011
import type { FormattedExecutionResult } from 'graphql';
1112
import type { GraphQLFormattedError } from 'graphql';
13+
import type { NotImplementedHandler } from '@apollo/client/incremental';
1214
import type { Observable } from 'rxjs';
1315
import type { OperationTypeNode } from 'graphql';
1416
import type { OperationVariables } from '@apollo/client';
15-
16-
// @public (undocumented)
17-
export interface AdditionalApolloLinkResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> {
18-
}
17+
import type { TypeOverrides } from '@apollo/client';
1918

2019
// @public (undocumented)
2120
export namespace ApolloLink {
21+
// (undocumented)
22+
export type AdditionalResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> = ApplyHKTImplementationWithDefault<TypeOverrides, "AdditionalApolloLinkResultTypes", NotImplementedHandler.TypeOverrides, TData, TExtensions>;
2223
// (undocumented)
2324
export namespace DocumentationTypes {
2425
export function ForwardFunction(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
@@ -51,7 +52,7 @@ export namespace ApolloLink {
5152
}
5253
export type RequestHandler = (operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction) => Observable<ApolloLink.Result>;
5354
// (undocumented)
54-
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalApolloLinkResultTypes<TData, TExtensions>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
55+
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalResultTypes<TData, TExtensions>;
5556
}
5657

5758
// @public

.api-reports/api-report-testing.api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { ApolloLink } from '@apollo/client/link';
88
import type { DocumentNode } from 'graphql';
9+
import { FormattedExecutionResult } from 'graphql';
910
import { Observable } from 'rxjs';
1011
import type { OperationVariables } from '@apollo/client';
1112
import type { Unmasked } from '@apollo/client/masking';
@@ -108,7 +109,7 @@ export class MockSubscriptionLink extends ApolloLink {
108109
// (undocumented)
109110
operation?: ApolloLink.Operation;
110111
// (undocumented)
111-
request(operation: ApolloLink.Operation): Observable<ApolloLink.Result<Record<string, any>, Record<string, any>>>;
112+
request(operation: ApolloLink.Operation): Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>;
112113
// (undocumented)
113114
setups: any[];
114115
// (undocumented)

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

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import type { ASTNode } from 'graphql';
88
import { disableExperimentalFragmentVariables } from 'graphql-tag';
99
import { disableFragmentWarnings } from 'graphql-tag';
10-
import type { DocumentNode } from 'graphql';
10+
import { DocumentNode } from 'graphql';
1111
import { enableExperimentalFragmentVariables } from 'graphql-tag';
1212
import type { FieldNode } from 'graphql';
1313
import type { FormattedExecutionResult } from 'graphql';
@@ -29,10 +29,6 @@ import type { Subscription } from 'rxjs';
2929
import { Trie } from '@wry/trie';
3030
import { TypedDocumentNode } from '@graphql-typed-document-node/core';
3131

32-
// @public (undocumented)
33-
interface AdditionalApolloLinkResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> {
34-
}
35-
3632
// Warning: (ae-forgotten-export) The symbol "Modifier" needs to be exported by the entry point index.d.ts
3733
// Warning: (ae-forgotten-export) The symbol "StoreObjectValueMaybeReference" needs to be exported by the entry point index.d.ts
3834
//
@@ -389,6 +385,11 @@ export type ApolloClientOptions = ApolloClient.Options;
389385

390386
// @public (undocumented)
391387
export namespace ApolloLink {
388+
// Warning: (ae-forgotten-export) The symbol "ApplyHKTImplementationWithDefault" needs to be exported by the entry point index.d.ts
389+
// Warning: (ae-forgotten-export) The symbol "NotImplementedHandler" needs to be exported by the entry point index.d.ts
390+
//
391+
// (undocumented)
392+
export type AdditionalResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> = ApplyHKTImplementationWithDefault<TypeOverrides, "AdditionalApolloLinkResultTypes", NotImplementedHandler.TypeOverrides, TData, TExtensions>;
392393
// (undocumented)
393394
export namespace DocumentationTypes {
394395
export function ForwardFunction(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
@@ -420,10 +421,8 @@ export namespace ApolloLink {
420421
variables?: OperationVariables;
421422
}
422423
export type RequestHandler = (operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction) => Observable<ApolloLink.Result>;
423-
// Warning: (ae-forgotten-export) The symbol "AdditionalApolloLinkResultTypes" needs to be exported by the entry point index.d.ts
424-
//
425424
// (undocumented)
426-
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalApolloLinkResultTypes<TData, TExtensions>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
425+
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalResultTypes<TData, TExtensions>;
427426
}
428427

429428
// @public
@@ -829,7 +828,6 @@ export type DataState<TData> = {
829828

830829
// @public (undocumented)
831830
export namespace DataValue {
832-
// Warning: (ae-forgotten-export) The symbol "ApplyHKTImplementationWithDefault" needs to be exported by the entry point index.d.ts
833831
// Warning: (ae-forgotten-export) The symbol "OverridableTypes" needs to be exported by the entry point index.d.ts
834832
export type Complete<TData> = ApplyHKTImplementationWithDefault<TypeOverrides, "Complete", OverridableTypes.Defaults, TData>;
835833
export type Partial<TData> = ApplyHKTImplementationWithDefault<TypeOverrides, "Partial", OverridableTypes.Defaults, TData>;
@@ -1832,6 +1830,38 @@ export interface NormalizedCacheObject {
18321830
// @public
18331831
export type NormalizedExecutionResult<TData = Record<string, unknown>, TExtensions = Record<string, unknown>> = Omit<FormattedExecutionResult<TData, TExtensions>, "data"> & GetDataState<TData, "streaming" | "complete">;
18341832

1833+
// @public (undocumented)
1834+
namespace NotImplementedHandler {
1835+
// (undocumented)
1836+
interface NotImplementedResult extends HKT {
1837+
// (undocumented)
1838+
arg1: unknown;
1839+
// (undocumented)
1840+
arg2: unknown;
1841+
// (undocumented)
1842+
return: never;
1843+
}
1844+
// (undocumented)
1845+
interface TypeOverrides {
1846+
// Warning: (ae-forgotten-export) The symbol "NotImplementedHandler" needs to be exported by the entry point index.d.ts
1847+
//
1848+
// (undocumented)
1849+
AdditionalApolloLinkResultTypes: NotImplementedResult;
1850+
}
1851+
}
1852+
1853+
// @public (undocumented)
1854+
class NotImplementedHandler implements Incremental.Handler<never> {
1855+
// (undocumented)
1856+
extractErrors(): void;
1857+
// (undocumented)
1858+
isIncrementalResult(_: any): _ is never;
1859+
// (undocumented)
1860+
prepareRequest(request: ApolloLink.Request): ApolloLink.Request;
1861+
// (undocumented)
1862+
startRequest: any;
1863+
}
1864+
18351865
export { Observable }
18361866

18371867
// @public (undocumented)

.changeset/four-rockets-live.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
"@apollo/client": major
3+
---
4+
5+
If you use an incremental delivery handler, you now have to explicitly opt into adding the chunk types to the `ApolloLink.Result` type.
6+
7+
8+
```ts title="apollo-client.d.ts
9+
import { Defer20220824Handler } from "@apollo/client/incremental";
10+
11+
declare module "@apollo/client" {
12+
export interface TypeOverrides extends Defer20220824Handler.TypeOverrides {}
13+
}
14+
```

.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)": 43855,
3-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38649,
4-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33615,
5-
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27649
2+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43879,
3+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38651,
4+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33590,
5+
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27664
66
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { ApolloLink } from "@apollo/client";
2+
import { expectTypeOf } from "expect-type";
3+
import type { FormattedExecutionResult } from "graphql";
4+
5+
// ensure that without manual addition to `TypeOverrides`,
6+
// `ApolloLink.Result` equals `FormattedExecutionResult`
7+
// with no additional alternatives
8+
9+
type TData = { foo: string };
10+
type TExtensions = { bar: number };
11+
expectTypeOf<ApolloLink.Result<TData, TExtensions>>().toEqualTypeOf<
12+
FormattedExecutionResult<TData, TExtensions>
13+
>();

src/incremental/handlers/defer20220824.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
} from "graphql";
66

77
import type { ApolloLink } from "@apollo/client/link";
8-
import type { DeepPartial } from "@apollo/client/utilities";
8+
import type { DeepPartial, HKT } from "@apollo/client/utilities";
99
import {
1010
DeepMerger,
1111
hasDirectives,
@@ -15,6 +15,15 @@ import {
1515
import type { Incremental } from "../types.js";
1616

1717
export declare namespace Defer20220824Handler {
18+
interface Defer20220824Result extends HKT {
19+
arg1: unknown; // TData
20+
arg2: unknown; // TExtensions
21+
return: Defer20220824Handler.Chunk<Record<string, unknown>>;
22+
}
23+
export interface TypeOverrides {
24+
AdditionalApolloLinkResultTypes: Defer20220824Result;
25+
}
26+
1827
export type InitialResult<TData = Record<string, unknown>> = {
1928
data?: TData | null | undefined;
2029
errors?: ReadonlyArray<GraphQLFormattedError>;
@@ -43,12 +52,6 @@ export declare namespace Defer20220824Handler {
4352
};
4453
}
4554

46-
declare module "@apollo/client/link" {
47-
export interface AdditionalApolloLinkResultTypes {
48-
Defer20220824Handler: Defer20220824Handler.Chunk<Record<string, unknown>>;
49-
}
50-
}
51-
5255
class DeferRequest<TData extends Record<string, unknown>>
5356
implements
5457
Incremental.IncrementalRequest<Defer20220824Handler.Chunk<TData>, TData>

src/incremental/handlers/notImplemented.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
import type { ApolloLink } from "@apollo/client/link";
2+
import type { HKT } from "@apollo/client/utilities";
23
import { hasDirectives } from "@apollo/client/utilities/internal";
34
import { invariant } from "@apollo/client/utilities/invariant";
45

56
import type { Incremental } from "../types.js";
67

8+
export declare namespace NotImplementedHandler {
9+
interface NotImplementedResult extends HKT {
10+
arg1: unknown; // TData
11+
arg2: unknown; // TExtensions
12+
return: never;
13+
}
14+
export interface TypeOverrides {
15+
AdditionalApolloLinkResultTypes: NotImplementedResult;
16+
}
17+
}
18+
719
export class NotImplementedHandler implements Incremental.Handler<never> {
820
isIncrementalResult(_: any): _ is never {
921
return false;

src/link/core/ApolloLink.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import type {
1111
DefaultContext,
1212
OperationVariables,
1313
} from "@apollo/client";
14+
import type { TypeOverrides } from "@apollo/client";
15+
import type { NotImplementedHandler } from "@apollo/client/incremental";
1416
import { createOperation } from "@apollo/client/link/utils";
1517
import { __DEV__ } from "@apollo/client/utilities/environment";
18+
import type { ApplyHKTImplementationWithDefault } from "@apollo/client/utilities/internal";
1619
import {
1720
invariant,
1821
newInvariantError,
1922
} from "@apollo/client/utilities/invariant";
2023

21-
import type { AdditionalApolloLinkResultTypes } from "./types.js";
22-
2324
export declare namespace ApolloLink {
2425
/**
2526
* Context provided for link execution, such as the client executing the
@@ -73,15 +74,23 @@ export declare namespace ApolloLink {
7374
forward: ApolloLink.ForwardFunction
7475
) => Observable<ApolloLink.Result>;
7576

77+
export type AdditionalResultTypes<
78+
TData = Record<string, any>,
79+
TExtensions = Record<string, any>,
80+
> = ApplyHKTImplementationWithDefault<
81+
TypeOverrides,
82+
"AdditionalApolloLinkResultTypes",
83+
NotImplementedHandler.TypeOverrides,
84+
TData,
85+
TExtensions
86+
>;
87+
7688
export type Result<
7789
TData = Record<string, any>,
7890
TExtensions = Record<string, any>,
7991
> =
8092
| FormattedExecutionResult<TData, TExtensions>
81-
| AdditionalApolloLinkResultTypes<
82-
TData,
83-
TExtensions
84-
>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
93+
| AdditionalResultTypes<TData, TExtensions>;
8594

8695
/**
8796
* The currently executed operation object provided to an `ApolloLink.RequestHandler`

0 commit comments

Comments
 (0)