Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .api-reports/api-report-incremental.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ import type { DeepPartial } from '@apollo/client/utilities';
import type { DocumentNode } from 'graphql';
import type { FormattedExecutionResult } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import type { HKT } from '@apollo/client/utilities';

// @public (undocumented)
namespace Defer20220824Handler {
// (undocumented)
type Chunk<TData extends Record<string, unknown>> = InitialResult<TData> | SubsequentResult<TData>;
// (undocumented)
interface Defer20220824Result extends HKT {
// (undocumented)
arg1: unknown;
// (undocumented)
arg2: unknown;
// (undocumented)
return: Defer20220824Handler.Chunk<Record<string, unknown>>;
}
// (undocumented)
type IncrementalDeferPayload<TData = Record<string, unknown>> = {
data?: TData | null | undefined;
errors?: ReadonlyArray<GraphQLFormattedError>;
Expand All @@ -37,6 +47,11 @@ namespace Defer20220824Handler {
hasNext: boolean;
incremental?: Array<IncrementalDeferPayload<TData>>;
};
// (undocumented)
interface TypeOverrides {
// (undocumented)
AdditionalApolloLinkResultTypes: Defer20220824Result;
}
}

// @public
Expand Down Expand Up @@ -91,6 +106,24 @@ export namespace Incremental {
export type Path = ReadonlyArray<string | number>;
}

// @public (undocumented)
export namespace NotImplementedHandler {
// (undocumented)
export interface NotImplementedResult extends HKT {
// (undocumented)
arg1: unknown;
// (undocumented)
arg2: unknown;
// (undocumented)
return: never;
}
// (undocumented)
export interface TypeOverrides {
// (undocumented)
AdditionalApolloLinkResultTypes: NotImplementedResult;
}
}

// @public (undocumented)
export class NotImplementedHandler implements Incremental.Handler<never> {
// (undocumented)
Expand Down
13 changes: 7 additions & 6 deletions .api-reports/api-report-link.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@
```ts

import type { ApolloClient } from '@apollo/client';
import type { ApplyHKTImplementationWithDefault } from '@apollo/client/utilities/internal';
import type { DefaultContext } from '@apollo/client';
import type { DocumentNode } from 'graphql';
import { DocumentNode } from 'graphql';
import type { FormattedExecutionResult } from 'graphql';
import type { GraphQLFormattedError } from 'graphql';
import type { NotImplementedHandler } from '@apollo/client/incremental';
import type { Observable } from 'rxjs';
import type { OperationTypeNode } from 'graphql';
import type { OperationVariables } from '@apollo/client';

// @public (undocumented)
export interface AdditionalApolloLinkResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> {
}
import type { TypeOverrides } from '@apollo/client';

// @public (undocumented)
export namespace ApolloLink {
// (undocumented)
export type AdditionalResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> = ApplyHKTImplementationWithDefault<TypeOverrides, "AdditionalApolloLinkResultTypes", NotImplementedHandler.TypeOverrides, TData, TExtensions>;
// (undocumented)
export namespace DocumentationTypes {
export function ForwardFunction(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
Expand Down Expand Up @@ -51,7 +52,7 @@ export namespace ApolloLink {
}
export type RequestHandler = (operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction) => Observable<ApolloLink.Result>;
// (undocumented)
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalApolloLinkResultTypes<TData, TExtensions>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalResultTypes<TData, TExtensions>;
}

// @public
Expand Down
3 changes: 2 additions & 1 deletion .api-reports/api-report-testing.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { ApolloLink } from '@apollo/client/link';
import type { DocumentNode } from 'graphql';
import { FormattedExecutionResult } from 'graphql';
import { Observable } from 'rxjs';
import type { OperationVariables } from '@apollo/client';
import type { Unmasked } from '@apollo/client/masking';
Expand Down Expand Up @@ -108,7 +109,7 @@ export class MockSubscriptionLink extends ApolloLink {
// (undocumented)
operation?: ApolloLink.Operation;
// (undocumented)
request(operation: ApolloLink.Operation): Observable<ApolloLink.Result<Record<string, any>, Record<string, any>>>;
request(operation: ApolloLink.Operation): Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>;
// (undocumented)
setups: any[];
// (undocumented)
Expand Down
48 changes: 39 additions & 9 deletions .api-reports/api-report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import type { ASTNode } from 'graphql';
import { disableExperimentalFragmentVariables } from 'graphql-tag';
import { disableFragmentWarnings } from 'graphql-tag';
import type { DocumentNode } from 'graphql';
import { DocumentNode } from 'graphql';
import { enableExperimentalFragmentVariables } from 'graphql-tag';
import type { FieldNode } from 'graphql';
import type { FormattedExecutionResult } from 'graphql';
Expand All @@ -29,10 +29,6 @@ import type { Subscription } from 'rxjs';
import { Trie } from '@wry/trie';
import { TypedDocumentNode } from '@graphql-typed-document-node/core';

// @public (undocumented)
interface AdditionalApolloLinkResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> {
}

// Warning: (ae-forgotten-export) The symbol "Modifier" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "StoreObjectValueMaybeReference" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -389,6 +385,11 @@ export type ApolloClientOptions = ApolloClient.Options;

// @public (undocumented)
export namespace ApolloLink {
// Warning: (ae-forgotten-export) The symbol "ApplyHKTImplementationWithDefault" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "NotImplementedHandler" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export type AdditionalResultTypes<TData = Record<string, any>, TExtensions = Record<string, any>> = ApplyHKTImplementationWithDefault<TypeOverrides, "AdditionalApolloLinkResultTypes", NotImplementedHandler.TypeOverrides, TData, TExtensions>;
// (undocumented)
export namespace DocumentationTypes {
export function ForwardFunction(operation: ApolloLink.Operation): Observable<ApolloLink.Result>;
Expand Down Expand Up @@ -420,10 +421,8 @@ export namespace ApolloLink {
variables?: OperationVariables;
}
export type RequestHandler = (operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction) => Observable<ApolloLink.Result>;
// Warning: (ae-forgotten-export) The symbol "AdditionalApolloLinkResultTypes" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalApolloLinkResultTypes<TData, TExtensions>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
export type Result<TData = Record<string, any>, TExtensions = Record<string, any>> = FormattedExecutionResult<TData, TExtensions> | AdditionalResultTypes<TData, TExtensions>;
}

// @public
Expand Down Expand Up @@ -829,7 +828,6 @@ export type DataState<TData> = {

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

// @public (undocumented)
namespace NotImplementedHandler {
// (undocumented)
interface NotImplementedResult extends HKT {
// (undocumented)
arg1: unknown;
// (undocumented)
arg2: unknown;
// (undocumented)
return: never;
}
// (undocumented)
interface TypeOverrides {
// Warning: (ae-forgotten-export) The symbol "NotImplementedHandler" needs to be exported by the entry point index.d.ts
//
// (undocumented)
AdditionalApolloLinkResultTypes: NotImplementedResult;
}
}

// @public (undocumented)
class NotImplementedHandler implements Incremental.Handler<never> {
// (undocumented)
extractErrors(): void;
// (undocumented)
isIncrementalResult(_: any): _ is never;
// (undocumented)
prepareRequest(request: ApolloLink.Request): ApolloLink.Request;
// (undocumented)
startRequest: any;
}

export { Observable }

// @public (undocumented)
Expand Down
14 changes: 14 additions & 0 deletions .changeset/four-rockets-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@apollo/client": major
---

If you use an incremental delivery handler, you now have to explicitly opt into adding the chunk types to the `ApolloLink.Result` type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm good with this. Less magic and makes a ton of sense. Good change!



```ts title="apollo-client.d.ts
import { Defer20220824Handler } from "@apollo/client/incremental";

declare module "@apollo/client" {
export interface TypeOverrides extends Defer20220824Handler.TypeOverrides {}
}
```
8 changes: 4 additions & 4 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43855,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38649,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33615,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27649
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 43879,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 38651,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33590,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27664
}
13 changes: 13 additions & 0 deletions integration-tests/vite/src/ApolloLinkResultType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { ApolloLink } from "@apollo/client";
import { expectTypeOf } from "expect-type";
import type { FormattedExecutionResult } from "graphql";

// ensure that without manual addition to `TypeOverrides`,
// `ApolloLink.Result` equals `FormattedExecutionResult`
// with no additional alternatives

type TData = { foo: string };
type TExtensions = { bar: number };
expectTypeOf<ApolloLink.Result<TData, TExtensions>>().toEqualTypeOf<
FormattedExecutionResult<TData, TExtensions>
>();
17 changes: 10 additions & 7 deletions src/incremental/handlers/defer20220824.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from "graphql";

import type { ApolloLink } from "@apollo/client/link";
import type { DeepPartial } from "@apollo/client/utilities";
import type { DeepPartial, HKT } from "@apollo/client/utilities";
import {
DeepMerger,
hasDirectives,
Expand All @@ -15,6 +15,15 @@ import {
import type { Incremental } from "../types.js";

export declare namespace Defer20220824Handler {
interface Defer20220824Result extends HKT {
arg1: unknown; // TData
arg2: unknown; // TExtensions
return: Defer20220824Handler.Chunk<Record<string, unknown>>;
}
export interface TypeOverrides {
AdditionalApolloLinkResultTypes: Defer20220824Result;
}

export type InitialResult<TData = Record<string, unknown>> = {
data?: TData | null | undefined;
errors?: ReadonlyArray<GraphQLFormattedError>;
Expand Down Expand Up @@ -43,12 +52,6 @@ export declare namespace Defer20220824Handler {
};
}

declare module "@apollo/client/link" {
export interface AdditionalApolloLinkResultTypes {
Defer20220824Handler: Defer20220824Handler.Chunk<Record<string, unknown>>;
}
}

class DeferRequest<TData extends Record<string, unknown>>
implements
Incremental.IncrementalRequest<Defer20220824Handler.Chunk<TData>, TData>
Expand Down
12 changes: 12 additions & 0 deletions src/incremental/handlers/notImplemented.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import type { ApolloLink } from "@apollo/client/link";
import type { HKT } from "@apollo/client/utilities";
import { hasDirectives } from "@apollo/client/utilities/internal";
import { invariant } from "@apollo/client/utilities/invariant";

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

export declare namespace NotImplementedHandler {
interface NotImplementedResult extends HKT {
arg1: unknown; // TData
arg2: unknown; // TExtensions
return: never;
}
export interface TypeOverrides {
AdditionalApolloLinkResultTypes: NotImplementedResult;
}
}

export class NotImplementedHandler implements Incremental.Handler<never> {
isIncrementalResult(_: any): _ is never {
return false;
Expand Down
21 changes: 15 additions & 6 deletions src/link/core/ApolloLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import type {
DefaultContext,
OperationVariables,
} from "@apollo/client";
import type { TypeOverrides } from "@apollo/client";
import type { NotImplementedHandler } from "@apollo/client/incremental";
import { createOperation } from "@apollo/client/link/utils";
import { __DEV__ } from "@apollo/client/utilities/environment";
import type { ApplyHKTImplementationWithDefault } from "@apollo/client/utilities/internal";
import {
invariant,
newInvariantError,
} from "@apollo/client/utilities/invariant";

import type { AdditionalApolloLinkResultTypes } from "./types.js";

export declare namespace ApolloLink {
/**
* Context provided for link execution, such as the client executing the
Expand Down Expand Up @@ -73,15 +74,23 @@ export declare namespace ApolloLink {
forward: ApolloLink.ForwardFunction
) => Observable<ApolloLink.Result>;

export type AdditionalResultTypes<
TData = Record<string, any>,
TExtensions = Record<string, any>,
> = ApplyHKTImplementationWithDefault<
TypeOverrides,
"AdditionalApolloLinkResultTypes",
NotImplementedHandler.TypeOverrides,
TData,
TExtensions
>;

export type Result<
TData = Record<string, any>,
TExtensions = Record<string, any>,
> =
| FormattedExecutionResult<TData, TExtensions>
| AdditionalApolloLinkResultTypes<
TData,
TExtensions
>[keyof AdditionalApolloLinkResultTypes<TData, TExtensions>];
| AdditionalResultTypes<TData, TExtensions>;

/**
* The currently executed operation object provided to an `ApolloLink.RequestHandler`
Expand Down
8 changes: 0 additions & 8 deletions src/link/core/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import type { FormattedExecutionResult, GraphQLFormattedError } from "graphql";
import type { DocumentNode } from "graphql";

export type { DocumentNode };

export interface ApolloPayloadResult<
TData = Record<string, any>,
Expand All @@ -12,8 +9,3 @@ export interface ApolloPayloadResult<
// these are fatal errors that will include done: true.
errors?: ReadonlyArray<GraphQLFormattedError>;
}

export interface AdditionalApolloLinkResultTypes<
TData = Record<string, any>,
TExtensions = Record<string, any>,
> {}
8 changes: 3 additions & 5 deletions src/link/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
export type { DocumentNode } from "graphql";

export { empty } from "./core/empty.js";
export { from } from "./core/from.js";
export { split } from "./core/split.js";
export { concat } from "./core/concat.js";
export { execute } from "./core/execute.js";
export { ApolloLink } from "./core/ApolloLink.js";

export type {
AdditionalApolloLinkResultTypes,
ApolloPayloadResult,
DocumentNode,
} from "./core/types.js";
export type { ApolloPayloadResult } from "./core/types.js";

export type {
FetchResult,
Expand Down
Loading