Skip to content

Commit 6e3c9c4

Browse files
committed
type overrides for ApolloLink.Result
1 parent d37cc3d commit 6e3c9c4

1 file changed

Lines changed: 34 additions & 3 deletions

File tree

docs/source/migrating/apollo-client-4-migration.mdx

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,19 @@ const client = new ApolloClient({
509509
});
510510
```
511511

512+
Additionally, you should enable the `TypeOverrides` for the `Defer20220824Handler`.
513+
This will add the deferred chunk types to `ApolloLink.Result` and ensures that you handle incremental results correctly in custom links that might access `result` directly.
514+
515+
To do so, create a new `.d.ts` file in your project (e.g. `apollo-client.d.ts`) and add the following content:
516+
517+
```ts title="apollo-client.d.ts
518+
import { Defer20220824Handler } from "@apollo/client/incremental"; // [!code highlight]
519+
520+
declare module "@apollo/client" {
521+
export interface TypeOverrides extends Defer20220824Handler.TypeOverrides {} // [!code highlight]
522+
}
523+
```
524+
512525
<Note>
513526

514527
Over time, we will introduce additional incremental handlers to support different proposals of the protocol.
@@ -517,19 +530,37 @@ Over time, we will introduce additional incremental handlers to support differen
517530

518531
## Enable data masking types
519532

520-
In Apollo Client 4, the data masking types are now pluggable to allow for more flexibility when working with different solutions like GraphQL Code Generator or `gql.tadqa` - all of which might have different typings for data masking.
533+
In Apollo Client 4, the data masking types are now pluggable to allow for more flexibility when working with different solutions like GraphQL Code Generator or `gql.tadqa` - which might have different typings for data masking.
521534

522535
To configure the data masking types to be the same as they were in Apollo Client 3, create a `.d.ts` file in your project with the following content:
523536

524537
```ts title="apollo-client.d.ts
525-
import { GraphQLCodegenDataMasking } from "@apollo/client/masking";
538+
import { GraphQLCodegenDataMasking } from "@apollo/client/masking"; // [!code highlight]
526539

527540
declare module "@apollo/client" {
528-
export interface TypeOverrides
541+
export interface TypeOverrides // [!code highlight:2]
529542
extends GraphQLCodegenDataMasking.TypeOverrides {}
530543
}
531544
```
532545

546+
<Note>
547+
548+
You can always combine multiple `TypeOverrides` of different kinds, so you can also combine this with the `Defer20220824Handler` type overrides from the previous section.
549+
550+
```ts title="apollo-client.d.ts
551+
import { Defer20220824Handler } from "@apollo/client/incremental";
552+
import { GraphQLCodegenDataMasking } from "@apollo/client/masking"; // [!code ++]
553+
554+
declare module "@apollo/client" {
555+
export interface TypeOverrides extends Defer20220824Handler.TypeOverrides {} // [!code --]
556+
export interface TypeOverrides // [!code ++:3]
557+
extends Defer20220824Handler.TypeOverrides,
558+
GraphQLCodegenDataMasking.TypeOverrides {}
559+
}
560+
```
561+
562+
</Note>
563+
533564
## For React users
534565

535566
### (optional, but recommended) Stop using generated hooks

0 commit comments

Comments
 (0)