@apollo/client 4.0.0-rc.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2488 -0
- package/README.md +6 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs +2 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +18 -12
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.cjs +1 -1
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -1
- package/__cjs/core/QueryInfo.cjs +2 -6
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +1 -1
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +9 -6
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/incremental/handlers/notImplemented.d.cts +11 -0
- package/__cjs/link/batch/batchLink.cjs +30 -2
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +69 -2
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs +156 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs.map +1 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.d.cts +68 -0
- package/__cjs/link/batch-http/batchHttpLink.cjs +3 -128
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +4 -20
- package/__cjs/link/batch-http/index.cjs +2 -1
- package/__cjs/link/batch-http/index.cjs.map +1 -1
- package/__cjs/link/batch-http/index.d.cts +2 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +3 -3
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +20 -1
- package/__cjs/link/context/index.cjs +19 -0
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +64 -2
- package/__cjs/link/core/ApolloLink.cjs.map +1 -1
- package/__cjs/link/core/ApolloLink.d.cts +5 -2
- package/__cjs/link/core/types.d.cts +0 -4
- package/__cjs/link/http/BaseHttpLink.cjs +59 -8
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/BaseHttpLink.d.cts +256 -2
- package/__cjs/link/http/HttpLink.cjs +1 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +5 -208
- package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
- package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -7
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +2 -1
- package/__cjs/link/persisted-queries/index.cjs +16 -0
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +181 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +48 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +115 -0
- package/__cjs/link/retry/retryLink.cjs +25 -3
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +82 -9
- package/__cjs/link/schema/index.cjs +20 -0
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +128 -6
- package/__cjs/link/ws/index.cjs +18 -0
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +56 -5
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +10 -42
- package/__cjs/masking/PreserveTypes.cjs +3 -0
- package/__cjs/masking/PreserveTypes.cjs.map +1 -0
- package/__cjs/masking/PreserveTypes.d.cts +26 -0
- package/__cjs/masking/index.cjs.map +1 -1
- package/__cjs/masking/index.d.cts +1 -1
- package/__cjs/masking/internal/types.d.cts +0 -1
- package/__cjs/masking/types.d.cts +6 -23
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +2 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +2 -1
- package/__cjs/react/hooks/useQuery.d.cts +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +2 -1
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +2 -6
- package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +1 -1
- package/__cjs/react/types/deprecated.d.cts +1 -1
- package/__cjs/react/types/types.documentation.d.cts +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +1 -1
- package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
- package/__cjs/testing/react/MockedProvider.d.cts +5 -0
- package/__cjs/utilities/common/stripTypename.cjs +11 -0
- package/__cjs/utilities/common/stripTypename.cjs.map +1 -1
- package/__cjs/utilities/common/stripTypename.d.cts +11 -0
- package/__cjs/utilities/graphql/DocumentTransform.cjs +84 -1
- package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
- package/__cjs/utilities/graphql/DocumentTransform.d.cts +94 -5
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs +27 -0
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs.map +1 -1
- package/__cjs/utilities/graphql/isFormattedExecutionResult.d.cts +27 -0
- package/__cjs/utilities/graphql/operations.cjs +54 -3
- package/__cjs/utilities/graphql/operations.cjs.map +1 -1
- package/__cjs/utilities/graphql/operations.d.cts +54 -3
- package/__cjs/utilities/graphql/storeUtils.cjs +9 -0
- package/__cjs/utilities/graphql/storeUtils.cjs.map +1 -1
- package/__cjs/utilities/graphql/storeUtils.d.cts +9 -0
- package/__cjs/utilities/graphql/transform.cjs +12 -1
- package/__cjs/utilities/graphql/transform.cjs.map +1 -1
- package/__cjs/utilities/graphql/transform.d.cts +12 -1
- package/__cjs/utilities/internal/canonicalStringify.cjs +30 -7
- package/__cjs/utilities/internal/canonicalStringify.cjs.map +1 -1
- package/__cjs/utilities/internal/canonicalStringify.d.cts +30 -7
- package/__cjs/utilities/internal/getMainDefinition.cjs +36 -8
- package/__cjs/utilities/internal/getMainDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getMainDefinition.d.cts +36 -8
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +2 -6
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/v4-migration.cjs +9 -0
- package/__cjs/v4-migration.cjs.map +1 -0
- package/__cjs/v4-migration.d.cts +826 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/inmemory/inMemoryCache.js +2 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.js +18 -12
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/writeToStore.js +1 -1
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -1
- package/core/ObservableQuery.js +1 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +1 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +9 -6
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/notImplemented.d.ts +11 -0
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/legacyEntryPoints/v4-migration/index.d.ts +1 -0
- package/legacyEntryPoints/v4-migration/index.js +1 -0
- package/legacyEntryPoints/v4-migration/v4-migration.cjs +1 -0
- package/legacyEntryPoints/v4-migration/v4-migration.d.cts +1 -0
- package/link/batch/batchLink.d.ts +69 -2
- package/link/batch/batchLink.js +30 -2
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch-http/BaseBatchHttpLink.d.ts +68 -0
- package/link/batch-http/BaseBatchHttpLink.js +152 -0
- package/link/batch-http/BaseBatchHttpLink.js.map +1 -0
- package/link/batch-http/batchHttpLink.d.ts +5 -21
- package/link/batch-http/batchHttpLink.js +1 -125
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/index.d.ts +2 -1
- package/link/batch-http/index.js +2 -1
- package/link/batch-http/index.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +21 -2
- package/link/client-awareness/ClientAwarenessLink.js +3 -3
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +65 -3
- package/link/context/index.js +19 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +5 -2
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/types.d.ts +0 -4
- package/link/core/types.js.map +1 -1
- package/link/http/BaseHttpLink.d.ts +257 -3
- package/link/http/BaseHttpLink.js +59 -8
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +6 -209
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +2 -2
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +7 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/index.d.ts +2 -1
- package/link/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +182 -1
- package/link/persisted-queries/index.js +16 -0
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +115 -0
- package/link/remove-typename/removeTypenameFromVariables.js +48 -0
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/retryLink.d.ts +83 -10
- package/link/retry/retryLink.js +25 -3
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +129 -7
- package/link/schema/index.js +20 -0
- package/link/schema/index.js.map +1 -1
- package/link/ws/index.d.ts +56 -5
- package/link/ws/index.js +18 -0
- package/link/ws/index.js.map +1 -1
- package/local-state/LocalState.js.map +1 -1
- package/masking/GraphQLCodegenDataMasking.d.ts +10 -42
- package/masking/GraphQLCodegenDataMasking.js.map +1 -1
- package/masking/PreserveTypes.d.ts +26 -0
- package/masking/PreserveTypes.js +2 -0
- package/masking/PreserveTypes.js.map +1 -0
- package/masking/index.d.ts +1 -1
- package/masking/index.js.map +1 -1
- package/masking/internal/types.d.ts +0 -1
- package/masking/internal/types.js.map +1 -1
- package/masking/types.d.ts +6 -23
- package/masking/types.js.map +1 -1
- package/package.json +8 -2
- package/react/hooks/useBackgroundQuery.d.ts +2 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +1 -1
- package/react/hooks/useLoadableQuery.d.ts +2 -1
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +2 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +1 -1
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +2 -1
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +2 -1
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +2 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +1 -1
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +1 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/deprecated.d.ts +1 -1
- package/react/types/deprecated.js.map +1 -1
- package/react/types/types.documentation.d.ts +1 -1
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts +5 -0
- package/testing/react/MockedProvider.js.map +1 -1
- package/utilities/common/stripTypename.d.ts +11 -0
- package/utilities/common/stripTypename.js +11 -0
- package/utilities/common/stripTypename.js.map +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +94 -5
- package/utilities/graphql/DocumentTransform.js +84 -1
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/isFormattedExecutionResult.d.ts +27 -0
- package/utilities/graphql/isFormattedExecutionResult.js +27 -0
- package/utilities/graphql/isFormattedExecutionResult.js.map +1 -1
- package/utilities/graphql/operations.d.ts +54 -3
- package/utilities/graphql/operations.js +54 -3
- package/utilities/graphql/operations.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +9 -0
- package/utilities/graphql/storeUtils.js +9 -0
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts +12 -1
- package/utilities/graphql/transform.js +12 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/internal/canonicalStringify.d.ts +30 -7
- package/utilities/internal/canonicalStringify.js +30 -7
- package/utilities/internal/canonicalStringify.js.map +1 -1
- package/utilities/internal/getMainDefinition.d.ts +37 -9
- package/utilities/internal/getMainDefinition.js +36 -8
- package/utilities/internal/getMainDefinition.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -2
- package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/v4-migration.d.ts +826 -0
- package/v4-migration.js +8 -0
- package/v4-migration.js.map +1 -0
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -28,10 +28,49 @@ export declare namespace BatchLink {
|
|
|
28
28
|
batchKey?: (operation: ApolloLink.Operation) => string;
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Function type for handling a batch of GraphQL operations.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
*
|
|
36
|
+
* The batch handler is responsible for processing multiple operations together
|
|
37
|
+
* and returning their results. Each operation has a corresponding forward function
|
|
38
|
+
* that can be used to continue processing down the link chain.
|
|
39
|
+
*
|
|
40
|
+
* Results must be returned in the same order as the input operations to ensure
|
|
41
|
+
* proper correlation with the original requests.
|
|
42
|
+
*
|
|
43
|
+
* @param operations - Array of GraphQL operations to process
|
|
44
|
+
* @param forward - Array of forward functions, one per operation
|
|
45
|
+
* @returns Observable that emits an array of results in the same order as operations
|
|
46
|
+
*/
|
|
31
47
|
type BatchHandler = (operations: ApolloLink.Operation[], forward: ApolloLink.ForwardFunction[]) => Observable<ApolloLink.Result[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Configuration options for creating a `BatchLink` instance.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
*
|
|
53
|
+
* `BatchLink` options control how operations are grouped into batches
|
|
54
|
+
* and when those batches are processed. The `batchHandler` function
|
|
55
|
+
* is responsible for actually processing the batched operations.
|
|
56
|
+
*
|
|
57
|
+
* Most batching behavior is configured through timing options:
|
|
58
|
+
*
|
|
59
|
+
* - `batchInterval`: How long to wait before processing a batch
|
|
60
|
+
* - `batchDebounce`: Whether to reset the timer on new operations
|
|
61
|
+
* - `batchMax`: Maximum operations per batch (0 = unlimited)
|
|
62
|
+
*
|
|
63
|
+
* Custom grouping logic can be implemented via `batchKey` function.
|
|
64
|
+
*/
|
|
32
65
|
interface Options extends Shared.Options {
|
|
33
66
|
/**
|
|
34
|
-
* The handler that
|
|
67
|
+
* The handler that executes a batch of operations.
|
|
68
|
+
*
|
|
69
|
+
* @remarks
|
|
70
|
+
*
|
|
71
|
+
* This function receives an array of operations and their corresponding
|
|
72
|
+
* forward functions, and should return an Observable that emits the results
|
|
73
|
+
* for all operations in the batch.
|
|
35
74
|
*/
|
|
36
75
|
batchHandler?: BatchLink.BatchHandler;
|
|
37
76
|
/**
|
|
@@ -42,9 +81,37 @@ export declare namespace BatchLink {
|
|
|
42
81
|
batchMax?: number;
|
|
43
82
|
}
|
|
44
83
|
}
|
|
84
|
+
/**
|
|
85
|
+
* `BatchLink` is a non-terminating link that provides the core batching
|
|
86
|
+
* functionality for grouping multiple GraphQL operations into batches based
|
|
87
|
+
* on configurable timing and key-based grouping strategies. It serves as a base
|
|
88
|
+
* link to `BatchHttpLink`.
|
|
89
|
+
*
|
|
90
|
+
* @remarks
|
|
91
|
+
*
|
|
92
|
+
* > [!NOTE]
|
|
93
|
+
* > You will not generally use `BatchLink` on your own unless you need to
|
|
94
|
+
* > provide batching capabilities to third-party terminating links. Prefer
|
|
95
|
+
* > using `BatchHttpLink` to batch GraphQL operations over HTTP.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
*
|
|
99
|
+
* ```ts
|
|
100
|
+
* import { BatchLink } from "@apollo/client/link/batch";
|
|
101
|
+
*
|
|
102
|
+
* const link = new BatchLink({
|
|
103
|
+
* batchInterval: 20,
|
|
104
|
+
* batchMax: 5,
|
|
105
|
+
* batchHandler: (operations, forwards) => {
|
|
106
|
+
* // Custom logic to process batch of operations
|
|
107
|
+
* return handleBatch(operations, forwards);
|
|
108
|
+
* },
|
|
109
|
+
* });
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
45
112
|
export declare class BatchLink extends ApolloLink {
|
|
46
113
|
private batcher;
|
|
47
|
-
constructor(
|
|
114
|
+
constructor(options?: BatchLink.Options);
|
|
48
115
|
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
49
116
|
}
|
|
50
117
|
//# sourceMappingURL=batchLink.d.ts.map
|
package/link/batch/batchLink.js
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
import { EMPTY } from "rxjs";
|
|
2
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
3
|
import { OperationBatcher } from "./batching.js";
|
|
4
|
+
/**
|
|
5
|
+
* `BatchLink` is a non-terminating link that provides the core batching
|
|
6
|
+
* functionality for grouping multiple GraphQL operations into batches based
|
|
7
|
+
* on configurable timing and key-based grouping strategies. It serves as a base
|
|
8
|
+
* link to `BatchHttpLink`.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
*
|
|
12
|
+
* > [!NOTE]
|
|
13
|
+
* > You will not generally use `BatchLink` on your own unless you need to
|
|
14
|
+
* > provide batching capabilities to third-party terminating links. Prefer
|
|
15
|
+
* > using `BatchHttpLink` to batch GraphQL operations over HTTP.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { BatchLink } from "@apollo/client/link/batch";
|
|
21
|
+
*
|
|
22
|
+
* const link = new BatchLink({
|
|
23
|
+
* batchInterval: 20,
|
|
24
|
+
* batchMax: 5,
|
|
25
|
+
* batchHandler: (operations, forwards) => {
|
|
26
|
+
* // Custom logic to process batch of operations
|
|
27
|
+
* return handleBatch(operations, forwards);
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
4
32
|
export class BatchLink extends ApolloLink {
|
|
5
33
|
batcher;
|
|
6
|
-
constructor(
|
|
34
|
+
constructor(options) {
|
|
7
35
|
super();
|
|
8
|
-
const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () => EMPTY, batchKey = () => "", } =
|
|
36
|
+
const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () => EMPTY, batchKey = () => "", } = options || {};
|
|
9
37
|
this.batcher = new OperationBatcher({
|
|
10
38
|
batchDebounce,
|
|
11
39
|
batchInterval,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchLink.js","sourceRoot":"","sources":["../../../src/link/batch/batchLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"batchLink.js","sourceRoot":"","sources":["../../../src/link/batch/batchLink.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAyFjD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,OAAO,SAAU,SAAQ,UAAU;IAC/B,OAAO,CAAmB;IAElC,YAAY,OAA2B;QACrC,KAAK,EAAE,CAAC;QAER,MAAM,EACJ,aAAa,EACb,aAAa,GAAG,EAAE,EAClB,QAAQ,GAAG,CAAC,EACZ,YAAY,GAAG,GAAG,EAAE,CAAC,KAAK,EAC1B,QAAQ,GAAG,GAAG,EAAE,CAAC,EAAE,GACpB,GAAG,OAAO,IAAI,EAAE,CAAC;QAElB,IAAI,CAAC,OAAO,GAAG,IAAI,gBAAgB,CAAC;YAClC,aAAa;YACb,aAAa;YACb,QAAQ;YACR,YAAY;YACZ,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import type { Observable } from \"rxjs\";\nimport { EMPTY } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\n\nimport { OperationBatcher } from \"./batching.js\";\n\nexport declare namespace BatchLink {\n export namespace Shared {\n /** These options are shared between `BatchLink` and `BatchHttpLink` */\n interface Options {\n /**\n * The interval at which to batch, in milliseconds.\n *\n * @defaultValue 10\n */\n batchInterval?: number;\n\n /**\n * \"batchInterval\" is a throttling behavior by default, if you instead wish\n * to debounce outbound requests, set \"batchDebounce\" to true. More useful\n * for mutations than queries.\n */\n batchDebounce?: boolean;\n\n /**\n * The maximum number of operations to include in a single batch.\n *\n * @defaultValue \\{\\{defaultValue\\}\\}\n */\n batchMax?: number;\n\n /**\n * Creates the key for a batch\n */\n batchKey?: (operation: ApolloLink.Operation) => string;\n }\n }\n\n /**\n * Function type for handling a batch of GraphQL operations.\n *\n * @remarks\n *\n * The batch handler is responsible for processing multiple operations together\n * and returning their results. Each operation has a corresponding forward function\n * that can be used to continue processing down the link chain.\n *\n * Results must be returned in the same order as the input operations to ensure\n * proper correlation with the original requests.\n *\n * @param operations - Array of GraphQL operations to process\n * @param forward - Array of forward functions, one per operation\n * @returns Observable that emits an array of results in the same order as operations\n */\n export type BatchHandler = (\n operations: ApolloLink.Operation[],\n forward: ApolloLink.ForwardFunction[]\n ) => Observable<ApolloLink.Result[]>;\n\n /**\n * Configuration options for creating a `BatchLink` instance.\n *\n * @remarks\n *\n * `BatchLink` options control how operations are grouped into batches\n * and when those batches are processed. The `batchHandler` function\n * is responsible for actually processing the batched operations.\n *\n * Most batching behavior is configured through timing options:\n *\n * - `batchInterval`: How long to wait before processing a batch\n * - `batchDebounce`: Whether to reset the timer on new operations\n * - `batchMax`: Maximum operations per batch (0 = unlimited)\n *\n * Custom grouping logic can be implemented via `batchKey` function.\n */\n export interface Options extends Shared.Options {\n /**\n * The handler that executes a batch of operations.\n *\n * @remarks\n *\n * This function receives an array of operations and their corresponding\n * forward functions, and should return an Observable that emits the results\n * for all operations in the batch.\n */\n batchHandler?: BatchLink.BatchHandler;\n\n /** {@inheritDoc @apollo/client/link/batch!BatchLink.Shared.Options#batchMax:member {\"defaultValue\": 0}} */\n batchMax?: number;\n }\n}\n\n/**\n * `BatchLink` is a non-terminating link that provides the core batching\n * functionality for grouping multiple GraphQL operations into batches based\n * on configurable timing and key-based grouping strategies. It serves as a base\n * link to `BatchHttpLink`.\n *\n * @remarks\n *\n * > [!NOTE]\n * > You will not generally use `BatchLink` on your own unless you need to\n * > provide batching capabilities to third-party terminating links. Prefer\n * > using `BatchHttpLink` to batch GraphQL operations over HTTP.\n *\n * @example\n *\n * ```ts\n * import { BatchLink } from \"@apollo/client/link/batch\";\n *\n * const link = new BatchLink({\n * batchInterval: 20,\n * batchMax: 5,\n * batchHandler: (operations, forwards) => {\n * // Custom logic to process batch of operations\n * return handleBatch(operations, forwards);\n * },\n * });\n * ```\n */\nexport class BatchLink extends ApolloLink {\n private batcher: OperationBatcher;\n\n constructor(options?: BatchLink.Options) {\n super();\n\n const {\n batchDebounce,\n batchInterval = 10,\n batchMax = 0,\n batchHandler = () => EMPTY,\n batchKey = () => \"\",\n } = options || {};\n\n this.batcher = new OperationBatcher({\n batchDebounce,\n batchInterval,\n batchMax,\n batchHandler,\n batchKey,\n });\n }\n\n public request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n return this.batcher.enqueueRequest({ operation, forward });\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
|
+
import { ApolloLink } from "@apollo/client/link";
|
|
3
|
+
import { BatchLink } from "@apollo/client/link/batch";
|
|
4
|
+
import type { BaseHttpLink } from "@apollo/client/link/http";
|
|
5
|
+
export declare namespace BaseBatchHttpLink {
|
|
6
|
+
/**
|
|
7
|
+
* Options passed to `BaseBatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
8
|
+
* non-terminating links in the link chain also can set these values to
|
|
9
|
+
* customize the behavior of `BatchHttpLink` for each operation.
|
|
10
|
+
*
|
|
11
|
+
* > [!NOTE]
|
|
12
|
+
* > Some of these values can also be provided to the `BaseBatchHttpLink` constructor.
|
|
13
|
+
* > If a value is provided to both, the value in `context` takes precedence.
|
|
14
|
+
*/
|
|
15
|
+
interface ContextOptions extends BaseHttpLink.ContextOptions {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for creating a `BaseBatchHttpLink` instance.
|
|
19
|
+
*
|
|
20
|
+
* > [!NOTE]
|
|
21
|
+
* > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
|
|
22
|
+
* > Context options override the options passed to the constructor. Treat
|
|
23
|
+
* > these options as default values that are used when the request context
|
|
24
|
+
* > does not override the value.
|
|
25
|
+
*/
|
|
26
|
+
interface Options extends BatchLink.Shared.Options, BaseHttpLink.Shared.Options {
|
|
27
|
+
/**
|
|
28
|
+
* The maximum number of operations to include in a single batch.
|
|
29
|
+
*
|
|
30
|
+
* @defaultValue 10
|
|
31
|
+
*/
|
|
32
|
+
batchMax?: number;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* `BaseBatchHttpLink` is a terminating link that batches array of individual
|
|
37
|
+
* GraphQL operations into a single HTTP request that's sent to a single GraphQL
|
|
38
|
+
* endpoint. It serves as a base link to `BatchHttpLink`.
|
|
39
|
+
*
|
|
40
|
+
* @remarks
|
|
41
|
+
*
|
|
42
|
+
* > [!NOTE]
|
|
43
|
+
* > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use
|
|
44
|
+
* > `BaseBatchHttpLink` when you need to disable client awareness features and
|
|
45
|
+
* > would like to tree-shake the implementation of `ClientAwarenessLink` out
|
|
46
|
+
* > of your app bundle.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { BaseBatchHttpLink } from "@apollo/client/link/batch-http";
|
|
52
|
+
*
|
|
53
|
+
* const link = new BaseBatchHttpLink({
|
|
54
|
+
* uri: "http://localhost:4000/graphql",
|
|
55
|
+
* batchMax: 5, // No more than 5 operations per batch
|
|
56
|
+
* batchInterval: 20, // Wait no more than 20ms after first batched operation
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare class BaseBatchHttpLink extends ApolloLink {
|
|
61
|
+
private batchDebounce?;
|
|
62
|
+
private batchInterval;
|
|
63
|
+
private batchMax;
|
|
64
|
+
private batcher;
|
|
65
|
+
constructor(options?: BaseBatchHttpLink.Options);
|
|
66
|
+
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=BaseBatchHttpLink.d.ts.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Observable, throwError } from "rxjs";
|
|
2
|
+
import { ApolloLink } from "@apollo/client/link";
|
|
3
|
+
import { BatchLink } from "@apollo/client/link/batch";
|
|
4
|
+
import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI, } from "@apollo/client/link/http";
|
|
5
|
+
import { filterOperationVariables } from "@apollo/client/link/utils";
|
|
6
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
7
|
+
import { compact } from "@apollo/client/utilities/internal";
|
|
8
|
+
import { maybe } from "@apollo/client/utilities/internal/globals";
|
|
9
|
+
const backupFetch = maybe(() => fetch);
|
|
10
|
+
/**
|
|
11
|
+
* `BaseBatchHttpLink` is a terminating link that batches array of individual
|
|
12
|
+
* GraphQL operations into a single HTTP request that's sent to a single GraphQL
|
|
13
|
+
* endpoint. It serves as a base link to `BatchHttpLink`.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
*
|
|
17
|
+
* > [!NOTE]
|
|
18
|
+
* > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use
|
|
19
|
+
* > `BaseBatchHttpLink` when you need to disable client awareness features and
|
|
20
|
+
* > would like to tree-shake the implementation of `ClientAwarenessLink` out
|
|
21
|
+
* > of your app bundle.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { BaseBatchHttpLink } from "@apollo/client/link/batch-http";
|
|
27
|
+
*
|
|
28
|
+
* const link = new BaseBatchHttpLink({
|
|
29
|
+
* uri: "http://localhost:4000/graphql",
|
|
30
|
+
* batchMax: 5, // No more than 5 operations per batch
|
|
31
|
+
* batchInterval: 20, // Wait no more than 20ms after first batched operation
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export class BaseBatchHttpLink extends ApolloLink {
|
|
36
|
+
batchDebounce;
|
|
37
|
+
batchInterval;
|
|
38
|
+
batchMax;
|
|
39
|
+
batcher;
|
|
40
|
+
constructor(options = {}) {
|
|
41
|
+
super();
|
|
42
|
+
let { uri = "/graphql",
|
|
43
|
+
// use default global fetch if nothing is passed in
|
|
44
|
+
fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, batchInterval, batchDebounce, batchMax, batchKey, includeUnusedVariables = false, ...requestOptions } = options;
|
|
45
|
+
if (__DEV__) {
|
|
46
|
+
// Make sure at least one of preferredFetch, window.fetch, or backupFetch
|
|
47
|
+
// is defined, so requests won't fail at runtime.
|
|
48
|
+
checkFetcher(preferredFetch || backupFetch);
|
|
49
|
+
}
|
|
50
|
+
const linkConfig = {
|
|
51
|
+
http: compact({ includeExtensions, preserveHeaderCase }),
|
|
52
|
+
options: requestOptions.fetchOptions,
|
|
53
|
+
credentials: requestOptions.credentials,
|
|
54
|
+
headers: requestOptions.headers,
|
|
55
|
+
};
|
|
56
|
+
this.batchDebounce = batchDebounce;
|
|
57
|
+
this.batchInterval = batchInterval || 10;
|
|
58
|
+
this.batchMax = batchMax || 10;
|
|
59
|
+
const batchHandler = (operations) => {
|
|
60
|
+
const chosenURI = selectURI(operations[0], uri);
|
|
61
|
+
const context = operations[0].getContext();
|
|
62
|
+
const contextConfig = {
|
|
63
|
+
http: context.http,
|
|
64
|
+
options: context.fetchOptions,
|
|
65
|
+
credentials: context.credentials,
|
|
66
|
+
headers: context.headers,
|
|
67
|
+
};
|
|
68
|
+
//uses fallback, link, and then context to build options
|
|
69
|
+
const optsAndBody = operations.map((operation) => {
|
|
70
|
+
const result = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig);
|
|
71
|
+
if (result.body.variables && !includeUnusedVariables) {
|
|
72
|
+
result.body.variables = filterOperationVariables(result.body.variables, operation.query);
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
});
|
|
76
|
+
const loadedBody = optsAndBody.map(({ body }) => body);
|
|
77
|
+
const options = optsAndBody[0].options;
|
|
78
|
+
// There's no spec for using GET with batches.
|
|
79
|
+
if (options.method === "GET") {
|
|
80
|
+
return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
options.body = JSON.stringify(loadedBody);
|
|
84
|
+
}
|
|
85
|
+
catch (parseError) {
|
|
86
|
+
return throwError(() => parseError);
|
|
87
|
+
}
|
|
88
|
+
let controller;
|
|
89
|
+
if (!options.signal && typeof AbortController !== "undefined") {
|
|
90
|
+
controller = new AbortController();
|
|
91
|
+
options.signal = controller.signal;
|
|
92
|
+
}
|
|
93
|
+
return new Observable((observer) => {
|
|
94
|
+
// Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and
|
|
95
|
+
// otherwise fall back to the *current* global window.fetch function
|
|
96
|
+
// (see issue #7832), or (if all else fails) the backupFetch function we
|
|
97
|
+
// saved when this module was first evaluated. This last option protects
|
|
98
|
+
// against the removal of window.fetch, which is unlikely but not
|
|
99
|
+
// impossible.
|
|
100
|
+
const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
|
|
101
|
+
currentFetch(chosenURI, options)
|
|
102
|
+
.then((response) => {
|
|
103
|
+
// Make the raw response available in the context.
|
|
104
|
+
operations.forEach((operation) => operation.setContext({ response }));
|
|
105
|
+
return response;
|
|
106
|
+
})
|
|
107
|
+
.then(parseAndCheckHttpResponse(operations))
|
|
108
|
+
.then((result) => {
|
|
109
|
+
controller = undefined;
|
|
110
|
+
// we have data and can send it to back up the link chain
|
|
111
|
+
observer.next(result);
|
|
112
|
+
observer.complete();
|
|
113
|
+
return result;
|
|
114
|
+
})
|
|
115
|
+
.catch((err) => {
|
|
116
|
+
controller = undefined;
|
|
117
|
+
observer.error(err);
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
// XXX support canceling this request
|
|
121
|
+
// https://developers.google.com/web/updates/2017/09/abortable-fetch
|
|
122
|
+
if (controller)
|
|
123
|
+
controller.abort();
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
batchKey =
|
|
128
|
+
batchKey ||
|
|
129
|
+
((operation) => {
|
|
130
|
+
const context = operation.getContext();
|
|
131
|
+
const contextConfig = {
|
|
132
|
+
http: context.http,
|
|
133
|
+
options: context.fetchOptions,
|
|
134
|
+
credentials: context.credentials,
|
|
135
|
+
headers: context.headers,
|
|
136
|
+
};
|
|
137
|
+
//may throw error if config not serializable
|
|
138
|
+
return selectURI(operation, uri) + JSON.stringify(contextConfig);
|
|
139
|
+
});
|
|
140
|
+
this.batcher = new BatchLink({
|
|
141
|
+
batchDebounce: this.batchDebounce,
|
|
142
|
+
batchInterval: this.batchInterval,
|
|
143
|
+
batchMax: this.batchMax,
|
|
144
|
+
batchKey,
|
|
145
|
+
batchHandler,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
request(operation, forward) {
|
|
149
|
+
return this.batcher.request(operation, forward);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=BaseBatchHttpLink.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BaseBatchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/BaseBatchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAEtD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,yBAAyB,EACzB,gCAAgC,EAChC,SAAS,GACV,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AA8BlE,MAAM,WAAW,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IACvC,aAAa,CAAW;IACxB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GAAG;wBACpB,IAAI,EAAE,OAAO,CAAC,IAAI;wBAClB,OAAO,EAAE,OAAO,CAAC,YAAY;wBAC7B,WAAW,EAAE,OAAO,CAAC,WAAW;wBAChC,OAAO,EAAE,OAAO,CAAC,OAAO;qBACzB,CAAC;oBAEF,4CAA4C;oBAC5C,OAAO,SAAS,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { BatchLink } from \"@apollo/client/link/batch\";\nimport type { BaseHttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\n} from \"@apollo/client/link/http\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nexport declare namespace BaseBatchHttpLink {\n /**\n * Options passed to `BaseBatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous\n * non-terminating links in the link chain also can set these values to\n * customize the behavior of `BatchHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `BaseBatchHttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n export interface ContextOptions extends BaseHttpLink.ContextOptions {}\n /**\n * Configuration options for creating a `BaseBatchHttpLink` instance.\n *\n * > [!NOTE]\n * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).\n * > Context options override the options passed to the constructor. Treat\n * > these options as default values that are used when the request context\n * > does not override the value.\n */\n interface Options\n extends BatchLink.Shared.Options,\n BaseHttpLink.Shared.Options {\n /** {@inheritDoc @apollo/client/link/batch!BatchLink.Shared.Options#batchMax:member {\"defaultValue\": 10}} */\n batchMax?: number;\n }\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * `BaseBatchHttpLink` is a terminating link that batches array of individual\n * GraphQL operations into a single HTTP request that's sent to a single GraphQL\n * endpoint. It serves as a base link to `BatchHttpLink`.\n *\n * @remarks\n *\n * > [!NOTE]\n * > Prefer using `BatchHttpLink` over `BaseBatchHttpLink`. Use\n * > `BaseBatchHttpLink` when you need to disable client awareness features and\n * > would like to tree-shake the implementation of `ClientAwarenessLink` out\n * > of your app bundle.\n *\n * @example\n *\n * ```ts\n * import { BaseBatchHttpLink } from \"@apollo/client/link/batch-http\";\n *\n * const link = new BaseBatchHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * batchMax: 5, // No more than 5 operations per batch\n * batchInterval: 20, // Wait no more than 20ms after first batched operation\n * });\n * ```\n */\nexport class BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(options: BaseBatchHttpLink.Options = {}) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = options;\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch\n // is defined, so requests won't fail at runtime.\n checkFetcher(preferredFetch || backupFetch);\n }\n\n const linkConfig = {\n http: compact({ includeExtensions, preserveHeaderCase }),\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler: BatchLink.BatchHandler = (operations) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation) => {\n const result = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return throwError(\n () =>\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = JSON.stringify(loadedBody);\n } catch (parseError) {\n return throwError(() => parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable((observer) => {\n // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and\n // otherwise fall back to the *current* global window.fetch function\n // (see issue #7832), or (if all else fails) the backupFetch function we\n // saved when this module was first evaluated. This last option protects\n // against the removal of window.fetch, which is unlikely but not\n // impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n currentFetch!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: ApolloLink.Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n return this.batcher.request(operation, forward);\n }\n}\n"]}
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
import { Observable } from "rxjs";
|
|
2
1
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
|
-
import { BatchLink } from "@apollo/client/link/batch";
|
|
4
2
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
5
|
-
import
|
|
3
|
+
import { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
|
|
6
4
|
export declare namespace BatchHttpLink {
|
|
7
5
|
/**
|
|
8
6
|
* Options provided to the `BatchHttpLink` constructor.
|
|
9
7
|
*/
|
|
10
|
-
interface Options extends
|
|
11
|
-
/**
|
|
12
|
-
* The maximum number of operations to include in a single batch.
|
|
13
|
-
*
|
|
14
|
-
* @defaultValue 10
|
|
15
|
-
*/
|
|
16
|
-
batchMax?: number;
|
|
8
|
+
interface Options extends BaseBatchHttpLink.Options, ClientAwarenessLink.Options {
|
|
17
9
|
}
|
|
18
10
|
/**
|
|
19
11
|
* Options passed to `BatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
@@ -24,7 +16,7 @@ export declare namespace BatchHttpLink {
|
|
|
24
16
|
* > Some of these values can also be provided to the `BatchHttpLink` constructor.
|
|
25
17
|
* > If a value is provided to both, the value in `context` takes precedence.
|
|
26
18
|
*/
|
|
27
|
-
interface ContextOptions extends
|
|
19
|
+
interface ContextOptions extends BaseBatchHttpLink.ContextOptions, ClientAwarenessLink.ContextOptions {
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
22
|
/**
|
|
@@ -52,14 +44,6 @@ export declare namespace BatchHttpLink {
|
|
|
52
44
|
* ```
|
|
53
45
|
*/
|
|
54
46
|
export declare class BatchHttpLink extends ApolloLink {
|
|
55
|
-
constructor(options?: BatchHttpLink.Options
|
|
47
|
+
constructor(options?: BatchHttpLink.Options);
|
|
56
48
|
}
|
|
57
|
-
|
|
58
|
-
private batchDebounce?;
|
|
59
|
-
private batchInterval;
|
|
60
|
-
private batchMax;
|
|
61
|
-
private batcher;
|
|
62
|
-
constructor(fetchParams?: BatchHttpLink.Options);
|
|
63
|
-
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
64
|
-
}
|
|
65
|
-
//# sourceMappingURL=batchHttpLink.d.ts.map
|
|
49
|
+
//# sourceMappingURL=batchHttpLink.d.ts.map
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { Observable, throwError } from "rxjs";
|
|
2
1
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
|
-
import { BatchLink } from "@apollo/client/link/batch";
|
|
4
2
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
5
|
-
import {
|
|
6
|
-
import { filterOperationVariables } from "@apollo/client/link/utils";
|
|
7
|
-
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
8
|
-
import { compact } from "@apollo/client/utilities/internal";
|
|
9
|
-
import { maybe } from "@apollo/client/utilities/internal/globals";
|
|
10
|
-
const backupFetch = maybe(() => fetch);
|
|
3
|
+
import { BaseBatchHttpLink } from "./BaseBatchHttpLink.js";
|
|
11
4
|
/**
|
|
12
5
|
* `BatchHttpLink` is a terminating link that batches array of individual
|
|
13
6
|
* GraphQL operations into a single HTTP request that's sent to a single GraphQL
|
|
@@ -42,121 +35,4 @@ export class BatchHttpLink extends ApolloLink {
|
|
|
42
35
|
Object.assign(this, { left, right });
|
|
43
36
|
}
|
|
44
37
|
}
|
|
45
|
-
export class BaseBatchHttpLink extends ApolloLink {
|
|
46
|
-
batchDebounce;
|
|
47
|
-
batchInterval;
|
|
48
|
-
batchMax;
|
|
49
|
-
batcher;
|
|
50
|
-
constructor(fetchParams) {
|
|
51
|
-
super();
|
|
52
|
-
let { uri = "/graphql",
|
|
53
|
-
// use default global fetch if nothing is passed in
|
|
54
|
-
fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, batchInterval, batchDebounce, batchMax, batchKey, includeUnusedVariables = false, ...requestOptions } = fetchParams || {};
|
|
55
|
-
if (__DEV__) {
|
|
56
|
-
// Make sure at least one of preferredFetch, window.fetch, or backupFetch
|
|
57
|
-
// is defined, so requests won't fail at runtime.
|
|
58
|
-
checkFetcher(preferredFetch || backupFetch);
|
|
59
|
-
}
|
|
60
|
-
const linkConfig = {
|
|
61
|
-
http: compact({ includeExtensions, preserveHeaderCase }),
|
|
62
|
-
options: requestOptions.fetchOptions,
|
|
63
|
-
credentials: requestOptions.credentials,
|
|
64
|
-
headers: requestOptions.headers,
|
|
65
|
-
};
|
|
66
|
-
this.batchDebounce = batchDebounce;
|
|
67
|
-
this.batchInterval = batchInterval || 10;
|
|
68
|
-
this.batchMax = batchMax || 10;
|
|
69
|
-
const batchHandler = (operations) => {
|
|
70
|
-
const chosenURI = selectURI(operations[0], uri);
|
|
71
|
-
const context = operations[0].getContext();
|
|
72
|
-
const contextConfig = {
|
|
73
|
-
http: context.http,
|
|
74
|
-
options: context.fetchOptions,
|
|
75
|
-
credentials: context.credentials,
|
|
76
|
-
headers: context.headers,
|
|
77
|
-
};
|
|
78
|
-
//uses fallback, link, and then context to build options
|
|
79
|
-
const optsAndBody = operations.map((operation) => {
|
|
80
|
-
const result = selectHttpOptionsAndBodyInternal(operation, print, fallbackHttpConfig, linkConfig, contextConfig);
|
|
81
|
-
if (result.body.variables && !includeUnusedVariables) {
|
|
82
|
-
result.body.variables = filterOperationVariables(result.body.variables, operation.query);
|
|
83
|
-
}
|
|
84
|
-
return result;
|
|
85
|
-
});
|
|
86
|
-
const loadedBody = optsAndBody.map(({ body }) => body);
|
|
87
|
-
const options = optsAndBody[0].options;
|
|
88
|
-
// There's no spec for using GET with batches.
|
|
89
|
-
if (options.method === "GET") {
|
|
90
|
-
return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
options.body = JSON.stringify(loadedBody);
|
|
94
|
-
}
|
|
95
|
-
catch (parseError) {
|
|
96
|
-
return throwError(() => parseError);
|
|
97
|
-
}
|
|
98
|
-
let controller;
|
|
99
|
-
if (!options.signal && typeof AbortController !== "undefined") {
|
|
100
|
-
controller = new AbortController();
|
|
101
|
-
options.signal = controller.signal;
|
|
102
|
-
}
|
|
103
|
-
return new Observable((observer) => {
|
|
104
|
-
// Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and
|
|
105
|
-
// otherwise fall back to the *current* global window.fetch function
|
|
106
|
-
// (see issue #7832), or (if all else fails) the backupFetch function we
|
|
107
|
-
// saved when this module was first evaluated. This last option protects
|
|
108
|
-
// against the removal of window.fetch, which is unlikely but not
|
|
109
|
-
// impossible.
|
|
110
|
-
const currentFetch = preferredFetch || maybe(() => fetch) || backupFetch;
|
|
111
|
-
currentFetch(chosenURI, options)
|
|
112
|
-
.then((response) => {
|
|
113
|
-
// Make the raw response available in the context.
|
|
114
|
-
operations.forEach((operation) => operation.setContext({ response }));
|
|
115
|
-
return response;
|
|
116
|
-
})
|
|
117
|
-
.then(parseAndCheckHttpResponse(operations))
|
|
118
|
-
.then((result) => {
|
|
119
|
-
controller = undefined;
|
|
120
|
-
// we have data and can send it to back up the link chain
|
|
121
|
-
observer.next(result);
|
|
122
|
-
observer.complete();
|
|
123
|
-
return result;
|
|
124
|
-
})
|
|
125
|
-
.catch((err) => {
|
|
126
|
-
controller = undefined;
|
|
127
|
-
observer.error(err);
|
|
128
|
-
});
|
|
129
|
-
return () => {
|
|
130
|
-
// XXX support canceling this request
|
|
131
|
-
// https://developers.google.com/web/updates/2017/09/abortable-fetch
|
|
132
|
-
if (controller)
|
|
133
|
-
controller.abort();
|
|
134
|
-
};
|
|
135
|
-
});
|
|
136
|
-
};
|
|
137
|
-
batchKey =
|
|
138
|
-
batchKey ||
|
|
139
|
-
((operation) => {
|
|
140
|
-
const context = operation.getContext();
|
|
141
|
-
const contextConfig = {
|
|
142
|
-
http: context.http,
|
|
143
|
-
options: context.fetchOptions,
|
|
144
|
-
credentials: context.credentials,
|
|
145
|
-
headers: context.headers,
|
|
146
|
-
};
|
|
147
|
-
//may throw error if config not serializable
|
|
148
|
-
return selectURI(operation, uri) + JSON.stringify(contextConfig);
|
|
149
|
-
});
|
|
150
|
-
this.batcher = new BatchLink({
|
|
151
|
-
batchDebounce: this.batchDebounce,
|
|
152
|
-
batchInterval: this.batchInterval,
|
|
153
|
-
batchMax: this.batchMax,
|
|
154
|
-
batchKey,
|
|
155
|
-
batchHandler,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
request(operation, forward) {
|
|
159
|
-
return this.batcher.request(operation, forward);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
38
|
//# sourceMappingURL=batchHttpLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/batchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,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GAAG,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;QAEL,IAAI,CAAC,OAAO,GAAG,IAAI,SAAS,CAAC;YAC3B,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,aAAa,EAAE,IAAI,CAAC,aAAa;YACjC,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ;YACR,YAAY;SACb,CAAC,CAAC;IACL,CAAC;IAEM,OAAO,CACZ,SAA+B,EAC/B,OAAmC;QAEnC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;CACF","sourcesContent":["import { Observable, throwError } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { BatchLink } from \"@apollo/client/link/batch\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport type { HttpLink } from \"@apollo/client/link/http\";\nimport {\n checkFetcher,\n defaultPrinter,\n fallbackHttpConfig,\n parseAndCheckHttpResponse,\n selectHttpOptionsAndBodyInternal,\n selectURI,\n} from \"@apollo/client/link/http\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nexport declare namespace BatchHttpLink {\n /**\n * Options provided to the `BatchHttpLink` constructor.\n */\n export interface Options\n extends BatchLink.Shared.Options,\n HttpLink.Shared.Options {\n /** {@inheritDoc @apollo/client/link/batch!BatchLink.Shared.Options#batchMax:member {\"defaultValue\": 10}} */\n batchMax?: number;\n }\n\n /**\n * Options passed to `BatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous\n * non-terminating links in the link chain also can set these values to\n * customize the behavior of `BatchHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `BatchHttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n export interface ContextOptions extends HttpLink.ContextOptions {}\n}\n\nconst backupFetch = maybe(() => fetch);\n\n/**\n * `BatchHttpLink` is a terminating link that batches array of individual\n * GraphQL operations into a single HTTP request that's sent to a single GraphQL\n * endpoint. It combines the functionality of `BaseBatchHttpLink` and\n * `ClientAwarenessLink` into a single link.\n *\n * @remarks\n *\n * If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,\n * Apollo Client automatically batches executed GraphQL operations and transmits\n * them to your server according to the batching options you provide.\n *\n * @example\n *\n * ```ts\n * import { BatchHttpLink } from \"@apollo/client/link/batch-http\";\n *\n * const link = new BatchHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * batchMax: 5, // No more than 5 operations per batch\n * batchInterval: 20, // Wait no more than 20ms after first batched operation\n * });\n * ```\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(\n options: BatchHttpLink.Options & ClientAwarenessLink.Options = {}\n ) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\nexport class BaseBatchHttpLink extends ApolloLink {\n private batchDebounce?: boolean;\n private batchInterval: number;\n private batchMax: number;\n private batcher: ApolloLink;\n\n constructor(fetchParams?: BatchHttpLink.Options) {\n super();\n\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing is passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n batchInterval,\n batchDebounce,\n batchMax,\n batchKey,\n includeUnusedVariables = false,\n ...requestOptions\n } = fetchParams || ({} as BatchHttpLink.Options);\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch\n // is defined, so requests won't fail at runtime.\n checkFetcher(preferredFetch || backupFetch);\n }\n\n const linkConfig = {\n http: compact({ includeExtensions, preserveHeaderCase }),\n options: requestOptions.fetchOptions,\n credentials: requestOptions.credentials,\n headers: requestOptions.headers,\n };\n\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval || 10;\n this.batchMax = batchMax || 10;\n\n const batchHandler: BatchLink.BatchHandler = (operations) => {\n const chosenURI = selectURI(operations[0], uri);\n\n const context = operations[0].getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //uses fallback, link, and then context to build options\n const optsAndBody = operations.map((operation) => {\n const result = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (result.body.variables && !includeUnusedVariables) {\n result.body.variables = filterOperationVariables(\n result.body.variables,\n operation.query\n );\n }\n\n return result;\n });\n\n const loadedBody = optsAndBody.map(({ body }) => body);\n const options = optsAndBody[0].options;\n\n // There's no spec for using GET with batches.\n if (options.method === \"GET\") {\n return throwError(\n () =>\n new Error(\"apollo-link-batch-http does not support GET requests\")\n );\n }\n\n try {\n (options as any).body = JSON.stringify(loadedBody);\n } catch (parseError) {\n return throwError(() => parseError);\n }\n\n let controller: AbortController | undefined;\n if (!options.signal && typeof AbortController !== \"undefined\") {\n controller = new AbortController();\n options.signal = controller.signal;\n }\n\n return new Observable((observer) => {\n // Prefer BatchHttpLink.Options.fetch (preferredFetch) if provided, and\n // otherwise fall back to the *current* global window.fetch function\n // (see issue #7832), or (if all else fails) the backupFetch function we\n // saved when this module was first evaluated. This last option protects\n // against the removal of window.fetch, which is unlikely but not\n // impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n currentFetch!(chosenURI, options)\n .then((response) => {\n // Make the raw response available in the context.\n operations.forEach((operation) =>\n operation.setContext({ response })\n );\n return response;\n })\n .then(parseAndCheckHttpResponse(operations))\n .then((result) => {\n controller = undefined;\n // we have data and can send it to back up the link chain\n observer.next(result);\n observer.complete();\n return result;\n })\n .catch((err) => {\n controller = undefined;\n observer.error(err);\n });\n\n return () => {\n // XXX support canceling this request\n // https://developers.google.com/web/updates/2017/09/abortable-fetch\n if (controller) controller.abort();\n };\n });\n };\n\n batchKey =\n batchKey ||\n ((operation: ApolloLink.Operation) => {\n const context = operation.getContext();\n\n const contextConfig = {\n http: context.http,\n options: context.fetchOptions,\n credentials: context.credentials,\n headers: context.headers,\n };\n\n //may throw error if config not serializable\n return selectURI(operation, uri) + JSON.stringify(contextConfig);\n });\n\n this.batcher = new BatchLink({\n batchDebounce: this.batchDebounce,\n batchInterval: this.batchInterval,\n batchMax: this.batchMax,\n batchKey,\n batchHandler,\n });\n }\n\n public request(\n operation: ApolloLink.Operation,\n forward: ApolloLink.ForwardFunction\n ): Observable<ApolloLink.Result> {\n return this.batcher.request(operation, forward);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"batchHttpLink.js","sourceRoot":"","sources":["../../../src/link/batch-http/batchHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAwB3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAC3C,YAAY,UAAiC,EAAE;QAC7C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC;YAC/C,IAAI,mBAAmB,CAAC,OAAO,CAAC;YAChC,IAAI,iBAAiB,CAAC,OAAO,CAAC;SAC/B,CAAC,CAAC;QACH,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACvC,CAAC;CACF","sourcesContent":["import { ApolloLink } from \"@apollo/client/link\";\nimport { ClientAwarenessLink } from \"@apollo/client/link/client-awareness\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\n\nimport { BaseBatchHttpLink } from \"./BaseBatchHttpLink.js\";\n\nexport declare namespace BatchHttpLink {\n /**\n * Options provided to the `BatchHttpLink` constructor.\n */\n export interface Options\n extends BaseBatchHttpLink.Options,\n ClientAwarenessLink.Options {}\n\n /**\n * Options passed to `BatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous\n * non-terminating links in the link chain also can set these values to\n * customize the behavior of `BatchHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `BatchHttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n export interface ContextOptions\n extends BaseBatchHttpLink.ContextOptions,\n ClientAwarenessLink.ContextOptions {}\n}\n\n/**\n * `BatchHttpLink` is a terminating link that batches array of individual\n * GraphQL operations into a single HTTP request that's sent to a single GraphQL\n * endpoint. It combines the functionality of `BaseBatchHttpLink` and\n * `ClientAwarenessLink` into a single link.\n *\n * @remarks\n *\n * If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,\n * Apollo Client automatically batches executed GraphQL operations and transmits\n * them to your server according to the batching options you provide.\n *\n * @example\n *\n * ```ts\n * import { BatchHttpLink } from \"@apollo/client/link/batch-http\";\n *\n * const link = new BatchHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * batchMax: 5, // No more than 5 operations per batch\n * batchInterval: 20, // Wait no more than 20ms after first batched operation\n * });\n * ```\n */\nexport class BatchHttpLink extends ApolloLink {\n constructor(options: BatchHttpLink.Options = {}) {\n const { left, right, request } = ApolloLink.from([\n new ClientAwarenessLink(options),\n new BaseBatchHttpLink(options),\n ]);\n super(request);\n Object.assign(this, { left, right });\n }\n}\n"]}
|
package/link/batch-http/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch-http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { BaseBatchHttpLink
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch-http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { BaseBatchHttpLink } from \"./BaseBatchHttpLink.js\";\nexport { BatchHttpLink } from \"./batchHttpLink.js\";\n"]}
|