@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
package/link/error/index.d.ts
CHANGED
|
@@ -1,14 +1,30 @@
|
|
|
1
1
|
import { Observable } from "rxjs";
|
|
2
2
|
import type { ErrorLike } from "@apollo/client";
|
|
3
|
-
import type { FetchResult, NextLink, Operation } from "@apollo/client/link";
|
|
4
3
|
import { ApolloLink } from "@apollo/client/link";
|
|
5
4
|
export declare namespace ErrorLink {
|
|
5
|
+
namespace ErrorLinkDocumentationTypes {
|
|
6
|
+
/**
|
|
7
|
+
* Callback that is called by `ErrorLink` when an error occurs from a
|
|
8
|
+
* downstream link in link chain.
|
|
9
|
+
*
|
|
10
|
+
* @param options - The options object provided by `ErrorLink` to the error
|
|
11
|
+
* handler when an error occurs.
|
|
12
|
+
*/
|
|
13
|
+
function ErrorHandler(options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;
|
|
14
|
+
}
|
|
6
15
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
16
|
+
* Callback that is called by `ErrorLink` when an error occurs from a
|
|
17
|
+
* downstream link in link chain.
|
|
18
|
+
*
|
|
19
|
+
* @param options - The options object provided by `ErrorLink` to the error
|
|
20
|
+
* handler when an error occurs.
|
|
21
|
+
*/
|
|
9
22
|
interface ErrorHandler {
|
|
10
|
-
(options: ErrorHandlerOptions): Observable<
|
|
23
|
+
(options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;
|
|
11
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* The object provided to the `ErrorHandler` callback function.
|
|
27
|
+
*/
|
|
12
28
|
interface ErrorHandlerOptions {
|
|
13
29
|
/**
|
|
14
30
|
* The error that occurred during the operation execution. This can be a
|
|
@@ -22,25 +38,68 @@ export declare namespace ErrorLink {
|
|
|
22
38
|
* The raw GraphQL result from the server (if available), which may include
|
|
23
39
|
* partial data alongside errors.
|
|
24
40
|
*/
|
|
25
|
-
result?:
|
|
41
|
+
result?: ApolloLink.Result;
|
|
26
42
|
/** The details of the GraphQL operation that produced an error. */
|
|
27
|
-
operation: Operation;
|
|
43
|
+
operation: ApolloLink.Operation;
|
|
28
44
|
/**
|
|
29
45
|
* A function that calls the next link in the link chain. Calling
|
|
30
46
|
* `return forward(operation)` in your `ErrorLink` callback
|
|
31
47
|
* [retries the operation](../../data/error-handling#retrying-operations), returning a new observable for the
|
|
32
48
|
* upstream link to subscribe to.
|
|
33
49
|
*/
|
|
34
|
-
forward:
|
|
50
|
+
forward: ApolloLink.ForwardFunction;
|
|
35
51
|
}
|
|
36
52
|
}
|
|
37
|
-
export import ErrorHandler = ErrorLink.ErrorHandler;
|
|
38
53
|
/**
|
|
39
54
|
* @deprecated
|
|
40
55
|
* Use `ErrorLink` from `@apollo/client/link/error` instead.
|
|
41
56
|
*/
|
|
42
|
-
export declare function onError(errorHandler: ErrorHandler): ErrorLink;
|
|
57
|
+
export declare function onError(errorHandler: ErrorLink.ErrorHandler): ErrorLink;
|
|
58
|
+
/**
|
|
59
|
+
* Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)
|
|
60
|
+
* occurs.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
*
|
|
64
|
+
* This link is used after the GraphQL operation completes and execution is
|
|
65
|
+
* moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should
|
|
66
|
+
* not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).
|
|
67
|
+
*
|
|
68
|
+
* For more information on the types of errors that might be encountered, see
|
|
69
|
+
* the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* ```ts
|
|
74
|
+
* import { ErrorLink } from "@apollo/client/link/error";
|
|
75
|
+
* import {
|
|
76
|
+
* CombinedGraphQLErrors,
|
|
77
|
+
* CombinedProtocolErrors,
|
|
78
|
+
* } from "@apollo/client/errors";
|
|
79
|
+
*
|
|
80
|
+
* // Log any GraphQL errors, protocol errors, or network error that occurred
|
|
81
|
+
* const errorLink = new ErrorLink(({ error, operation }) => {
|
|
82
|
+
* if (CombinedGraphQLErrors.is(error)) {
|
|
83
|
+
* error.errors.forEach(({ message, locations, path }) =>
|
|
84
|
+
* console.log(
|
|
85
|
+
* `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
|
|
86
|
+
* )
|
|
87
|
+
* );
|
|
88
|
+
* } else if (CombinedProtocolErrors.is(error)) {
|
|
89
|
+
* error.errors.forEach(({ message, extensions }) =>
|
|
90
|
+
* console.log(
|
|
91
|
+
* `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(
|
|
92
|
+
* extensions
|
|
93
|
+
* )}`
|
|
94
|
+
* )
|
|
95
|
+
* );
|
|
96
|
+
* } else {
|
|
97
|
+
* console.error(`[Network error]: ${error}`);
|
|
98
|
+
* }
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
43
102
|
export declare class ErrorLink extends ApolloLink {
|
|
44
103
|
constructor(errorHandler: ErrorLink.ErrorHandler);
|
|
45
104
|
}
|
|
46
|
-
//# sourceMappingURL=index.d.ts.map
|
|
105
|
+
//# sourceMappingURL=index.d.ts.map
|
package/link/error/index.js
CHANGED
|
@@ -8,6 +8,50 @@ import { ApolloLink } from "@apollo/client/link";
|
|
|
8
8
|
export function onError(errorHandler) {
|
|
9
9
|
return new ErrorLink(errorHandler);
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)
|
|
13
|
+
* occurs.
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
*
|
|
17
|
+
* This link is used after the GraphQL operation completes and execution is
|
|
18
|
+
* moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should
|
|
19
|
+
* not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).
|
|
20
|
+
*
|
|
21
|
+
* For more information on the types of errors that might be encountered, see
|
|
22
|
+
* the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { ErrorLink } from "@apollo/client/link/error";
|
|
28
|
+
* import {
|
|
29
|
+
* CombinedGraphQLErrors,
|
|
30
|
+
* CombinedProtocolErrors,
|
|
31
|
+
* } from "@apollo/client/errors";
|
|
32
|
+
*
|
|
33
|
+
* // Log any GraphQL errors, protocol errors, or network error that occurred
|
|
34
|
+
* const errorLink = new ErrorLink(({ error, operation }) => {
|
|
35
|
+
* if (CombinedGraphQLErrors.is(error)) {
|
|
36
|
+
* error.errors.forEach(({ message, locations, path }) =>
|
|
37
|
+
* console.log(
|
|
38
|
+
* `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
|
|
39
|
+
* )
|
|
40
|
+
* );
|
|
41
|
+
* } else if (CombinedProtocolErrors.is(error)) {
|
|
42
|
+
* error.errors.forEach(({ message, extensions }) =>
|
|
43
|
+
* console.log(
|
|
44
|
+
* `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(
|
|
45
|
+
* extensions
|
|
46
|
+
* )}`
|
|
47
|
+
* )
|
|
48
|
+
* );
|
|
49
|
+
* } else {
|
|
50
|
+
* console.error(`[Network error]: ${error}`);
|
|
51
|
+
* }
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
11
55
|
export class ErrorLink extends ApolloLink {
|
|
12
56
|
constructor(errorHandler) {
|
|
13
57
|
super((operation, forward) => {
|
package/link/error/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/link/error/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAG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,OAAO,GAAG,EAAE;oBACV,IAAI,GAAG;wBAAE,GAAG,CAAC,WAAW,EAAE,CAAC;oBAC3B,IAAI,UAAU;wBAAE,UAAU,CAAC,WAAW,EAAE,CAAC;gBAC3C,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type { Subscription } from \"rxjs\";\nimport { Observable } from \"rxjs\";\n\nimport type { ErrorLike } from \"@apollo/client\";\nimport {\n CombinedGraphQLErrors,\n graphQLResultHasProtocolErrors,\n PROTOCOL_ERRORS_SYMBOL,\n toErrorLike,\n} from \"@apollo/client/errors\";\nimport { ApolloLink } from \"@apollo/client/link\";\n\nexport declare namespace ErrorLink {\n // Using a different namespace name to avoid clash with\n // `ApolloLink.DocumentationTypes`\n export namespace ErrorLinkDocumentationTypes {\n /**\n * Callback that is called by `ErrorLink` when an error occurs from a\n * downstream link in link chain.\n *\n * @param options - The options object provided by `ErrorLink` to the error\n * handler when an error occurs.\n */\n export function ErrorHandler(\n options: ErrorHandlerOptions\n ): Observable<ApolloLink.Result> | void;\n }\n\n /** {@inheritDoc @apollo/client/link/error!ErrorLink.ErrorLinkDocumentationTypes.ErrorHandler:function(1)} */\n export interface ErrorHandler {\n (options: ErrorHandlerOptions): Observable<ApolloLink.Result> | void;\n }\n\n /**\n * The object provided to the `ErrorHandler` callback function.\n */\n export interface ErrorHandlerOptions {\n /**\n * The error that occurred during the operation execution. This can be a\n * `CombinedGraphQLErrors` instance (for GraphQL errors) or another error\n * type (for network errors).\n *\n * Use `CombinedGraphQLErrors.is(error)` to check if it's a GraphQL error with an `errors` array.\n */\n error: ErrorLike;\n /**\n * The raw GraphQL result from the server (if available), which may include\n * partial data alongside errors.\n */\n result?: ApolloLink.Result;\n\n /** The details of the GraphQL operation that produced an error. */\n operation: ApolloLink.Operation;\n\n /**\n * A function that calls the next link in the link chain. Calling\n * `return forward(operation)` in your `ErrorLink` callback\n * [retries the operation](../../data/error-handling#retrying-operations), returning a new observable for the\n * upstream link to subscribe to.\n */\n forward: ApolloLink.ForwardFunction;\n }\n}\n\n/**\n * @deprecated\n * Use `ErrorLink` from `@apollo/client/link/error` instead.\n */\nexport function onError(errorHandler: ErrorLink.ErrorHandler) {\n return new ErrorLink(errorHandler);\n}\n\n/**\n * Use the `ErrorLink` to perform custom logic when a [GraphQL or network error](https://apollographql.com/docs/react/data/error-handling)\n * occurs.\n *\n * @remarks\n *\n * This link is used after the GraphQL operation completes and execution is\n * moving back up your [link chain](https://apollographql.com/docs/react/introduction#handling-a-response). The `errorHandler` function should\n * not return a value unless you want to [retry the operation](https://apollographql.com/docs/react/data/error-handling#retrying-operations).\n *\n * For more information on the types of errors that might be encountered, see\n * the guide on [error handling](https://apollographql.com/docs/react/data/error-handling).\n *\n * @example\n *\n * ```ts\n * import { ErrorLink } from \"@apollo/client/link/error\";\n * import {\n * CombinedGraphQLErrors,\n * CombinedProtocolErrors,\n * } from \"@apollo/client/errors\";\n *\n * // Log any GraphQL errors, protocol errors, or network error that occurred\n * const errorLink = new ErrorLink(({ error, operation }) => {\n * if (CombinedGraphQLErrors.is(error)) {\n * error.errors.forEach(({ message, locations, path }) =>\n * console.log(\n * `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`\n * )\n * );\n * } else if (CombinedProtocolErrors.is(error)) {\n * error.errors.forEach(({ message, extensions }) =>\n * console.log(\n * `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(\n * extensions\n * )}`\n * )\n * );\n * } else {\n * console.error(`[Network error]: ${error}`);\n * }\n * });\n * ```\n */\nexport class ErrorLink extends ApolloLink {\n constructor(errorHandler: ErrorLink.ErrorHandler) {\n super((operation, forward) => {\n return new Observable((observer) => {\n let sub: Subscription | undefined;\n let retriedSub: Subscription | undefined;\n let retriedResult: ReturnType<ErrorLink.ErrorHandler>;\n\n try {\n sub = forward(operation).subscribe({\n next: (result) => {\n const handler =\n operation.client[\"queryManager\"].incrementalHandler;\n const errors =\n handler.isIncrementalResult(result) ?\n handler.extractErrors(result)\n : result.errors;\n if (errors) {\n retriedResult = errorHandler({\n error: new CombinedGraphQLErrors(result, errors),\n result,\n operation,\n forward,\n });\n } else if (graphQLResultHasProtocolErrors(result)) {\n retriedResult = errorHandler({\n error: result.extensions[PROTOCOL_ERRORS_SYMBOL],\n result,\n operation,\n forward,\n });\n }\n\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.next(result);\n }\n },\n error: (error) => {\n retriedResult = errorHandler({\n operation,\n error: toErrorLike(error),\n forward,\n });\n retriedSub = retriedResult?.subscribe(observer);\n\n if (!retriedSub) {\n observer.error(error);\n }\n },\n complete: () => {\n // disable the previous sub from calling complete on observable\n // if retry is in flight.\n if (!retriedResult) {\n observer.complete();\n }\n },\n });\n } catch (e) {\n errorHandler({ error: toErrorLike(e), operation, forward });\n observer.error(e);\n }\n\n return () => {\n if (sub) sub.unsubscribe();\n if (retriedSub) retriedSub.unsubscribe();\n };\n });\n });\n }\n}\n"]}
|
|
@@ -10,7 +10,6 @@ import { parseAndCheckHttpResponse, readMultipartBody, } from "./parseAndCheckHt
|
|
|
10
10
|
import { rewriteURIForGET } from "./rewriteURIForGET.js";
|
|
11
11
|
import { defaultPrinter, fallbackHttpConfig, selectHttpOptionsAndBodyInternal, } from "./selectHttpOptionsAndBody.js";
|
|
12
12
|
import { selectURI } from "./selectURI.js";
|
|
13
|
-
import { serializeFetchParameter } from "./serializeFetchParameter.js";
|
|
14
13
|
const backupFetch = maybe(() => fetch);
|
|
15
14
|
export class BaseHttpLink extends ApolloLink {
|
|
16
15
|
constructor(linkOptions = {}) {
|
|
@@ -31,7 +30,7 @@ export class BaseHttpLink extends ApolloLink {
|
|
|
31
30
|
super((operation) => {
|
|
32
31
|
let chosenURI = selectURI(operation, uri);
|
|
33
32
|
const context = operation.getContext();
|
|
34
|
-
const http =
|
|
33
|
+
const http = { ...context.http };
|
|
35
34
|
if (isSubscriptionOperation(operation.query)) {
|
|
36
35
|
http.accept = [
|
|
37
36
|
"multipart/mixed;boundary=graphql;subscriptionSpec=1.0",
|
|
@@ -39,7 +38,7 @@ export class BaseHttpLink extends ApolloLink {
|
|
|
39
38
|
];
|
|
40
39
|
}
|
|
41
40
|
const contextConfig = {
|
|
42
|
-
http
|
|
41
|
+
http,
|
|
43
42
|
options: context.fetchOptions,
|
|
44
43
|
credentials: context.credentials,
|
|
45
44
|
headers: context.headers,
|
|
@@ -66,7 +65,7 @@ export class BaseHttpLink extends ApolloLink {
|
|
|
66
65
|
chosenURI = newURI;
|
|
67
66
|
}
|
|
68
67
|
else {
|
|
69
|
-
options.body =
|
|
68
|
+
options.body = JSON.stringify(body);
|
|
70
69
|
}
|
|
71
70
|
// Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise
|
|
72
71
|
// fall back to the *current* global window.fetch function (see issue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseHttpLink.js","sourceRoot":"","sources":["../../../src/link/http/BaseHttpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EACL,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,gCAA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D,IAAI,KAAK,KAAK,IAAI,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;wBACvD,OAAO,iBAAiB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;oBACnD,CAAC;yBAAM,CAAC;wBACN,OAAO,yBAAyB,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CACxD,YAAY,CACb,CAAC;oBACJ,CAAC;gBACH,CAAC,CAAC;qBACD,IAAI,CAAC,GAAG,EAAE;oBACT,UAAU,GAAG,SAAS,CAAC;oBACvB,QAAQ,CAAC,QAAQ,EAAE,CAAC;gBACtB,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;oBACb,UAAU,GAAG,SAAS,CAAC;oBACvB,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACtB,CAAC,CAAC,CAAC;gBAEL,OAAO,GAAG,EAAE;oBACV,qCAAqC;oBACrC,oEAAoE;oBACpE,IAAI,UAAU;wBAAE,UAAU,CAAC,KAAK,EAAE,CAAC;gBACrC,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { Observable } from \"rxjs\";\n\nimport { ApolloLink } from \"@apollo/client/link\";\nimport { filterOperationVariables } from \"@apollo/client/link/utils\";\nimport {\n isMutationOperation,\n isSubscriptionOperation,\n} from \"@apollo/client/utilities\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport { compact } from \"@apollo/client/utilities/internal\";\nimport { maybe } from \"@apollo/client/utilities/internal/globals\";\n\nimport { checkFetcher } from \"./checkFetcher.js\";\nimport type { HttpLink } from \"./HttpLink.js\";\nimport {\n parseAndCheckHttpResponse,\n readMultipartBody,\n} from \"./parseAndCheckHttpResponse.js\";\nimport { rewriteURIForGET } from \"./rewriteURIForGET.js\";\nimport {\n defaultPrinter,\n fallbackHttpConfig,\n selectHttpOptionsAndBodyInternal,\n} from \"./selectHttpOptionsAndBody.js\";\nimport { selectURI } from \"./selectURI.js\";\n\nconst backupFetch = maybe(() => fetch);\n\nexport class BaseHttpLink extends ApolloLink {\n constructor(linkOptions: HttpLink.Options = {}) {\n let {\n uri = \"/graphql\",\n // use default global fetch if nothing passed in\n fetch: preferredFetch,\n print = defaultPrinter,\n includeExtensions,\n preserveHeaderCase,\n useGETForQueries,\n includeUnusedVariables = false,\n ...requestOptions\n } = linkOptions;\n\n if (__DEV__) {\n // Make sure at least one of preferredFetch, window.fetch, or backupFetch is\n // 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 super((operation) => {\n let chosenURI = selectURI(operation, uri);\n\n const context = operation.getContext();\n\n const http = { ...context.http };\n if (isSubscriptionOperation(operation.query)) {\n http.accept = [\n \"multipart/mixed;boundary=graphql;subscriptionSpec=1.0\",\n ...(http.accept || []),\n ];\n }\n\n const contextConfig = {\n 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 { options, body } = selectHttpOptionsAndBodyInternal(\n operation,\n print,\n fallbackHttpConfig,\n linkConfig,\n contextConfig\n );\n\n if (body.variables && !includeUnusedVariables) {\n body.variables = filterOperationVariables(\n body.variables,\n operation.query\n );\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 if (useGETForQueries && !isMutationOperation(operation.query)) {\n options.method = \"GET\";\n }\n\n return new Observable((observer) => {\n if (options.method === \"GET\") {\n const { newURI, parseError } = rewriteURIForGET(chosenURI, body);\n if (parseError) {\n throw parseError;\n }\n chosenURI = newURI;\n } else {\n options.body = JSON.stringify(body);\n }\n // Prefer linkOptions.fetch (preferredFetch) if provided, and otherwise\n // fall back to the *current* global window.fetch function (see issue\n // #7832), or (if all else fails) the backupFetch function we saved when\n // this module was first evaluated. This last option protects against the\n // removal of window.fetch, which is unlikely but not impossible.\n const currentFetch =\n preferredFetch || maybe(() => fetch) || backupFetch;\n\n const observerNext = observer.next.bind(observer);\n currentFetch!(chosenURI, options)\n .then((response) => {\n operation.setContext({ response });\n const ctype = response.headers?.get(\"content-type\");\n\n if (ctype !== null && /^multipart\\/mixed/i.test(ctype)) {\n return readMultipartBody(response, observerNext);\n } else {\n return parseAndCheckHttpResponse(operation)(response).then(\n observerNext\n );\n }\n })\n .then(() => {\n controller = undefined;\n observer.complete();\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}\n"]}
|
package/link/http/HttpLink.d.ts
CHANGED
|
@@ -1,37 +1,55 @@
|
|
|
1
1
|
import type { ASTNode } from "graphql";
|
|
2
|
-
import type { Operation } from "@apollo/client/link";
|
|
3
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
4
3
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
5
4
|
import type { print } from "@apollo/client/utilities";
|
|
6
5
|
export declare namespace HttpLink {
|
|
7
6
|
/**
|
|
8
|
-
* Options passed to `HttpLink` through request context.
|
|
7
|
+
* Options passed to `HttpLink` 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 `HttpLink` for each operation.
|
|
10
|
+
*
|
|
11
|
+
* > [!NOTE]
|
|
12
|
+
* > Some of these values can also be provided to the `HttpLink` constructor.
|
|
13
|
+
* > If a value is provided to both, the value in `context` takes precedence.
|
|
9
14
|
*/
|
|
10
15
|
interface ContextOptions {
|
|
11
16
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
18
|
+
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
19
|
+
* string URL to use for that operation.
|
|
20
|
+
*
|
|
21
|
+
* @defaultValue "/graphql"
|
|
22
|
+
*/
|
|
23
|
+
uri?: string | HttpLink.UriFunction;
|
|
17
24
|
/**
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
* An object representing headers to include in every HTTP request.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* ```json
|
|
30
|
+
* {
|
|
31
|
+
* "Authorization": "Bearer 1234"
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
21
35
|
headers?: Record<string, string>;
|
|
22
36
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
*/
|
|
37
|
+
* The credentials policy to use for each `fetch` call.
|
|
38
|
+
*/
|
|
26
39
|
credentials?: RequestCredentials;
|
|
27
40
|
/**
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
41
|
+
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
42
|
+
*
|
|
43
|
+
* An object containing options to use for each call to `fetch`. If a
|
|
44
|
+
* particular option is not included in this object, the default value of
|
|
45
|
+
* that option is used.
|
|
46
|
+
*
|
|
47
|
+
* > [!NOTE]
|
|
48
|
+
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
49
|
+
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
50
|
+
*
|
|
51
|
+
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
52
|
+
*/
|
|
35
53
|
fetchOptions?: RequestInit;
|
|
36
54
|
/**
|
|
37
55
|
* An object that configures advanced `HttpLink` functionality, such as
|
|
@@ -40,16 +58,16 @@ export declare namespace HttpLink {
|
|
|
40
58
|
http?: HttpLink.HttpOptions;
|
|
41
59
|
}
|
|
42
60
|
/**
|
|
43
|
-
* Options passed to `HttpLink` through the `http`
|
|
44
|
-
*
|
|
61
|
+
* Options passed to `HttpLink` through the `http` property of a request
|
|
62
|
+
* context.
|
|
45
63
|
*/
|
|
46
64
|
interface HttpOptions {
|
|
47
65
|
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
66
|
+
* If `true`, includes the `extensions` field in operations sent to your
|
|
67
|
+
* GraphQL endpoint.
|
|
68
|
+
*
|
|
69
|
+
* @defaultValue true
|
|
70
|
+
*/
|
|
53
71
|
includeExtensions?: boolean;
|
|
54
72
|
/**
|
|
55
73
|
* If `false`, the GraphQL query string is not included in the request. Set
|
|
@@ -59,17 +77,16 @@ export declare namespace HttpLink {
|
|
|
59
77
|
*/
|
|
60
78
|
includeQuery?: boolean;
|
|
61
79
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
* If `true`, header names won't be automatically normalized to lowercase.
|
|
81
|
+
* This allows for non-http-spec-compliant servers that might expect
|
|
82
|
+
* capitalized header names.
|
|
83
|
+
*
|
|
84
|
+
* @defaultValue false
|
|
85
|
+
*/
|
|
68
86
|
preserveHeaderCase?: boolean;
|
|
69
87
|
/**
|
|
70
88
|
* A list of additional `accept` headers to include in the request,
|
|
71
|
-
* as defined in
|
|
72
|
-
* https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
|
89
|
+
* as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
|
73
90
|
*
|
|
74
91
|
* @example
|
|
75
92
|
*
|
|
@@ -79,65 +96,128 @@ export declare namespace HttpLink {
|
|
|
79
96
|
*/
|
|
80
97
|
accept?: string[];
|
|
81
98
|
}
|
|
99
|
+
namespace Shared {
|
|
100
|
+
/** These options are shared between `HttpLink` and `BatchHttpLink` */
|
|
101
|
+
interface Options {
|
|
102
|
+
/**
|
|
103
|
+
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
104
|
+
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
105
|
+
* string URL to use for that operation.
|
|
106
|
+
*
|
|
107
|
+
* @defaultValue "/graphql"
|
|
108
|
+
*/
|
|
109
|
+
uri?: string | HttpLink.UriFunction;
|
|
110
|
+
/**
|
|
111
|
+
* If `true`, includes the `extensions` field in operations sent to your
|
|
112
|
+
* GraphQL endpoint.
|
|
113
|
+
*
|
|
114
|
+
* @defaultValue true
|
|
115
|
+
*/
|
|
116
|
+
includeExtensions?: boolean;
|
|
117
|
+
/**
|
|
118
|
+
* A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly
|
|
119
|
+
* when sending HTTP requests to your GraphQL endpoint. The function must
|
|
120
|
+
* conform to the signature of `fetch`.
|
|
121
|
+
*
|
|
122
|
+
* By default, the Fetch API is used unless it isn't available in your
|
|
123
|
+
* runtime environment.
|
|
124
|
+
*
|
|
125
|
+
* See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).
|
|
126
|
+
*/
|
|
127
|
+
fetch?: typeof fetch;
|
|
128
|
+
/**
|
|
129
|
+
* An object representing headers to include in every HTTP request.
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
*
|
|
133
|
+
* ```json
|
|
134
|
+
* {
|
|
135
|
+
* "Authorization": "Bearer 1234"
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
headers?: Record<string, string>;
|
|
140
|
+
/**
|
|
141
|
+
* If `true`, header names won't be automatically normalized to lowercase.
|
|
142
|
+
* This allows for non-http-spec-compliant servers that might expect
|
|
143
|
+
* capitalized header names.
|
|
144
|
+
*
|
|
145
|
+
* @defaultValue false
|
|
146
|
+
*/
|
|
147
|
+
preserveHeaderCase?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* The credentials policy to use for each `fetch` call.
|
|
150
|
+
*/
|
|
151
|
+
credentials?: RequestCredentials;
|
|
152
|
+
/**
|
|
153
|
+
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
154
|
+
*
|
|
155
|
+
* An object containing options to use for each call to `fetch`. If a
|
|
156
|
+
* particular option is not included in this object, the default value of
|
|
157
|
+
* that option is used.
|
|
158
|
+
*
|
|
159
|
+
* > [!NOTE]
|
|
160
|
+
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
161
|
+
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
162
|
+
*
|
|
163
|
+
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
164
|
+
*/
|
|
165
|
+
fetchOptions?: RequestInit;
|
|
166
|
+
/**
|
|
167
|
+
* If `true`, unused variables from the operation will not be stripped from
|
|
168
|
+
* the request and will instead be sent to the GraphQL endpoint.
|
|
169
|
+
*
|
|
170
|
+
* @remarks
|
|
171
|
+
* Unused variables are likely to trigger server-side validation errors,
|
|
172
|
+
* per https://spec.graphql.org/draft/#sec-All-Variables-Used.
|
|
173
|
+
* `includeUnusedVariables` can be useful if your server deviates
|
|
174
|
+
* from the GraphQL specification by not strictly enforcing that rule.
|
|
175
|
+
*
|
|
176
|
+
* @defaultValue false
|
|
177
|
+
*/
|
|
178
|
+
includeUnusedVariables?: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* A function to use when transforming a GraphQL document into a string. It
|
|
181
|
+
* accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`
|
|
182
|
+
* function as arguments, and is expected to return a string. This option
|
|
183
|
+
* enables you to, for example, use `stripIgnoredCharacters` to remove
|
|
184
|
+
* whitespace from queries.
|
|
185
|
+
*
|
|
186
|
+
* By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
*
|
|
190
|
+
* ```ts
|
|
191
|
+
* import { stripIgnoredCharacters } from "graphql";
|
|
192
|
+
*
|
|
193
|
+
* const httpLink = new HttpLink({
|
|
194
|
+
* uri: "/graphql",
|
|
195
|
+
* print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
print?: HttpLink.Printer;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
82
202
|
/**
|
|
83
|
-
* Options
|
|
203
|
+
* Options provided to the `HttpLink` constructor.
|
|
204
|
+
*
|
|
205
|
+
* > [!NOTE]
|
|
206
|
+
* > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
|
|
207
|
+
* > Context options override the options passed to the constructor. Treat
|
|
208
|
+
* > these options as default values that are used when the request context
|
|
209
|
+
* > does not override the value.
|
|
84
210
|
*/
|
|
85
|
-
interface Options {
|
|
86
|
-
/**
|
|
87
|
-
* The URI to use when fetching operations.
|
|
88
|
-
*
|
|
89
|
-
* Defaults to '/graphql'.
|
|
90
|
-
*/
|
|
91
|
-
uri?: string | UriFunction;
|
|
211
|
+
interface Options extends Shared.Options {
|
|
92
212
|
/**
|
|
93
|
-
*
|
|
213
|
+
* If `true`, the link uses an HTTP `GET` request when sending query
|
|
214
|
+
* operations to your GraphQL endpoint. Mutation operations continue to use
|
|
215
|
+
* `POST` requests. If you want all operations to use `GET` requests,
|
|
216
|
+
* set `fetchOptions.method` instead.
|
|
94
217
|
*
|
|
95
|
-
*
|
|
96
|
-
*/
|
|
97
|
-
includeExtensions?: boolean;
|
|
98
|
-
/**
|
|
99
|
-
* A `fetch`-compatible API to use when making requests.
|
|
100
|
-
*/
|
|
101
|
-
fetch?: typeof fetch;
|
|
102
|
-
/**
|
|
103
|
-
* An object representing values to be sent as headers on the request.
|
|
104
|
-
*/
|
|
105
|
-
headers?: Record<string, string>;
|
|
106
|
-
/**
|
|
107
|
-
* If set to true, header names won't be automatically normalized to
|
|
108
|
-
* lowercase. This allows for non-http-spec-compliant servers that might
|
|
109
|
-
* expect capitalized header names.
|
|
110
|
-
*/
|
|
111
|
-
preserveHeaderCase?: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* The credentials policy you want to use for the fetch call.
|
|
114
|
-
*/
|
|
115
|
-
credentials?: string;
|
|
116
|
-
/**
|
|
117
|
-
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
118
|
-
*/
|
|
119
|
-
fetchOptions?: any;
|
|
120
|
-
/**
|
|
121
|
-
* If set to true, use the HTTP GET method for query operations. Mutations
|
|
122
|
-
* will still use the method specified in fetchOptions.method (which defaults
|
|
123
|
-
* to POST).
|
|
218
|
+
* @defaultValue false
|
|
124
219
|
*/
|
|
125
220
|
useGETForQueries?: boolean;
|
|
126
|
-
/**
|
|
127
|
-
* If set to true, the default behavior of stripping unused variables
|
|
128
|
-
* from the request will be disabled.
|
|
129
|
-
*
|
|
130
|
-
* Unused variables are likely to trigger server-side validation errors,
|
|
131
|
-
* per https://spec.graphql.org/draft/#sec-All-Variables-Used, but this
|
|
132
|
-
* includeUnusedVariables option can be useful if your server deviates
|
|
133
|
-
* from the GraphQL specification by not strictly enforcing that rule.
|
|
134
|
-
*/
|
|
135
|
-
includeUnusedVariables?: boolean;
|
|
136
|
-
/**
|
|
137
|
-
* A function to substitute for the default query print function. Can be
|
|
138
|
-
* used to apply changes to the results of the print function.
|
|
139
|
-
*/
|
|
140
|
-
print?: Printer;
|
|
141
221
|
}
|
|
142
222
|
interface Body {
|
|
143
223
|
query?: string;
|
|
@@ -146,8 +226,30 @@ export declare namespace HttpLink {
|
|
|
146
226
|
extensions?: Record<string, any>;
|
|
147
227
|
}
|
|
148
228
|
type Printer = (node: ASTNode, originalPrint: typeof print) => string;
|
|
149
|
-
type UriFunction = (operation: Operation) => string;
|
|
229
|
+
type UriFunction = (operation: ApolloLink.Operation) => string;
|
|
150
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* `HttpLink` is a terminating link that sends a GraphQL operation to a remote
|
|
233
|
+
* endpoint over HTTP. It combines the functionality of `BaseHttpLink` and
|
|
234
|
+
* `ClientAwarenessLink` into a single link.
|
|
235
|
+
*
|
|
236
|
+
* @remarks
|
|
237
|
+
*
|
|
238
|
+
* `HttpLink` supports both POST and GET requests, and you can configure HTTP
|
|
239
|
+
* options on a per-operation basis. You can use these options for
|
|
240
|
+
* authentication, persisted queries, dynamic URIs, and other granular updates.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* import { HttpLink } from "@apollo/client";
|
|
246
|
+
*
|
|
247
|
+
* const link = new HttpLink({
|
|
248
|
+
* uri: "http://localhost:4000/graphql",
|
|
249
|
+
* // Additional options
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
151
253
|
export declare class HttpLink extends ApolloLink {
|
|
152
254
|
constructor(options?: HttpLink.Options & ClientAwarenessLink.Options);
|
|
153
255
|
}
|
|
@@ -156,4 +258,4 @@ export declare class HttpLink extends ApolloLink {
|
|
|
156
258
|
* Use `HttpLink` from `@apollo/client/link/http` instead.
|
|
157
259
|
*/
|
|
158
260
|
export declare const createHttpLink: (linkOptions?: HttpLink.Options & ClientAwarenessLink.Options) => HttpLink;
|
|
159
|
-
//# sourceMappingURL=HttpLink.d.ts.map
|
|
261
|
+
//# sourceMappingURL=HttpLink.d.ts.map
|
package/link/http/HttpLink.js
CHANGED
|
@@ -1,9 +1,34 @@
|
|
|
1
1
|
import { ApolloLink } from "@apollo/client/link";
|
|
2
2
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
3
3
|
import { BaseHttpLink } from "./BaseHttpLink.js";
|
|
4
|
+
/**
|
|
5
|
+
* `HttpLink` is a terminating link that sends a GraphQL operation to a remote
|
|
6
|
+
* endpoint over HTTP. It combines the functionality of `BaseHttpLink` and
|
|
7
|
+
* `ClientAwarenessLink` into a single link.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
*
|
|
11
|
+
* `HttpLink` supports both POST and GET requests, and you can configure HTTP
|
|
12
|
+
* options on a per-operation basis. You can use these options for
|
|
13
|
+
* authentication, persisted queries, dynamic URIs, and other granular updates.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { HttpLink } from "@apollo/client";
|
|
19
|
+
*
|
|
20
|
+
* const link = new HttpLink({
|
|
21
|
+
* uri: "http://localhost:4000/graphql",
|
|
22
|
+
* // Additional options
|
|
23
|
+
* });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
4
26
|
export class HttpLink extends ApolloLink {
|
|
5
27
|
constructor(options = {}) {
|
|
6
|
-
const { left, right, request } = ApolloLink.
|
|
28
|
+
const { left, right, request } = ApolloLink.from([
|
|
29
|
+
new ClientAwarenessLink(options),
|
|
30
|
+
new BaseHttpLink(options),
|
|
31
|
+
]);
|
|
7
32
|
super(request);
|
|
8
33
|
Object.assign(this, { left, right });
|
|
9
34
|
}
|