Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
41bcf5f
Don't export OperationBatcher from batch link
jerelmiller Aug 4, 2025
7ffe5c0
Don't export BatchableRequest from batch link
jerelmiller Aug 4, 2025
f6d2f28
Move BatchHandler type to BatchLink namespace
jerelmiller Aug 4, 2025
f34c7d8
Update type in BatchHttpLink
jerelmiller Aug 4, 2025
17c819f
Use ErrorLink.ErrorHandler instead
jerelmiller Aug 4, 2025
903cbf2
Update types in PersistedQueryLink
jerelmiller Aug 4, 2025
74a941f
Combine options types
jerelmiller Aug 4, 2025
797d340
Namespace types in RemoveTypenameFromVariablesLink
jerelmiller Aug 4, 2025
bd1edf1
Move DelayFunction types over to RetryLink
jerelmiller Aug 4, 2025
0367fd9
Move RetryFunction type to RetryLink
jerelmiller Aug 4, 2025
cc353f5
Rename RetryFunction to AttemptsFunction
jerelmiller Aug 4, 2025
b92973c
Move delay/retry function to retryLink file
jerelmiller Aug 4, 2025
19b29c8
Use namespace for type
jerelmiller Aug 4, 2025
daffbc6
Add changesets
jerelmiller Aug 4, 2025
44badde
Don't export `OperationBatcher` from `@apollo/client/link/batch`. Thi…
jerelmiller Aug 4, 2025
e1117f7
Update exports snapshot
jerelmiller Aug 4, 2025
8e48c3f
Update api report
jerelmiller Aug 4, 2025
7c5e710
Revert "Move delay/retry function to retryLink file"
jerelmiller Aug 4, 2025
7c1bcaa
Fix batch link tests with updated exports
jerelmiller Aug 4, 2025
0caf3f0
Update changeset
jerelmiller Aug 4, 2025
76cfacf
Merge branch 'release-4.0' into jerel/more-unify-types
jerelmiller Aug 5, 2025
baaf587
Use defaultValue tag
jerelmiller Aug 5, 2025
1d98845
BaseOptions -> Base.Options
jerelmiller Aug 5, 2025
bb57dce
Clean up Prettier, Size-limit, and Api-Extractor
jerelmiller Aug 5, 2025
b5c3403
Fix typo
jerelmiller Aug 5, 2025
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
32 changes: 4 additions & 28 deletions .api-reports/api-report-link_batch.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@
```ts

import { ApolloLink } from '@apollo/client/link';
import { Observable } from 'rxjs';

// @public (undocumented)
export interface BatchableRequest {
// (undocumented)
forward: ApolloLink.ForwardFunction;
// (undocumented)
operation: ApolloLink.Operation;
}

// @public (undocumented)
export type BatchHandler = (operations: ApolloLink.Operation[], forward: ApolloLink.ForwardFunction[]) => Observable<ApolloLink.Result[]>;
import type { Observable } from 'rxjs';

// @public (undocumented)
export namespace BatchLink {
// (undocumented)
export type BatchHandler = (operations: ApolloLink.Operation[], forward: ApolloLink.ForwardFunction[]) => Observable<ApolloLink.Result[]>;
// (undocumented)
export interface Options {
batchDebounce?: boolean;
batchHandler?: BatchHandler;
batchHandler?: BatchLink.BatchHandler;
batchInterval?: number;
batchKey?: (operation: ApolloLink.Operation) => string;
batchMax?: number;
Expand All @@ -37,21 +28,6 @@ export class BatchLink extends ApolloLink {
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
}

// @public (undocumented)
export class OperationBatcher {
constructor({ batchDebounce, batchInterval, batchMax, batchHandler, batchKey, }: {
batchDebounce?: boolean;
batchInterval?: number;
batchMax?: number;
batchHandler: BatchHandler;
batchKey?: (operation: ApolloLink.Operation) => string;
});
// (undocumented)
consumeQueue(key?: string): (Observable<ApolloLink.Result> | undefined)[] | undefined;
// (undocumented)
enqueueRequest(request: BatchableRequest): Observable<ApolloLink.Result>;
}

// (No @packageDocumentation comment for this package)

```
7 changes: 1 addition & 6 deletions .api-reports/api-report-link_error.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import { ApolloLink } from '@apollo/client/link';
import type { ErrorLike } from '@apollo/client';
import { Observable } from 'rxjs';

export interface ErrorHandler {
// (undocumented)
(options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;
}

Comment on lines -11 to -15

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The call here is generally to drop all the old Types?
I'm for it, just gotta be really thorough with the codemod.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought so since we've done it with others

// @public (undocumented)
export namespace ErrorLink {
export interface ErrorHandler {
Expand All @@ -34,7 +29,7 @@ export class ErrorLink extends ApolloLink {
}

// @public @deprecated (undocumented)
export function onError(errorHandler: ErrorHandler): ErrorLink;
export function onError(errorHandler: ErrorLink.ErrorHandler): ErrorLink;

// (No @packageDocumentation comment for this package)

Expand Down
52 changes: 21 additions & 31 deletions .api-reports/api-report-link_persisted-queries.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,50 @@ interface BaseOptions {
// @public @deprecated (undocumented)
export const createPersistedQueryLink: (options: PersistedQueryLink.Options) => PersistedQueryLink;

// @public (undocumented)
type ErrorMeta = {
persistedQueryNotSupported: boolean;
persistedQueryNotFound: boolean;
};

// @public (undocumented)
type GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<string>;

// @public (undocumented)
export namespace PersistedQueryLink {
// (undocumented)
export interface CallbackOptions {
// (undocumented)
error: ErrorLike;
// Warning: (ae-forgotten-export) The symbol "ErrorMeta" needs to be exported by the entry point index.d.ts
//
export interface DisableFunctionOptions extends PersistedQueryLink.RetryFunctionOptions {
}
// (undocumented)
export interface ErrorMeta {
// (undocumented)
meta: ErrorMeta;
persistedQueryNotFound: boolean;
// (undocumented)
operation: ApolloLink.Operation;
// (undocumented)
result?: FormattedExecutionResult;
persistedQueryNotSupported: boolean;
}
// (undocumented)
export interface DisableFunctionOptions extends CallbackOptions {
}
export type GenerateHashFunction = (document: DocumentNode) => string | PromiseLike<string>;
// (undocumented)
export interface GenerateHashOptions extends BaseOptions {
// Warning: (ae-forgotten-export) The symbol "GenerateHashFunction" needs to be exported by the entry point index.d.ts
//
// (undocumented)
generateHash: GenerateHashFunction;
generateHash: PersistedQueryLink.GenerateHashFunction;
// (undocumented)
sha256?: never;
}
// (undocumented)
export type Options = SHA256Options | GenerateHashOptions;
export type Options = PersistedQueryLink.SHA256Options | PersistedQueryLink.GenerateHashOptions;
// (undocumented)
export interface RetryFunctionOptions extends CallbackOptions {
export interface RetryFunctionOptions {
// (undocumented)
error: ErrorLike;
// (undocumented)
meta: PersistedQueryLink.ErrorMeta;
// (undocumented)
operation: ApolloLink.Operation;
// (undocumented)
result?: FormattedExecutionResult;
}
// (undocumented)
export type SHA256Function = (queryString: string) => string | PromiseLike<string>;
// Warning: (ae-forgotten-export) The symbol "BaseOptions" needs to be exported by the entry point index.d.ts
//
// (undocumented)
export interface SHA256Options extends BaseOptions {
// (undocumented)
generateHash?: never;
// Warning: (ae-forgotten-export) The symbol "SHA256Function" needs to be exported by the entry point index.d.ts
//
// (undocumented)
sha256: SHA256Function;
sha256: PersistedQueryLink.SHA256Function;
}
}

Expand All @@ -83,9 +76,6 @@ export class PersistedQueryLink extends ApolloLink {
resetHashCache: () => void;
}

// @public (undocumented)
type SHA256Function = (...args: any[]) => string | PromiseLike<string>;

// @public (undocumented)
export const VERSION = 1;

Expand Down
28 changes: 14 additions & 14 deletions .api-reports/api-report-link_remove-typename.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@ import { ApolloLink } from '@apollo/client/link';
// @public (undocumented)
export const KEEP = "__KEEP";

// @public (undocumented)
interface KeepTypenameConfig {
// (undocumented)
[key: string]: typeof KEEP | KeepTypenameConfig;
}

// @public @deprecated (undocumented)
export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesOptions): RemoveTypenameFromVariablesLink;
export function removeTypenameFromVariables(options?: RemoveTypenameFromVariablesLink.Options): RemoveTypenameFromVariablesLink;

// @public (undocumented)
export class RemoveTypenameFromVariablesLink extends ApolloLink {
constructor(options?: RemoveTypenameFromVariablesOptions);
export namespace RemoveTypenameFromVariablesLink {
// (undocumented)
export interface KeepTypenameConfig {
// (undocumented)
[key: string]: typeof KEEP | RemoveTypenameFromVariablesLink.KeepTypenameConfig;
}
// (undocumented)
export interface Options {
// (undocumented)
except?: RemoveTypenameFromVariablesLink.KeepTypenameConfig;
}
}

// @public (undocumented)
export interface RemoveTypenameFromVariablesOptions {
// Warning: (ae-forgotten-export) The symbol "KeepTypenameConfig" needs to be exported by the entry point index.d.ts
//
// (undocumented)
except?: KeepTypenameConfig;
export class RemoveTypenameFromVariablesLink extends ApolloLink {
constructor(options?: RemoveTypenameFromVariablesLink.Options);
}

// (No @packageDocumentation comment for this package)
Expand Down
48 changes: 17 additions & 31 deletions .api-reports/api-report-link_retry.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,27 @@
import { ApolloLink } from '@apollo/client/link';
import { Observable } from 'rxjs';

// @public
interface DelayFunction {
// (undocumented)
(count: number, operation: ApolloLink.Operation, error: any): number;
}

// @public (undocumented)
interface DelayFunctionOptions {
initial?: number;
jitter?: boolean;
max?: number;
}

// @public
interface RetryFunction {
// (undocumented)
(count: number, operation: ApolloLink.Operation, error: any): boolean | Promise<boolean>;
}

// @public (undocumented)
interface RetryFunctionOptions {
max?: number;
retryIf?: (error: any, operation: ApolloLink.Operation) => boolean | Promise<boolean>;
}

// @public (undocumented)
export namespace RetryLink {
// (undocumented)
export type AttemptsFunction = (count: number, operation: ApolloLink.Operation, error: any) => boolean | Promise<boolean>;
// (undocumented)
export interface AttemptsOptions {
max?: number;
retryIf?: (error: any, operation: ApolloLink.Operation) => boolean | Promise<boolean>;
}
// (undocumented)
export type DelayFunction = (count: number, operation: ApolloLink.Operation, error: any) => number;
// (undocumented)
export interface DelayOptions {
initial?: number;
jitter?: boolean;
max?: number;
}
// (undocumented)
export interface Options {
// Warning: (ae-forgotten-export) The symbol "RetryFunctionOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "RetryFunction" needs to be exported by the entry point index.d.ts
attempts?: RetryFunctionOptions | RetryFunction;
// Warning: (ae-forgotten-export) The symbol "DelayFunctionOptions" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DelayFunction" needs to be exported by the entry point index.d.ts
delay?: DelayFunctionOptions | DelayFunction;
attempts?: RetryLink.AttemptsOptions | RetryLink.AttemptsFunction;
delay?: RetryLink.DelayOptions | RetryLink.DelayFunction;
}
}

Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-link_schema.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Observable } from 'rxjs';
export namespace SchemaLink {
// (undocumented)
export interface Options {
context?: ResolverContext | ResolverContextFunction;
context?: SchemaLink.ResolverContext | SchemaLink.ResolverContextFunction;
rootValue?: any;
schema: GraphQLSchema;
validate?: boolean;
Expand Down
5 changes: 5 additions & 0 deletions .changeset/sharp-lemons-bathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": major
---

Move all 1st party link types into a namespace.
5 changes: 5 additions & 0 deletions .changeset/sour-wombats-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": major
---

The `OperationBatcher` class is no longer exported from `@apollo/client/link/batch`. It is an implementation detail of `BatchLink` and should not be relied on directly.
5 changes: 5 additions & 0 deletions .changeset/tough-hairs-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

Fix the type of the argument for the `sha256` function for `PersistedQueryLink` from `...any[]` to `string`.
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ Array [
exports[`exports of public entry points @apollo/client/link/batch 1`] = `
Array [
"BatchLink",
"OperationBatcher",
]
`;

Expand Down
3 changes: 1 addition & 2 deletions src/link/batch-http/batchHttpLink.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Observable, throwError } from "rxjs";

import { ApolloLink } from "@apollo/client/link";
import type { BatchHandler } from "@apollo/client/link/batch";
import { BatchLink } from "@apollo/client/link/batch";
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
import type { HttpLink } from "@apollo/client/link/http";
Expand Down Expand Up @@ -87,7 +86,7 @@ export class BaseBatchHttpLink extends ApolloLink {
this.batchInterval = batchInterval || 10;
this.batchMax = batchMax || 10;

const batchHandler: BatchHandler = (operations) => {
const batchHandler: BatchLink.BatchHandler = (operations) => {
const chosenURI = selectURI(operations[0], uri);

const context = operations[0].getContext();
Expand Down
11 changes: 7 additions & 4 deletions src/link/batch/__tests__/batchLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { gql } from "graphql-tag";
import { EMPTY, map, Observable, of } from "rxjs";

import { ApolloLink } from "@apollo/client/link";
import { BatchLink, OperationBatcher } from "@apollo/client/link/batch";
import { BatchLink } from "@apollo/client/link/batch";
import {
executeWithDefaultContext as execute,
ObservableStream,
wait,
} from "@apollo/client/testing/internal";

import type { BatchableRequest, BatchHandler } from "../batchLink.js";
import type { BatchableRequest } from "../batching.js";
// not exported
// eslint-disable-next-line local-rules/no-relative-imports
import { OperationBatcher } from "../batching.js";

interface MockedResponse {
request: ApolloLink.Request;
Expand Down Expand Up @@ -63,7 +66,7 @@ function requestToKey(request: ApolloLink.Request): string {
function createMockBatchHandler(...mockedResponses: MockedResponse[]) {
const mockedResponsesByKey: { [key: string]: MockedResponse[] } = {};

const mockBatchHandler: BatchHandler = (
const mockBatchHandler: BatchLink.BatchHandler = (
operations: ApolloLink.Operation[]
) => {
return new Observable((observer) => {
Expand Down Expand Up @@ -811,7 +814,7 @@ describe("BatchLink", () => {
expect(forward!.length).toBe(1);

return forward![0]!(operation[0]).pipe(map((d: any) => [d]));
}) as BatchHandler);
}) as BatchLink.BatchHandler);

const link = ApolloLink.from([
new BatchLink({
Expand Down
10 changes: 6 additions & 4 deletions src/link/batch/batchLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { EMPTY } from "rxjs";

import { ApolloLink } from "@apollo/client/link";

import type { BatchHandler } from "./batching.js";
import { OperationBatcher } from "./batching.js";
export type { BatchableRequest, BatchHandler } from "./batching.js";
export { OperationBatcher } from "./batching.js";

export declare namespace BatchLink {
export type BatchHandler = (
operations: ApolloLink.Operation[],
forward: ApolloLink.ForwardFunction[]
) => Observable<ApolloLink.Result[]>;

export interface Options {
/**
* The interval at which to batch, in milliseconds.
Expand All @@ -34,7 +36,7 @@ export declare namespace BatchLink {
/**
* The handler that should execute a batch of operations.
*/
batchHandler?: BatchHandler;
batchHandler?: BatchLink.BatchHandler;

/**
* creates the key for a batch
Expand Down
Loading