@apollo/client 4.0.0-rc.6 → 4.0.0-rc.8
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 +159 -0
- package/__cjs/cache/core/cache.cjs +12 -7
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +12 -7
- package/__cjs/core/ApolloClient.cjs +2 -2
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +80 -98
- package/__cjs/core/ObservableQuery.d.cts +41 -74
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +3 -3
- package/__cjs/core/QueryManager.cjs +0 -2
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +3 -3
- package/__cjs/core/index.cjs +1 -2
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -3
- package/__cjs/core/types.d.cts +40 -28
- package/__cjs/errors/CombinedGraphQLErrors.cjs +22 -17
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +39 -20
- package/__cjs/errors/CombinedProtocolErrors.cjs +12 -6
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +12 -6
- package/__cjs/errors/ServerError.cjs +2 -1
- package/__cjs/errors/ServerError.cjs.map +1 -1
- package/__cjs/errors/ServerError.d.cts +2 -1
- package/__cjs/errors/ServerParseError.cjs +2 -1
- package/__cjs/errors/ServerParseError.cjs.map +1 -1
- package/__cjs/errors/ServerParseError.d.cts +2 -1
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +4 -4
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/incremental/handlers/notImplemented.d.cts +2 -2
- package/__cjs/incremental/types.d.cts +4 -4
- package/__cjs/invariantErrorCodes.cjs +15 -11
- package/__cjs/link/batch/batchLink.cjs +4 -12
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +36 -28
- package/__cjs/link/batch/batching.cjs +1 -1
- package/__cjs/link/batch/batching.cjs.map +1 -1
- package/__cjs/link/batch/batching.d.cts +8 -8
- package/__cjs/link/batch/index.cjs +1 -2
- package/__cjs/link/batch/index.cjs.map +1 -1
- package/__cjs/link/batch/index.d.cts +1 -2
- package/__cjs/link/batch-http/batchHttpLink.cjs +29 -6
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +45 -6
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +33 -0
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +35 -2
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +3 -4
- package/__cjs/link/core/ApolloLink.cjs +226 -54
- package/__cjs/link/core/ApolloLink.cjs.map +1 -1
- package/__cjs/link/core/ApolloLink.d.cts +355 -9
- package/__cjs/link/core/concat.cjs +4 -0
- package/__cjs/link/core/concat.cjs.map +1 -1
- package/__cjs/link/core/concat.d.cts +4 -0
- package/__cjs/link/core/deprecated.cjs +3 -0
- package/__cjs/link/core/deprecated.cjs.map +1 -0
- package/__cjs/link/core/deprecated.d.cts +10 -0
- package/__cjs/link/core/empty.cjs +4 -0
- package/__cjs/link/core/empty.cjs.map +1 -1
- package/__cjs/link/core/empty.d.cts +4 -0
- package/__cjs/link/core/from.cjs +4 -0
- package/__cjs/link/core/from.cjs.map +1 -1
- package/__cjs/link/core/from.d.cts +4 -0
- package/__cjs/link/core/split.cjs +4 -0
- package/__cjs/link/core/split.cjs.map +1 -1
- package/__cjs/link/core/split.d.cts +4 -0
- package/__cjs/link/core/types.d.cts +2 -33
- package/__cjs/link/error/index.cjs +44 -0
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +68 -9
- package/__cjs/link/http/BaseHttpLink.cjs +3 -4
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.cjs +26 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +191 -89
- package/__cjs/link/http/index.cjs +1 -3
- package/__cjs/link/http/index.cjs.map +1 -1
- package/__cjs/link/http/index.d.cts +0 -2
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +40 -25
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.d.cts +2 -2
- package/__cjs/link/http/rewriteURIForGET.cjs +2 -3
- package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +3 -3
- package/__cjs/link/http/selectURI.cjs.map +1 -1
- package/__cjs/link/http/selectURI.d.cts +2 -2
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +2 -1
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +23 -25
- package/__cjs/link/remove-typename/index.cjs.map +1 -1
- package/__cjs/link/remove-typename/index.d.cts +0 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +9 -8
- package/__cjs/link/retry/delayFunction.cjs.map +1 -1
- package/__cjs/link/retry/delayFunction.d.cts +2 -39
- package/__cjs/link/retry/retryFunction.cjs.map +1 -1
- package/__cjs/link/retry/retryFunction.d.cts +2 -29
- package/__cjs/link/retry/retryLink.cjs +12 -9
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +57 -6
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +3 -4
- package/__cjs/link/subscriptions/index.cjs +23 -0
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- package/__cjs/link/subscriptions/index.d.cts +24 -2
- package/__cjs/link/utils/createOperation.cjs +12 -4
- package/__cjs/link/utils/createOperation.cjs.map +1 -1
- package/__cjs/link/utils/createOperation.d.cts +2 -2
- package/__cjs/link/utils/index.cjs +1 -5
- package/__cjs/link/utils/index.cjs.map +1 -1
- package/__cjs/link/utils/index.d.cts +0 -2
- package/__cjs/link/ws/index.cjs +17 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +8 -2
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +125 -93
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +70 -108
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +52 -61
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +36 -54
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +64 -105
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +17 -8
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +6 -9
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +32 -24
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +75 -94
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +3 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +29 -20
- package/__cjs/react/types/types.documentation.d.cts +5 -5
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +5 -6
- package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +3 -4
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +20 -28
- package/__cjs/utilities/internal/types/VariablesOption.d.cts +2 -6
- package/__cjs/utilities/subscriptions/relay/index.cjs +1 -2
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +12 -7
- package/cache/core/cache.js +12 -7
- package/cache/core/cache.js.map +1 -1
- package/core/ApolloClient.d.ts +80 -98
- package/core/ApolloClient.js +2 -2
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +41 -74
- package/core/QueryInfo.d.ts +3 -3
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.js +0 -2
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +2 -3
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +40 -28
- package/errors/CombinedGraphQLErrors.d.ts +39 -20
- package/errors/CombinedGraphQLErrors.js +22 -17
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +12 -6
- package/errors/CombinedProtocolErrors.js +12 -6
- package/errors/CombinedProtocolErrors.js.map +1 -1
- package/errors/ServerError.d.ts +2 -1
- package/errors/ServerError.js +2 -1
- package/errors/ServerError.js.map +1 -1
- package/errors/ServerParseError.d.ts +2 -1
- package/errors/ServerParseError.js +2 -1
- package/errors/ServerParseError.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +4 -4
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/notImplemented.d.ts +2 -2
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/incremental/types.d.ts +4 -4
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +15 -11
- package/link/batch/batchLink.d.ts +37 -29
- package/link/batch/batchLink.js +3 -10
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.d.ts +8 -8
- package/link/batch/batching.js +2 -2
- package/link/batch/batching.js.map +1 -1
- package/link/batch/index.d.ts +1 -2
- package/link/batch/index.js +1 -1
- package/link/batch/index.js.map +1 -1
- package/link/batch-http/batchHttpLink.d.ts +46 -7
- package/link/batch-http/batchHttpLink.js +30 -7
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +35 -2
- package/link/client-awareness/ClientAwarenessLink.js +33 -0
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +3 -4
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +355 -9
- package/link/core/ApolloLink.js +227 -56
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/concat.d.ts +4 -0
- package/link/core/concat.js +4 -0
- package/link/core/concat.js.map +1 -1
- package/link/core/deprecated.d.ts +10 -0
- package/link/core/deprecated.js +2 -0
- package/link/core/deprecated.js.map +1 -0
- package/link/core/empty.d.ts +4 -0
- package/link/core/empty.js +4 -0
- package/link/core/empty.js.map +1 -1
- package/link/core/from.d.ts +4 -0
- package/link/core/from.js +4 -0
- package/link/core/from.js.map +1 -1
- package/link/core/split.d.ts +4 -0
- package/link/core/split.js +4 -0
- package/link/core/split.js.map +1 -1
- package/link/core/types.d.ts +2 -33
- package/link/core/types.js.map +1 -1
- package/link/error/index.d.ts +69 -10
- package/link/error/index.js +44 -0
- package/link/error/index.js.map +1 -1
- package/link/http/BaseHttpLink.js +3 -4
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +192 -90
- package/link/http/HttpLink.js +26 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/index.d.ts +0 -2
- package/link/http/index.js +0 -1
- package/link/http/index.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
- package/link/http/parseAndCheckHttpResponse.js +40 -25
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/rewriteURIForGET.js +2 -3
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +3 -3
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.d.ts +2 -2
- package/link/http/selectURI.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 +23 -25
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/index.d.ts +0 -1
- package/link/remove-typename/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -8
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/delayFunction.d.ts +2 -39
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retryFunction.d.ts +2 -29
- package/link/retry/retryFunction.js.map +1 -1
- package/link/retry/retryLink.d.ts +57 -6
- package/link/retry/retryLink.js +13 -10
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +3 -4
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.d.ts +24 -2
- package/link/subscriptions/index.js +23 -0
- package/link/subscriptions/index.js.map +1 -1
- package/link/utils/createOperation.d.ts +2 -2
- package/link/utils/createOperation.js +12 -4
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/index.d.ts +0 -2
- package/link/utils/index.js +0 -2
- package/link/utils/index.js.map +1 -1
- package/link/ws/index.d.ts +8 -2
- package/link/ws/index.js +13 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +125 -93
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +2 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +70 -108
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +52 -61
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +36 -54
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +64 -105
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +17 -8
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +6 -9
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +32 -24
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +75 -94
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +125 -93
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +2 -2
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +70 -108
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +52 -61
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +36 -54
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +64 -105
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +17 -8
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +6 -9
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +32 -24
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +75 -94
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +3 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +29 -20
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/types.documentation.d.ts +5 -5
- package/testing/core/mocking/mockLink.d.ts +5 -6
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -4
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +20 -28
- package/utilities/internal/types/VariablesOption.d.ts +2 -6
- package/utilities/subscriptions/relay/index.js +1 -2
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +0 -18
- package/__cjs/link/http/serializeFetchParameter.cjs.map +0 -1
- package/__cjs/link/http/serializeFetchParameter.d.cts +0 -6
- package/__cjs/link/utils/transformOperation.cjs +0 -22
- package/__cjs/link/utils/transformOperation.cjs.map +0 -1
- package/__cjs/link/utils/transformOperation.d.cts +0 -3
- package/__cjs/link/utils/validateOperation.cjs +0 -21
- package/__cjs/link/utils/validateOperation.cjs.map +0 -1
- package/__cjs/link/utils/validateOperation.d.cts +0 -3
- package/link/http/serializeFetchParameter.d.ts +0 -6
- package/link/http/serializeFetchParameter.js +0 -14
- package/link/http/serializeFetchParameter.js.map +0 -1
- package/link/utils/transformOperation.d.ts +0 -3
- package/link/utils/transformOperation.js +0 -19
- package/link/utils/transformOperation.js.map +0 -1
- package/link/utils/validateOperation.d.ts +0 -3
- package/link/utils/validateOperation.js +0 -18
- package/link/utils/validateOperation.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, FormattedExecutionResult, GraphQLFormattedError } from "graphql";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApolloLink } from "@apollo/client/link";
|
|
3
3
|
import type { DeepPartial } from "@apollo/client/utilities";
|
|
4
4
|
import type { Incremental } from "../types.js";
|
|
5
5
|
export declare namespace Defer20220824Handler {
|
|
@@ -26,7 +26,7 @@ export declare namespace Defer20220824Handler {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
declare module "@apollo/client/link" {
|
|
29
|
-
interface
|
|
29
|
+
interface AdditionalApolloLinkResultTypes {
|
|
30
30
|
Defer20220824Handler: Defer20220824Handler.Chunk<Record<string, unknown>>;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -44,8 +44,8 @@ declare class DeferRequest<TData extends Record<string, unknown>> implements Inc
|
|
|
44
44
|
*/
|
|
45
45
|
export declare class Defer20220824Handler implements Incremental.Handler<Defer20220824Handler.Chunk<any>> {
|
|
46
46
|
isIncrementalResult(result: Record<string, any>): result is Defer20220824Handler.SubsequentResult | Defer20220824Handler.InitialResult;
|
|
47
|
-
extractErrors(result:
|
|
48
|
-
prepareRequest(request:
|
|
47
|
+
extractErrors(result: ApolloLink.Result<any>): GraphQLFormattedError[] | undefined;
|
|
48
|
+
prepareRequest(request: ApolloLink.Request): ApolloLink.Request;
|
|
49
49
|
startRequest<TData extends Record<string, unknown>>(_: {
|
|
50
50
|
query: DocumentNode;
|
|
51
51
|
}): DeferRequest<TData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer20220824.js","sourceRoot":"","sources":["../../../src/incremental/handlers/defer20220824.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAuC3C,MAAM,YAAY;IAIT,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M,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;wBACpB,MAAM,YAAY,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;wBAClC,MAAM,MAAM,GAAiC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;wBACpE,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;wBACnB,IAAI,GAAG,MAAqB,CAAC;oBAC/B,CAAC;gBACH,CAAC;gBACD,IAAI,CAAC,OAAO,CACV;oBACE,MAAM;oBACN,UAAU;oBACV,IAAI,EAAE,IAAI,CAAC,CAAC,CAAE,IAAc,CAAC,CAAC,CAAC,SAAS;iBACzC,EACD,MAAM,CACP,CAAC;YACJ,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAoC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;QAEpE,IAAI,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC9B,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC;QACtC,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAG/B,mBAAmB,CACjB,MAA2B;QAI3B,OAAO,SAAS,IAAI,MAAM,CAAC;IAC7B,CAAC;IAED,aAAa,CAAC,
|
|
1
|
+
{"version":3,"file":"defer20220824.js","sourceRoot":"","sources":["../../../src/incremental/handlers/defer20220824.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,UAAU,EACV,aAAa,EACb,eAAe,GAChB,MAAM,mCAAmC,CAAC;AAuC3C,MAAM,YAAY;IAIT,OAAO,GAAG,IAAI,CAA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I,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,MAAM,CAAC,CAAC;YACb,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;gBACjC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACnC,CAAC;QACH,CAAC;QACD,IAAI,GAAG,CAAC,MAAM,EAAE,CAAC;YACf,OAAO,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAED,cAAc,CAAC,OAA2B;QACxC,IAAI,aAAa,CAAC,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;YACtC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG;gBACZ,oCAAoC;gBACpC,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;aACvB,CAAC;QACJ,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,YAAY,CAAwC,CAEnD;QACC,OAAO,IAAI,YAAY,EAAS,CAAC;IACnC,CAAC;CACF;AAED,iCAAiC;AACjC,MAAM,UAAU,oBAAoB,CAClC,MAA2B;IAE3B,OAAO,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import type {\n DocumentNode,\n FormattedExecutionResult,\n GraphQLFormattedError,\n} from \"graphql\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\nimport type { DeepPartial } from \"@apollo/client/utilities\";\nimport {\n DeepMerger,\n hasDirectives,\n isNonEmptyArray,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { Incremental } from \"../types.js\";\n\nexport declare namespace Defer20220824Handler {\n export type InitialResult<TData = Record<string, unknown>> = {\n data?: TData | null | undefined;\n errors?: ReadonlyArray<GraphQLFormattedError>;\n extensions?: Record<string, unknown>;\n hasNext: boolean;\n };\n\n export type SubsequentResult<TData = Record<string, unknown>> = {\n data?: TData | null | undefined;\n errors?: ReadonlyArray<GraphQLFormattedError>;\n extensions?: Record<string, unknown>;\n hasNext: boolean;\n incremental?: Array<IncrementalDeferPayload<TData>>;\n };\n\n export type Chunk<TData extends Record<string, unknown>> =\n | InitialResult<TData>\n | SubsequentResult<TData>;\n\n export type IncrementalDeferPayload<TData = Record<string, unknown>> = {\n data?: TData | null | undefined;\n errors?: ReadonlyArray<GraphQLFormattedError>;\n extensions?: Record<string, unknown>;\n path?: Incremental.Path;\n label?: string;\n };\n}\n\ndeclare module \"@apollo/client/link\" {\n export interface AdditionalApolloLinkResultTypes {\n Defer20220824Handler: Defer20220824Handler.Chunk<Record<string, unknown>>;\n }\n}\n\nclass DeferRequest<TData extends Record<string, unknown>>\n implements\n Incremental.IncrementalRequest<Defer20220824Handler.Chunk<TData>, TData>\n{\n public hasNext = true;\n\n private errors: Array<GraphQLFormattedError> = [];\n private extensions: Record<string, any> = {};\n private data: any = {};\n\n private mergeIn(\n normalized: FormattedExecutionResult<TData>,\n merger: DeepMerger<any[]>\n ) {\n if (normalized.data !== undefined) {\n this.data = merger.merge(this.data, normalized.data);\n }\n if (normalized.errors) {\n this.errors.push(...normalized.errors);\n }\n Object.assign(this.extensions, normalized.extensions);\n }\n\n handle(\n // we'll get `undefined` here in case of a `no-cache` fetch policy,\n // so we'll continue with the last value this request had accumulated\n cacheData: TData | DeepPartial<TData> | null | undefined = this.data,\n chunk: Defer20220824Handler.Chunk<TData>\n ): FormattedExecutionResult<TData> {\n this.hasNext = chunk.hasNext;\n this.data = cacheData;\n\n this.mergeIn(chunk, new DeepMerger());\n\n if (hasIncrementalChunks(chunk)) {\n const merger = new DeepMerger();\n for (const incremental of chunk.incremental) {\n let { data, path, errors, extensions } = incremental;\n if (data && path) {\n for (let i = path.length - 1; i >= 0; --i) {\n const key = path[i];\n const isNumericKey = !isNaN(+key);\n const parent: Record<string | number, any> = isNumericKey ? [] : {};\n parent[key] = data;\n data = parent as typeof data;\n }\n }\n this.mergeIn(\n {\n errors,\n extensions,\n data: data ? (data as TData) : undefined,\n },\n merger\n );\n }\n }\n\n const result: FormattedExecutionResult<TData> = { data: this.data };\n\n if (isNonEmptyArray(this.errors)) {\n result.errors = this.errors;\n }\n\n if (Object.keys(this.extensions).length > 0) {\n result.extensions = this.extensions;\n }\n\n return result;\n }\n}\n\n/**\n * This handler implements the `@defer` directive as specified in this historical commit:\n * https://github.com/graphql/graphql-spec/tree/48cf7263a71a683fab03d45d309fd42d8d9a6659/spec\n */\nexport class Defer20220824Handler\n implements Incremental.Handler<Defer20220824Handler.Chunk<any>>\n{\n isIncrementalResult(\n result: Record<string, any>\n ): result is\n | Defer20220824Handler.SubsequentResult\n | Defer20220824Handler.InitialResult {\n return \"hasNext\" in result;\n }\n\n extractErrors(result: ApolloLink.Result<any>) {\n const acc: GraphQLFormattedError[] = [];\n const push = ({\n errors,\n }: {\n errors?: ReadonlyArray<GraphQLFormattedError>;\n }) => {\n if (errors) {\n acc.push(...errors);\n }\n };\n if (this.isIncrementalResult(result)) {\n push(result);\n if (hasIncrementalChunks(result)) {\n result.incremental.forEach(push);\n }\n }\n if (acc.length) {\n return acc;\n }\n }\n\n prepareRequest(request: ApolloLink.Request): ApolloLink.Request {\n if (hasDirectives([\"defer\"], request.query)) {\n const context = request.context ?? {};\n const http = (context.http ??= {});\n http.accept = [\n \"multipart/mixed;deferSpec=20220824\",\n ...(http.accept || []),\n ];\n }\n\n return request;\n }\n startRequest<TData extends Record<string, unknown>>(_: {\n query: DocumentNode;\n }) {\n return new DeferRequest<TData>();\n }\n}\n\n// only exported for use in tests\nexport function hasIncrementalChunks(\n result: Record<string, any>\n): result is Required<Defer20220824Handler.SubsequentResult> {\n return isNonEmptyArray(result.incremental);\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ApolloLink } from "@apollo/client/link";
|
|
2
2
|
import type { Incremental } from "../types.js";
|
|
3
3
|
export declare class NotImplementedHandler implements Incremental.Handler<never> {
|
|
4
4
|
isIncrementalResult(_: any): _ is never;
|
|
5
|
-
prepareRequest(request:
|
|
5
|
+
prepareRequest(request: ApolloLink.Request): ApolloLink.Request;
|
|
6
6
|
extractErrors(): void;
|
|
7
7
|
startRequest: any;
|
|
8
8
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notImplemented.js","sources":["../../../src/incremental/handlers/notImplemented.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"notImplemented.js","sources":["../../../src/incremental/handlers/notImplemented.ts"],"sourcesContent":["import type { ApolloLink } from \"@apollo/client/link\";\nimport { hasDirectives } from \"@apollo/client/utilities/internal\";\nimport { invariant } from \"@apollo/client/utilities/invariant\";\n\nimport type { Incremental } from \"../types.js\";\n\nexport class NotImplementedHandler implements Incremental.Handler<never> {\n isIncrementalResult(_: any): _ is never {\n return false;\n }\n prepareRequest(request: ApolloLink.Request) {\n invariant(\n !hasDirectives([\"defer\"], request.query),\n \"`@defer` is not supported without specifying an incremental handler. Please pass a handler as the `incrementalHandler` option to the `ApolloClient` constructor.\"\n );\n\n return request;\n }\n extractErrors() {}\n // This code path can never be reached, so we won't implement it.\n startRequest = undefined as any;\n}\n"],"names":[],"mappings":"AACA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAA8B,CAA9B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAiE;AACjE,CAAA,CAA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,EAAW,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,CAAkB;IAChB;IACA,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAe,CAAf,EAAA,EAAmB;IACjB,CAAF,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,EAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA;IACE,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAiB,CAAjB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAiC;AACjC;"}
|
package/incremental/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DocumentNode, FormattedExecutionResult, GraphQLFormattedError } from "graphql";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ApolloLink } from "@apollo/client/link";
|
|
3
3
|
import type { DeepPartial } from "@apollo/client/utilities";
|
|
4
4
|
export declare namespace Incremental {
|
|
5
5
|
type Path = ReadonlyArray<string | number>;
|
|
@@ -9,9 +9,9 @@ export declare namespace Incremental {
|
|
|
9
9
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
10
10
|
*/
|
|
11
11
|
interface Handler<Chunk extends Record<string, unknown> = Record<string, unknown>> {
|
|
12
|
-
isIncrementalResult: (result:
|
|
13
|
-
prepareRequest: (request:
|
|
14
|
-
extractErrors: (result:
|
|
12
|
+
isIncrementalResult: (result: ApolloLink.Result<any>) => result is Chunk;
|
|
13
|
+
prepareRequest: (request: ApolloLink.Request) => ApolloLink.Request;
|
|
14
|
+
extractErrors: (result: ApolloLink.Result<any>) => readonly GraphQLFormattedError[] | undefined | void;
|
|
15
15
|
startRequest: <TData extends Record<string, unknown>>(request: {
|
|
16
16
|
query: DocumentNode;
|
|
17
17
|
}) => IncrementalRequest<Chunk, TData>;
|
package/incremental/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/incremental/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DocumentNode,\n FormattedExecutionResult,\n GraphQLFormattedError,\n} from \"graphql\";\n\nimport type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/incremental/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n DocumentNode,\n FormattedExecutionResult,\n GraphQLFormattedError,\n} from \"graphql\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\nimport type { DeepPartial } from \"@apollo/client/utilities\";\n\nexport declare namespace Incremental {\n export type Path = ReadonlyArray<string | number>;\n\n /** @internal */\n export interface Handler<\n Chunk extends Record<string, unknown> = Record<string, unknown>,\n > {\n isIncrementalResult: (result: ApolloLink.Result<any>) => result is Chunk;\n prepareRequest: (request: ApolloLink.Request) => ApolloLink.Request;\n extractErrors: (\n result: ApolloLink.Result<any>\n ) => readonly GraphQLFormattedError[] | undefined | void;\n startRequest: <TData extends Record<string, unknown>>(request: {\n query: DocumentNode;\n }) => IncrementalRequest<Chunk, TData>;\n }\n\n export interface IncrementalRequest<\n Chunk extends Record<string, unknown>,\n TData,\n > {\n hasNext: boolean;\n handle: (\n cacheData: TData | DeepPartial<TData> | undefined | null,\n chunk: Chunk\n ) => FormattedExecutionResult<TData>;\n }\n}\n"]}
|
package/invariantErrorCodes.js
CHANGED
|
@@ -289,11 +289,6 @@ you have an infinite render loop in your application.`
|
|
|
289
289
|
message: "The configured cache does not support fragment matching which will lead to incorrect results when executing local resolvers. Please use a cache that implements `fragmetMatches`."
|
|
290
290
|
},
|
|
291
291
|
|
|
292
|
-
56: {
|
|
293
|
-
file: "@apollo/client/link/utils/validateOperation.js",
|
|
294
|
-
message: `illegal argument: %s`
|
|
295
|
-
},
|
|
296
|
-
|
|
297
292
|
57: {
|
|
298
293
|
file: "@apollo/client/link/persisted-queries/index.js",
|
|
299
294
|
condition: "options &&\n (typeof options.sha256 === \"function\" ||\n typeof options.generateHash === \"function\")",
|
|
@@ -333,11 +328,6 @@ const client = new ApolloClient({
|
|
|
333
328
|
message: "Unknown type for `response.body`. Please use a `fetch` implementation that is WhatWG-compliant and that uses WhatWG ReadableStreams for `body`."
|
|
334
329
|
},
|
|
335
330
|
|
|
336
|
-
61: {
|
|
337
|
-
file: "@apollo/client/link/http/serializeFetchParameter.js",
|
|
338
|
-
message: `Network request failed. %s is not serializable: %s`
|
|
339
|
-
},
|
|
340
|
-
|
|
341
331
|
63: {
|
|
342
332
|
file: "@apollo/client/link/core/ApolloLink.js",
|
|
343
333
|
message: "request is not implemented"
|
|
@@ -594,9 +584,23 @@ export const devWarn = {
|
|
|
594
584
|
message: "The '%s' field on object %o returned `undefined` instead of a value. The parent resolver did not include the property in the returned value and there was no resolver defined for the field."
|
|
595
585
|
},
|
|
596
586
|
|
|
587
|
+
56: {
|
|
588
|
+
file: "@apollo/client/link/ws/index.js",
|
|
589
|
+
message: "`WebSocketLink` uses the deprecated and unmaintained `subscriptions-transport-ws` library. This link is no longer maintained and will be removed in a future major version of Apollo Client. We recommend switching to `GraphQLWsLink` which uses the `graphql-ws` library to send GraphQL operations through WebSocket connections (https://the-guild.dev/graphql/ws)."
|
|
590
|
+
},
|
|
591
|
+
|
|
592
|
+
61: {
|
|
593
|
+
file: "@apollo/client/link/core/ApolloLink.js",
|
|
594
|
+
message: "[ApolloLink.split]: The test function returned a non-boolean value which could result in subtle bugs (e.g. such as using an `async` function which always returns a truthy value). Got `%o`."
|
|
595
|
+
},
|
|
596
|
+
|
|
597
597
|
62: {
|
|
598
598
|
file: "@apollo/client/link/core/ApolloLink.js",
|
|
599
|
-
|
|
599
|
+
|
|
600
|
+
message: "The terminating link provided to `ApolloLink.execute` called `forward` instead of handling the request. " +
|
|
601
|
+
"This results in an observable that immediately completes and does not emit a value. " +
|
|
602
|
+
"Please provide a terminating link that properly handles the request.\n\n" +
|
|
603
|
+
"If you are using a split link, ensure each branch contains a terminating link that handles the request."
|
|
600
604
|
},
|
|
601
605
|
|
|
602
606
|
77: {
|
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
import type { Observable } from "rxjs";
|
|
2
|
-
import type { FetchResult, NextLink, Operation } from "@apollo/client/link";
|
|
3
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
4
|
-
import type { BatchHandler } from "./batching.js";
|
|
5
|
-
export type { BatchableRequest, BatchHandler } from "./batching.js";
|
|
6
|
-
export { OperationBatcher } from "./batching.js";
|
|
7
3
|
export declare namespace BatchLink {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
4
|
+
namespace Shared {
|
|
5
|
+
/** These options are shared between `BatchLink` and `BatchHttpLink` */
|
|
6
|
+
interface Options {
|
|
7
|
+
/**
|
|
8
|
+
* The interval at which to batch, in milliseconds.
|
|
9
|
+
*
|
|
10
|
+
* @defaultValue 10
|
|
11
|
+
*/
|
|
12
|
+
batchInterval?: number;
|
|
13
|
+
/**
|
|
14
|
+
* "batchInterval" is a throttling behavior by default, if you instead wish
|
|
15
|
+
* to debounce outbound requests, set "batchDebounce" to true. More useful
|
|
16
|
+
* for mutations than queries.
|
|
17
|
+
*/
|
|
18
|
+
batchDebounce?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The maximum number of operations to include in a single batch.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue \{\{defaultValue\}\}
|
|
23
|
+
*/
|
|
24
|
+
batchMax?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Creates the key for a batch
|
|
27
|
+
*/
|
|
28
|
+
batchKey?: (operation: ApolloLink.Operation) => string;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
type BatchHandler = (operations: ApolloLink.Operation[], forward: ApolloLink.ForwardFunction[]) => Observable<ApolloLink.Result[]>;
|
|
32
|
+
interface Options extends Shared.Options {
|
|
27
33
|
/**
|
|
28
34
|
* The handler that should execute a batch of operations.
|
|
29
35
|
*/
|
|
30
|
-
batchHandler?: BatchHandler;
|
|
36
|
+
batchHandler?: BatchLink.BatchHandler;
|
|
31
37
|
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
* The maximum number of operations to include in a single batch.
|
|
39
|
+
*
|
|
40
|
+
* @defaultValue 0
|
|
41
|
+
*/
|
|
42
|
+
batchMax?: number;
|
|
35
43
|
}
|
|
36
44
|
}
|
|
37
45
|
export declare class BatchLink extends ApolloLink {
|
|
38
46
|
private batcher;
|
|
39
47
|
constructor(fetchParams?: BatchLink.Options);
|
|
40
|
-
request(operation: Operation, forward
|
|
48
|
+
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
41
49
|
}
|
|
42
|
-
//# sourceMappingURL=batchLink.d.ts.map
|
|
50
|
+
//# sourceMappingURL=batchLink.d.ts.map
|
package/link/batch/batchLink.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
import { EMPTY } from "rxjs";
|
|
1
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
2
3
|
import { OperationBatcher } from "./batching.js";
|
|
3
|
-
export { OperationBatcher } from "./batching.js";
|
|
4
4
|
export class BatchLink extends ApolloLink {
|
|
5
5
|
batcher;
|
|
6
6
|
constructor(fetchParams) {
|
|
7
7
|
super();
|
|
8
|
-
const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () =>
|
|
8
|
+
const { batchDebounce, batchInterval = 10, batchMax = 0, batchHandler = () => EMPTY, batchKey = () => "", } = fetchParams || {};
|
|
9
9
|
this.batcher = new OperationBatcher({
|
|
10
10
|
batchDebounce,
|
|
11
11
|
batchInterval,
|
|
@@ -13,16 +13,9 @@ export class BatchLink extends ApolloLink {
|
|
|
13
13
|
batchHandler,
|
|
14
14
|
batchKey,
|
|
15
15
|
});
|
|
16
|
-
//make this link terminating
|
|
17
|
-
if (fetchParams.batchHandler.length <= 1) {
|
|
18
|
-
this.request = (operation) => this.batcher.enqueueRequest({ operation });
|
|
19
|
-
}
|
|
20
16
|
}
|
|
21
17
|
request(operation, forward) {
|
|
22
|
-
return this.batcher.enqueueRequest({
|
|
23
|
-
operation,
|
|
24
|
-
forward,
|
|
25
|
-
});
|
|
18
|
+
return this.batcher.enqueueRequest({ operation, forward });
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
21
|
//# sourceMappingURL=batchLink.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchLink.js","sourceRoot":"","sources":["../../../src/link/batch/batchLink.ts"],"names":[],"mappings":"
|
|
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;AAkDjD,MAAM,OAAO,SAAU,SAAQ,UAAU;IAC/B,OAAO,CAAmB;IAElC,YAAY,WAA+B;QACzC,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,WAAW,IAAI,EAAE,CAAC;QAEtB,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 export type BatchHandler = (\n operations: ApolloLink.Operation[],\n forward: ApolloLink.ForwardFunction[]\n ) => Observable<ApolloLink.Result[]>;\n\n export interface Options extends Shared.Options {\n /**\n * The handler that should execute a batch of operations.\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\nexport class BatchLink extends ApolloLink {\n private batcher: OperationBatcher;\n\n constructor(fetchParams?: BatchLink.Options) {\n super();\n\n const {\n batchDebounce,\n batchInterval = 10,\n batchMax = 0,\n batchHandler = () => EMPTY,\n batchKey = () => \"\",\n } = fetchParams || {};\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"]}
|
package/link/batch/batching.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { ApolloLink } from "@apollo/client/link";
|
|
3
|
+
import type { BatchLink } from "./batchLink.js";
|
|
4
4
|
export interface BatchableRequest {
|
|
5
|
-
operation: Operation;
|
|
6
|
-
forward
|
|
5
|
+
operation: ApolloLink.Operation;
|
|
6
|
+
forward: ApolloLink.ForwardFunction;
|
|
7
7
|
}
|
|
8
8
|
export declare class OperationBatcher {
|
|
9
9
|
private batchesByKey;
|
|
@@ -17,11 +17,11 @@ export declare class OperationBatcher {
|
|
|
17
17
|
batchDebounce?: boolean;
|
|
18
18
|
batchInterval?: number;
|
|
19
19
|
batchMax?: number;
|
|
20
|
-
batchHandler: BatchHandler;
|
|
21
|
-
batchKey?: (operation: Operation) => string;
|
|
20
|
+
batchHandler: BatchLink.BatchHandler;
|
|
21
|
+
batchKey?: (operation: ApolloLink.Operation) => string;
|
|
22
22
|
});
|
|
23
|
-
enqueueRequest(request: BatchableRequest): Observable<
|
|
24
|
-
consumeQueue(key?: string): (Observable<
|
|
23
|
+
enqueueRequest(request: BatchableRequest): Observable<ApolloLink.Result>;
|
|
24
|
+
consumeQueue(key?: string): (Observable<ApolloLink.Result> | undefined)[] | undefined;
|
|
25
25
|
private scheduleQueueConsumption;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=batching.d.ts.map
|
package/link/batch/batching.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Observable } from "rxjs";
|
|
2
2
|
// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within
|
|
3
3
|
// a certain amount of time (configurable through `batchInterval`) will be batched together
|
|
4
4
|
// into one query.
|
|
@@ -103,7 +103,7 @@ export class OperationBatcher {
|
|
|
103
103
|
errors.push(request.error);
|
|
104
104
|
completes.push(request.complete);
|
|
105
105
|
});
|
|
106
|
-
const batchedObservable = this.batchHandler(operations, forwards)
|
|
106
|
+
const batchedObservable = this.batchHandler(operations, forwards);
|
|
107
107
|
const onError = (error) => {
|
|
108
108
|
//each callback list in batch
|
|
109
109
|
errors.forEach((rejecters) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batching.js","sourceRoot":"","sources":["../../../src/link/batch/batching.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AA4BzC,qFAAqF;AACrF,2FAA2F;AAC3F,kBAAkB;AAClB,MAAM,OAAO,gBAAgB;IAC3B,oEAAoE;IAC5D,YAAY,GAAG,IAAI,GAAG,EAAwB,CAAC;IAE/C,wBAAwB,GAAG,IAAI,GAAG,EAGvC,CAAC;IACI,aAAa,CAAW;IACxB,aAAa,CAAU;IACvB,QAAQ,CAAS;IAEzB,oEAAoE;IAC5D,YAAY,CAAe;IAC3B,QAAQ,CAAmC;IAEnD,YAAY,EACV,aAAa,EACb,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,QAAQ,GAOT;QACC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IAEM,cAAc,CAAC,OAAyB;QAC7C,MAAM,WAAW,GAAkB;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GAAG,CAC/B,GAAG,EACH,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CACvB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { EMPTY, Observable } from \"rxjs\";\n\nimport type { FetchResult, NextLink, Operation } from \"@apollo/client/link\";\n\nexport type BatchHandler = (\n operations: Operation[],\n forward?: (NextLink | undefined)[]\n) => Observable<FetchResult[]> | null;\n\nexport interface BatchableRequest {\n operation: Operation;\n forward?: NextLink;\n}\n\ntype QueuedRequest = BatchableRequest & {\n observable?: Observable<FetchResult>;\n next: Array<(result: FetchResult) => void>;\n error: Array<(error: Error) => void>;\n complete: Array<() => void>;\n subscribers: Set<object>;\n};\n\n// Batches are primarily a Set<QueuedRequest>, but may have other optional\n// properties, such as batch.subscription.\ntype RequestBatch = Set<QueuedRequest> & {\n subscription?: Subscription;\n};\n\n// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within\n// a certain amount of time (configurable through `batchInterval`) will be batched together\n// into one query.\nexport class OperationBatcher {\n // Queue on which the QueryBatcher will operate on a per-tick basis.\n private batchesByKey = new Map<string, RequestBatch>();\n\n private scheduledBatchTimerByKey = new Map<\n string,\n ReturnType<typeof setTimeout>\n >();\n private batchDebounce?: boolean;\n private batchInterval?: number;\n private batchMax: number;\n\n //This function is called to the queries in the queue to the server.\n private batchHandler: BatchHandler;\n private batchKey: (operation: Operation) => string;\n\n constructor({\n batchDebounce,\n batchInterval,\n batchMax,\n batchHandler,\n batchKey,\n }: {\n batchDebounce?: boolean;\n batchInterval?: number;\n batchMax?: number;\n batchHandler: BatchHandler;\n batchKey?: (operation: Operation) => string;\n }) {\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval;\n this.batchMax = batchMax || 0;\n this.batchHandler = batchHandler;\n this.batchKey = batchKey || (() => \"\");\n }\n\n public enqueueRequest(request: BatchableRequest): Observable<FetchResult> {\n const requestCopy: QueuedRequest = {\n ...request,\n next: [],\n error: [],\n complete: [],\n subscribers: new Set(),\n };\n\n const key = this.batchKey(request.operation);\n\n if (!requestCopy.observable) {\n requestCopy.observable = new Observable<FetchResult>((observer) => {\n let batch = this.batchesByKey.get(key)!;\n if (!batch) this.batchesByKey.set(key, (batch = new Set()));\n\n // These booleans seem to me (@benjamn) like they might always be the\n // same (and thus we could do with only one of them), but I'm not 100%\n // sure about that.\n const isFirstEnqueuedRequest = batch.size === 0;\n const isFirstSubscriber = requestCopy.subscribers.size === 0;\n requestCopy.subscribers.add(observer);\n if (isFirstSubscriber) {\n batch.add(requestCopy);\n }\n\n // called for each subscriber, so need to save all listeners (next, error, complete)\n if (observer.next) {\n requestCopy.next.push(observer.next.bind(observer));\n }\n\n if (observer.error) {\n requestCopy.error.push(observer.error.bind(observer));\n }\n\n if (observer.complete) {\n requestCopy.complete.push(observer.complete.bind(observer));\n }\n\n // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds.\n if (isFirstEnqueuedRequest || this.batchDebounce) {\n this.scheduleQueueConsumption(key);\n }\n\n // When amount of requests reaches `batchMax`, trigger the queue consumption without waiting on the `batchInterval`.\n if (batch.size === this.batchMax) {\n this.consumeQueue(key);\n }\n\n return () => {\n // If this is last subscriber for this request, remove request from queue\n if (\n requestCopy.subscribers.delete(observer) &&\n requestCopy.subscribers.size < 1\n ) {\n // If this is last request from queue, remove queue entirely\n if (batch.delete(requestCopy) && batch.size < 1) {\n this.consumeQueue(key);\n // If queue was in flight, cancel it\n batch.subscription?.unsubscribe();\n }\n }\n };\n });\n }\n\n return requestCopy.observable;\n }\n\n // Consumes the queue.\n // Returns a list of promises (one for each query).\n public consumeQueue(\n key: string = \"\"\n ): (Observable<FetchResult> | undefined)[] | undefined {\n const batch = this.batchesByKey.get(key);\n // Delete this batch and process it below.\n this.batchesByKey.delete(key);\n if (!batch || !batch.size) {\n // No requests to be processed.\n return;\n }\n\n const operations: QueuedRequest[\"operation\"][] = [];\n const forwards: QueuedRequest[\"forward\"][] = [];\n const observables: QueuedRequest[\"observable\"][] = [];\n const nexts: QueuedRequest[\"next\"][] = [];\n const errors: QueuedRequest[\"error\"][] = [];\n const completes: QueuedRequest[\"complete\"][] = [];\n\n // Even though batch is a Set, it preserves the order of first insertion\n // when iterating (per ECMAScript specification), so these requests will be\n // handled in the order they were enqueued (minus any deleted ones).\n batch.forEach((request) => {\n operations.push(request.operation);\n forwards.push(request.forward);\n observables.push(request.observable);\n nexts.push(request.next);\n errors.push(request.error);\n completes.push(request.complete);\n });\n\n const batchedObservable = this.batchHandler(operations, forwards) || EMPTY;\n\n const onError = (error: Error) => {\n //each callback list in batch\n errors.forEach((rejecters) => {\n if (rejecters) {\n //each subscriber to request\n rejecters.forEach((e) => e(error));\n }\n });\n };\n\n batch.subscription = batchedObservable.subscribe({\n next: (results) => {\n if (!Array.isArray(results)) {\n results = [results];\n }\n\n if (nexts.length !== results.length) {\n const error = new Error(\n `server returned results with length ${results.length}, expected length of ${nexts.length}`\n );\n (error as any).result = results;\n\n return onError(error);\n }\n\n results.forEach((result, index) => {\n if (nexts[index]) {\n nexts[index].forEach((next) => next(result));\n }\n });\n },\n error: onError,\n complete: () => {\n completes.forEach((complete) => {\n if (complete) {\n //each subscriber to request\n complete.forEach((c) => c());\n }\n });\n },\n });\n\n return observables;\n }\n\n private scheduleQueueConsumption(key: string): void {\n clearTimeout(this.scheduledBatchTimerByKey.get(key));\n this.scheduledBatchTimerByKey.set(\n key,\n setTimeout(() => {\n this.consumeQueue(key);\n this.scheduledBatchTimerByKey.delete(key);\n }, this.batchInterval)\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"batching.js","sourceRoot":"","sources":["../../../src/link/batch/batching.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAyBlC,q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AC,KAAK,CAAC,EAAE,CAAC;wBACjB,KAAK,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;oBAC/C,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YACD,KAAK,EAAE,OAAO;YACd,QAAQ,EAAE,GAAG,EAAE;gBACb,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;oBAC7B,IAAI,QAAQ,EAAE,CAAC;wBACb,4BAA4B;wBAC5B,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;oBAC/B,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;QAEH,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,wBAAwB,CAAC,GAAW;QAC1C,YAAY,CAAC,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACrD,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAC/B,GAAG,EACH,UAAU,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,CAAC,EAAE,IAAI,CAAC,aAAa,CAAC,CACvB,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { Observable } from \"rxjs\";\n\nimport type { ApolloLink } from \"@apollo/client/link\";\n\nimport type { BatchLink } from \"./batchLink.js\";\n\nexport interface BatchableRequest {\n operation: ApolloLink.Operation;\n forward: ApolloLink.ForwardFunction;\n}\n\ntype QueuedRequest = BatchableRequest & {\n observable?: Observable<ApolloLink.Result>;\n next: Array<(result: ApolloLink.Result) => void>;\n error: Array<(error: Error) => void>;\n complete: Array<() => void>;\n subscribers: Set<object>;\n};\n\n// Batches are primarily a Set<QueuedRequest>, but may have other optional\n// properties, such as batch.subscription.\ntype RequestBatch = Set<QueuedRequest> & {\n subscription?: Subscription;\n};\n\n// QueryBatcher doesn't fire requests immediately. Requests that were enqueued within\n// a certain amount of time (configurable through `batchInterval`) will be batched together\n// into one query.\nexport class OperationBatcher {\n // Queue on which the QueryBatcher will operate on a per-tick basis.\n private batchesByKey = new Map<string, RequestBatch>();\n\n private scheduledBatchTimerByKey = new Map<\n string,\n ReturnType<typeof setTimeout>\n >();\n private batchDebounce?: boolean;\n private batchInterval?: number;\n private batchMax: number;\n\n //This function is called to the queries in the queue to the server.\n private batchHandler: BatchLink.BatchHandler;\n private batchKey: (operation: ApolloLink.Operation) => string;\n\n constructor({\n batchDebounce,\n batchInterval,\n batchMax,\n batchHandler,\n batchKey,\n }: {\n batchDebounce?: boolean;\n batchInterval?: number;\n batchMax?: number;\n batchHandler: BatchLink.BatchHandler;\n batchKey?: (operation: ApolloLink.Operation) => string;\n }) {\n this.batchDebounce = batchDebounce;\n this.batchInterval = batchInterval;\n this.batchMax = batchMax || 0;\n this.batchHandler = batchHandler;\n this.batchKey = batchKey || (() => \"\");\n }\n\n public enqueueRequest(\n request: BatchableRequest\n ): Observable<ApolloLink.Result> {\n const requestCopy: QueuedRequest = {\n ...request,\n next: [],\n error: [],\n complete: [],\n subscribers: new Set(),\n };\n\n const key = this.batchKey(request.operation);\n\n if (!requestCopy.observable) {\n requestCopy.observable = new Observable<ApolloLink.Result>((observer) => {\n let batch = this.batchesByKey.get(key)!;\n if (!batch) this.batchesByKey.set(key, (batch = new Set()));\n\n // These booleans seem to me (@benjamn) like they might always be the\n // same (and thus we could do with only one of them), but I'm not 100%\n // sure about that.\n const isFirstEnqueuedRequest = batch.size === 0;\n const isFirstSubscriber = requestCopy.subscribers.size === 0;\n requestCopy.subscribers.add(observer);\n if (isFirstSubscriber) {\n batch.add(requestCopy);\n }\n\n // called for each subscriber, so need to save all listeners (next, error, complete)\n if (observer.next) {\n requestCopy.next.push(observer.next.bind(observer));\n }\n\n if (observer.error) {\n requestCopy.error.push(observer.error.bind(observer));\n }\n\n if (observer.complete) {\n requestCopy.complete.push(observer.complete.bind(observer));\n }\n\n // The first enqueued request triggers the queue consumption after `batchInterval` milliseconds.\n if (isFirstEnqueuedRequest || this.batchDebounce) {\n this.scheduleQueueConsumption(key);\n }\n\n // When amount of requests reaches `batchMax`, trigger the queue consumption without waiting on the `batchInterval`.\n if (batch.size === this.batchMax) {\n this.consumeQueue(key);\n }\n\n return () => {\n // If this is last subscriber for this request, remove request from queue\n if (\n requestCopy.subscribers.delete(observer) &&\n requestCopy.subscribers.size < 1\n ) {\n // If this is last request from queue, remove queue entirely\n if (batch.delete(requestCopy) && batch.size < 1) {\n this.consumeQueue(key);\n // If queue was in flight, cancel it\n batch.subscription?.unsubscribe();\n }\n }\n };\n });\n }\n\n return requestCopy.observable;\n }\n\n // Consumes the queue.\n // Returns a list of promises (one for each query).\n public consumeQueue(\n key: string = \"\"\n ): (Observable<ApolloLink.Result> | undefined)[] | undefined {\n const batch = this.batchesByKey.get(key);\n // Delete this batch and process it below.\n this.batchesByKey.delete(key);\n if (!batch || !batch.size) {\n // No requests to be processed.\n return;\n }\n\n const operations: QueuedRequest[\"operation\"][] = [];\n const forwards: QueuedRequest[\"forward\"][] = [];\n const observables: QueuedRequest[\"observable\"][] = [];\n const nexts: QueuedRequest[\"next\"][] = [];\n const errors: QueuedRequest[\"error\"][] = [];\n const completes: QueuedRequest[\"complete\"][] = [];\n\n // Even though batch is a Set, it preserves the order of first insertion\n // when iterating (per ECMAScript specification), so these requests will be\n // handled in the order they were enqueued (minus any deleted ones).\n batch.forEach((request) => {\n operations.push(request.operation);\n forwards.push(request.forward);\n observables.push(request.observable);\n nexts.push(request.next);\n errors.push(request.error);\n completes.push(request.complete);\n });\n\n const batchedObservable = this.batchHandler(operations, forwards);\n\n const onError = (error: Error) => {\n //each callback list in batch\n errors.forEach((rejecters) => {\n if (rejecters) {\n //each subscriber to request\n rejecters.forEach((e) => e(error));\n }\n });\n };\n\n batch.subscription = batchedObservable.subscribe({\n next: (results) => {\n if (!Array.isArray(results)) {\n results = [results];\n }\n\n if (nexts.length !== results.length) {\n const error = new Error(\n `server returned results with length ${results.length}, expected length of ${nexts.length}`\n );\n (error as any).result = results;\n\n return onError(error);\n }\n\n results.forEach((result, index) => {\n if (nexts[index]) {\n nexts[index].forEach((next) => next(result));\n }\n });\n },\n error: onError,\n complete: () => {\n completes.forEach((complete) => {\n if (complete) {\n //each subscriber to request\n complete.forEach((c) => c());\n }\n });\n },\n });\n\n return observables;\n }\n\n private scheduleQueueConsumption(key: string): void {\n clearTimeout(this.scheduledBatchTimerByKey.get(key));\n this.scheduledBatchTimerByKey.set(\n key,\n setTimeout(() => {\n this.consumeQueue(key);\n this.scheduledBatchTimerByKey.delete(key);\n }, this.batchInterval)\n );\n }\n}\n"]}
|
package/link/batch/index.d.ts
CHANGED
package/link/batch/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BatchLink
|
|
1
|
+
export { BatchLink } from "./batchLink.js";
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/link/batch/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/batch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC","sourcesContent":["export { BatchLink } from \"./batchLink.js\";\n"]}
|
|
@@ -1,16 +1,55 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
|
-
import type { FetchResult, Operation } from "@apollo/client/link";
|
|
3
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
4
3
|
import { BatchLink } from "@apollo/client/link/batch";
|
|
5
4
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
6
5
|
import type { HttpLink } from "@apollo/client/link/http";
|
|
7
6
|
export declare namespace BatchHttpLink {
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Options provided to the `BatchHttpLink` constructor.
|
|
9
|
+
*/
|
|
10
|
+
interface Options extends BatchLink.Shared.Options, HttpLink.Shared.Options {
|
|
11
|
+
/**
|
|
12
|
+
* The maximum number of operations to include in a single batch.
|
|
13
|
+
*
|
|
14
|
+
* @defaultValue 10
|
|
15
|
+
*/
|
|
16
|
+
batchMax?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options passed to `BatchHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
20
|
+
* non-terminating links in the link chain also can set these values to
|
|
21
|
+
* customize the behavior of `BatchHttpLink` for each operation.
|
|
22
|
+
*
|
|
23
|
+
* > [!NOTE]
|
|
24
|
+
* > Some of these values can also be provided to the `BatchHttpLink` constructor.
|
|
25
|
+
* > If a value is provided to both, the value in `context` takes precedence.
|
|
26
|
+
*/
|
|
27
|
+
interface ContextOptions extends HttpLink.ContextOptions {
|
|
28
|
+
}
|
|
10
29
|
}
|
|
11
30
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
31
|
+
* `BatchHttpLink` is a terminating link that batches array of individual
|
|
32
|
+
* GraphQL operations into a single HTTP request that's sent to a single GraphQL
|
|
33
|
+
* endpoint. It combines the functionality of `BaseBatchHttpLink` and
|
|
34
|
+
* `ClientAwarenessLink` into a single link.
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
*
|
|
38
|
+
* If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,
|
|
39
|
+
* Apollo Client automatically batches executed GraphQL operations and transmits
|
|
40
|
+
* them to your server according to the batching options you provide.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { BatchHttpLink } from "@apollo/client/link/batch-http";
|
|
46
|
+
*
|
|
47
|
+
* const link = new BatchHttpLink({
|
|
48
|
+
* uri: "http://localhost:4000/graphql",
|
|
49
|
+
* batchMax: 5, // No more than 5 operations per batch
|
|
50
|
+
* batchInterval: 20, // Wait no more than 20ms after first batched operation
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
14
53
|
*/
|
|
15
54
|
export declare class BatchHttpLink extends ApolloLink {
|
|
16
55
|
constructor(options?: BatchHttpLink.Options & ClientAwarenessLink.Options);
|
|
@@ -21,6 +60,6 @@ export declare class BaseBatchHttpLink extends ApolloLink {
|
|
|
21
60
|
private batchMax;
|
|
22
61
|
private batcher;
|
|
23
62
|
constructor(fetchParams?: BatchHttpLink.Options);
|
|
24
|
-
request(operation: Operation): Observable<
|
|
63
|
+
request(operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction): Observable<ApolloLink.Result>;
|
|
25
64
|
}
|
|
26
|
-
//# sourceMappingURL=batchHttpLink.d.ts.map
|
|
65
|
+
//# sourceMappingURL=batchHttpLink.d.ts.map
|
|
@@ -2,19 +2,42 @@ import { Observable, throwError } from "rxjs";
|
|
|
2
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
3
|
import { BatchLink } from "@apollo/client/link/batch";
|
|
4
4
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
5
|
-
import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI,
|
|
5
|
+
import { checkFetcher, defaultPrinter, fallbackHttpConfig, parseAndCheckHttpResponse, selectHttpOptionsAndBodyInternal, selectURI, } from "@apollo/client/link/http";
|
|
6
6
|
import { filterOperationVariables } from "@apollo/client/link/utils";
|
|
7
7
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
8
8
|
import { compact } from "@apollo/client/utilities/internal";
|
|
9
9
|
import { maybe } from "@apollo/client/utilities/internal/globals";
|
|
10
10
|
const backupFetch = maybe(() => fetch);
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
12
|
+
* `BatchHttpLink` is a terminating link that batches array of individual
|
|
13
|
+
* GraphQL operations into a single HTTP request that's sent to a single GraphQL
|
|
14
|
+
* endpoint. It combines the functionality of `BaseBatchHttpLink` and
|
|
15
|
+
* `ClientAwarenessLink` into a single link.
|
|
16
|
+
*
|
|
17
|
+
* @remarks
|
|
18
|
+
*
|
|
19
|
+
* If you use `BatchHttpLink` instead of `HttpLink` as your terminating link,
|
|
20
|
+
* Apollo Client automatically batches executed GraphQL operations and transmits
|
|
21
|
+
* them to your server according to the batching options you provide.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { BatchHttpLink } from "@apollo/client/link/batch-http";
|
|
27
|
+
*
|
|
28
|
+
* const link = new BatchHttpLink({
|
|
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
|
+
* ```
|
|
14
34
|
*/
|
|
15
35
|
export class BatchHttpLink extends ApolloLink {
|
|
16
36
|
constructor(options = {}) {
|
|
17
|
-
const { left, right, request } = ApolloLink.
|
|
37
|
+
const { left, right, request } = ApolloLink.from([
|
|
38
|
+
new ClientAwarenessLink(options),
|
|
39
|
+
new BaseBatchHttpLink(options),
|
|
40
|
+
]);
|
|
18
41
|
super(request);
|
|
19
42
|
Object.assign(this, { left, right });
|
|
20
43
|
}
|
|
@@ -67,7 +90,7 @@ export class BaseBatchHttpLink extends ApolloLink {
|
|
|
67
90
|
return throwError(() => new Error("apollo-link-batch-http does not support GET requests"));
|
|
68
91
|
}
|
|
69
92
|
try {
|
|
70
|
-
options.body =
|
|
93
|
+
options.body = JSON.stringify(loadedBody);
|
|
71
94
|
}
|
|
72
95
|
catch (parseError) {
|
|
73
96
|
return throwError(() => parseError);
|
|
@@ -132,8 +155,8 @@ export class BaseBatchHttpLink extends ApolloLink {
|
|
|
132
155
|
batchHandler,
|
|
133
156
|
});
|
|
134
157
|
}
|
|
135
|
-
request(operation) {
|
|
136
|
-
return this.batcher.request(operation);
|
|
158
|
+
request(operation, forward) {
|
|
159
|
+
return this.batcher.request(operation, forward);
|
|
137
160
|
}
|
|
138
161
|
}
|
|
139
162
|
//# sourceMappingURL=batchHttpLink.js.map
|