@apollo/client 4.0.0-rc.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2488 -0
- package/README.md +6 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs +2 -2
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.cjs +18 -12
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.cjs +1 -1
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +1 -1
- package/__cjs/core/QueryInfo.cjs +2 -6
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +1 -1
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +9 -6
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/incremental/handlers/notImplemented.d.cts +11 -0
- package/__cjs/link/batch/batchLink.cjs +30 -2
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +69 -2
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs +156 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.cjs.map +1 -0
- package/__cjs/link/batch-http/BaseBatchHttpLink.d.cts +68 -0
- package/__cjs/link/batch-http/batchHttpLink.cjs +3 -128
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +4 -20
- package/__cjs/link/batch-http/index.cjs +2 -1
- package/__cjs/link/batch-http/index.cjs.map +1 -1
- package/__cjs/link/batch-http/index.d.cts +2 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +3 -3
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +20 -1
- package/__cjs/link/context/index.cjs +19 -0
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +64 -2
- package/__cjs/link/core/ApolloLink.cjs.map +1 -1
- package/__cjs/link/core/ApolloLink.d.cts +5 -2
- package/__cjs/link/core/types.d.cts +0 -4
- package/__cjs/link/http/BaseHttpLink.cjs +59 -8
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/BaseHttpLink.d.cts +256 -2
- package/__cjs/link/http/HttpLink.cjs +1 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +5 -208
- package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
- package/__cjs/link/http/rewriteURIForGET.d.cts +2 -2
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +7 -7
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +2 -1
- package/__cjs/link/persisted-queries/index.cjs +16 -0
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +181 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs +48 -0
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +115 -0
- package/__cjs/link/retry/retryLink.cjs +25 -3
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +82 -9
- package/__cjs/link/schema/index.cjs +20 -0
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +128 -6
- package/__cjs/link/ws/index.cjs +18 -0
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +56 -5
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +10 -42
- package/__cjs/masking/PreserveTypes.cjs +3 -0
- package/__cjs/masking/PreserveTypes.cjs.map +1 -0
- package/__cjs/masking/PreserveTypes.d.cts +26 -0
- package/__cjs/masking/index.cjs.map +1 -1
- package/__cjs/masking/index.d.cts +1 -1
- package/__cjs/masking/internal/types.d.cts +0 -1
- package/__cjs/masking/types.d.cts +6 -23
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +2 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +2 -1
- package/__cjs/react/hooks/useQuery.d.cts +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +2 -1
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +2 -6
- package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +1 -1
- package/__cjs/react/types/deprecated.d.cts +1 -1
- package/__cjs/react/types/types.documentation.d.cts +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +1 -1
- package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
- package/__cjs/testing/react/MockedProvider.d.cts +5 -0
- package/__cjs/utilities/common/stripTypename.cjs +11 -0
- package/__cjs/utilities/common/stripTypename.cjs.map +1 -1
- package/__cjs/utilities/common/stripTypename.d.cts +11 -0
- package/__cjs/utilities/graphql/DocumentTransform.cjs +84 -1
- package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
- package/__cjs/utilities/graphql/DocumentTransform.d.cts +94 -5
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs +27 -0
- package/__cjs/utilities/graphql/isFormattedExecutionResult.cjs.map +1 -1
- package/__cjs/utilities/graphql/isFormattedExecutionResult.d.cts +27 -0
- package/__cjs/utilities/graphql/operations.cjs +54 -3
- package/__cjs/utilities/graphql/operations.cjs.map +1 -1
- package/__cjs/utilities/graphql/operations.d.cts +54 -3
- package/__cjs/utilities/graphql/storeUtils.cjs +9 -0
- package/__cjs/utilities/graphql/storeUtils.cjs.map +1 -1
- package/__cjs/utilities/graphql/storeUtils.d.cts +9 -0
- package/__cjs/utilities/graphql/transform.cjs +12 -1
- package/__cjs/utilities/graphql/transform.cjs.map +1 -1
- package/__cjs/utilities/graphql/transform.d.cts +12 -1
- package/__cjs/utilities/internal/canonicalStringify.cjs +30 -7
- package/__cjs/utilities/internal/canonicalStringify.cjs.map +1 -1
- package/__cjs/utilities/internal/canonicalStringify.d.cts +30 -7
- package/__cjs/utilities/internal/getMainDefinition.cjs +36 -8
- package/__cjs/utilities/internal/getMainDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getMainDefinition.d.cts +36 -8
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +2 -6
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/v4-migration.cjs +9 -0
- package/__cjs/v4-migration.cjs.map +1 -0
- package/__cjs/v4-migration.d.cts +826 -0
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/inmemory/inMemoryCache.js +2 -2
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/policies.js +18 -12
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/writeToStore.js +1 -1
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ObservableQuery.d.ts +1 -1
- package/core/ObservableQuery.js +1 -1
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.js +1 -2
- package/core/QueryInfo.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +9 -6
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/notImplemented.d.ts +11 -0
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/legacyEntryPoints/v4-migration/index.d.ts +1 -0
- package/legacyEntryPoints/v4-migration/index.js +1 -0
- package/legacyEntryPoints/v4-migration/v4-migration.cjs +1 -0
- package/legacyEntryPoints/v4-migration/v4-migration.d.cts +1 -0
- package/link/batch/batchLink.d.ts +69 -2
- package/link/batch/batchLink.js +30 -2
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch-http/BaseBatchHttpLink.d.ts +68 -0
- package/link/batch-http/BaseBatchHttpLink.js +152 -0
- package/link/batch-http/BaseBatchHttpLink.js.map +1 -0
- package/link/batch-http/batchHttpLink.d.ts +5 -21
- package/link/batch-http/batchHttpLink.js +1 -125
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/index.d.ts +2 -1
- package/link/batch-http/index.js +2 -1
- package/link/batch-http/index.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +21 -2
- package/link/client-awareness/ClientAwarenessLink.js +3 -3
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +65 -3
- package/link/context/index.js +19 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +5 -2
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/types.d.ts +0 -4
- package/link/core/types.js.map +1 -1
- package/link/http/BaseHttpLink.d.ts +257 -3
- package/link/http/BaseHttpLink.js +59 -8
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +6 -209
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +2 -2
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +7 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/index.d.ts +2 -1
- package/link/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +182 -1
- package/link/persisted-queries/index.js +16 -0
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +115 -0
- package/link/remove-typename/removeTypenameFromVariables.js +48 -0
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/retryLink.d.ts +83 -10
- package/link/retry/retryLink.js +25 -3
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +129 -7
- package/link/schema/index.js +20 -0
- package/link/schema/index.js.map +1 -1
- package/link/ws/index.d.ts +56 -5
- package/link/ws/index.js +18 -0
- package/link/ws/index.js.map +1 -1
- package/local-state/LocalState.js.map +1 -1
- package/masking/GraphQLCodegenDataMasking.d.ts +10 -42
- package/masking/GraphQLCodegenDataMasking.js.map +1 -1
- package/masking/PreserveTypes.d.ts +26 -0
- package/masking/PreserveTypes.js +2 -0
- package/masking/PreserveTypes.js.map +1 -0
- package/masking/index.d.ts +1 -1
- package/masking/index.js.map +1 -1
- package/masking/internal/types.d.ts +0 -1
- package/masking/internal/types.js.map +1 -1
- package/masking/types.d.ts +6 -23
- package/masking/types.js.map +1 -1
- package/package.json +8 -2
- package/react/hooks/useBackgroundQuery.d.ts +2 -1
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +1 -1
- package/react/hooks/useLoadableQuery.d.ts +2 -1
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useQuery.d.ts +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +2 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +1 -1
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +2 -1
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +2 -1
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +2 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +1 -1
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +1 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/deprecated.d.ts +1 -1
- package/react/types/deprecated.js.map +1 -1
- package/react/types/types.documentation.d.ts +1 -1
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/react/MockedProvider.d.ts +5 -0
- package/testing/react/MockedProvider.js.map +1 -1
- package/utilities/common/stripTypename.d.ts +11 -0
- package/utilities/common/stripTypename.js +11 -0
- package/utilities/common/stripTypename.js.map +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +94 -5
- package/utilities/graphql/DocumentTransform.js +84 -1
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/isFormattedExecutionResult.d.ts +27 -0
- package/utilities/graphql/isFormattedExecutionResult.js +27 -0
- package/utilities/graphql/isFormattedExecutionResult.js.map +1 -1
- package/utilities/graphql/operations.d.ts +54 -3
- package/utilities/graphql/operations.js +54 -3
- package/utilities/graphql/operations.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +9 -0
- package/utilities/graphql/storeUtils.js +9 -0
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts +12 -1
- package/utilities/graphql/transform.js +12 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/internal/canonicalStringify.d.ts +30 -7
- package/utilities/internal/canonicalStringify.js +30 -7
- package/utilities/internal/canonicalStringify.js.map +1 -1
- package/utilities/internal/getMainDefinition.d.ts +37 -9
- package/utilities/internal/getMainDefinition.js +36 -8
- package/utilities/internal/getMainDefinition.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.js +1 -2
- package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/v4-migration.d.ts +826 -0
- package/v4-migration.js +8 -0
- package/v4-migration.js.map +1 -0
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -1,6 +1,260 @@
|
|
|
1
|
+
import type { ASTNode, print } from "graphql";
|
|
1
2
|
import { ApolloLink } from "@apollo/client/link";
|
|
2
|
-
|
|
3
|
+
export declare namespace BaseHttpLink {
|
|
4
|
+
/**
|
|
5
|
+
* Options passed to `BaseHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
6
|
+
* non-terminating links in the link chain also can set these values to
|
|
7
|
+
* customize the behavior of `BaseHttpLink` for each operation.
|
|
8
|
+
*
|
|
9
|
+
* > [!NOTE]
|
|
10
|
+
* > Some of these values can also be provided to the `HttpLink` constructor.
|
|
11
|
+
* > If a value is provided to both, the value in `context` takes precedence.
|
|
12
|
+
*/
|
|
13
|
+
interface ContextOptions {
|
|
14
|
+
/**
|
|
15
|
+
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
16
|
+
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
17
|
+
* string URL to use for that operation.
|
|
18
|
+
*
|
|
19
|
+
* @defaultValue "/graphql"
|
|
20
|
+
*/
|
|
21
|
+
uri?: string | BaseHttpLink.UriFunction;
|
|
22
|
+
/**
|
|
23
|
+
* An object representing headers to include in every HTTP request.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
*
|
|
27
|
+
* ```json
|
|
28
|
+
* {
|
|
29
|
+
* "Authorization": "Bearer 1234"
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
/**
|
|
35
|
+
* The credentials policy to use for each `fetch` call.
|
|
36
|
+
*/
|
|
37
|
+
credentials?: RequestCredentials;
|
|
38
|
+
/**
|
|
39
|
+
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
40
|
+
*
|
|
41
|
+
* An object containing options to use for each call to `fetch`. If a
|
|
42
|
+
* particular option is not included in this object, the default value of
|
|
43
|
+
* that option is used.
|
|
44
|
+
*
|
|
45
|
+
* > [!NOTE]
|
|
46
|
+
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
47
|
+
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
48
|
+
*
|
|
49
|
+
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
50
|
+
*/
|
|
51
|
+
fetchOptions?: RequestInit;
|
|
52
|
+
/**
|
|
53
|
+
* An object that configures advanced functionality, such as support for
|
|
54
|
+
* persisted queries.
|
|
55
|
+
*/
|
|
56
|
+
http?: BaseHttpLink.HttpOptions;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options passed to `BaseHttpLink` through the `http` property of a request
|
|
60
|
+
* context.
|
|
61
|
+
*/
|
|
62
|
+
interface HttpOptions {
|
|
63
|
+
/**
|
|
64
|
+
* If `true`, includes the `extensions` field in operations sent to your
|
|
65
|
+
* GraphQL endpoint.
|
|
66
|
+
*
|
|
67
|
+
* @defaultValue true
|
|
68
|
+
*/
|
|
69
|
+
includeExtensions?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* If `false`, the GraphQL query string is not included in the request. Set
|
|
72
|
+
* this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).
|
|
73
|
+
*
|
|
74
|
+
* @defaultValue `true`
|
|
75
|
+
*/
|
|
76
|
+
includeQuery?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* If `true`, header names won't be automatically normalized to lowercase.
|
|
79
|
+
* This allows for non-http-spec-compliant servers that might expect
|
|
80
|
+
* capitalized header names.
|
|
81
|
+
*
|
|
82
|
+
* @defaultValue false
|
|
83
|
+
*/
|
|
84
|
+
preserveHeaderCase?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* A list of additional `accept` headers to include in the request,
|
|
87
|
+
* as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
*
|
|
91
|
+
* ```json
|
|
92
|
+
* ["application/custom+json;q=1.0"]
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
accept?: string[];
|
|
96
|
+
}
|
|
97
|
+
namespace Shared {
|
|
98
|
+
/** These options are shared between `BaseHttpLink` and `BaseBatchHttpLink` */
|
|
99
|
+
interface Options {
|
|
100
|
+
/**
|
|
101
|
+
* The URL of the GraphQL endpoint to send requests to. Can also be a
|
|
102
|
+
* function that accepts an `ApolloLink.Operation` object and returns the
|
|
103
|
+
* string URL to use for that operation.
|
|
104
|
+
*
|
|
105
|
+
* @defaultValue "/graphql"
|
|
106
|
+
*/
|
|
107
|
+
uri?: string | BaseHttpLink.UriFunction;
|
|
108
|
+
/**
|
|
109
|
+
* If `true`, includes the `extensions` field in operations sent to your
|
|
110
|
+
* GraphQL endpoint.
|
|
111
|
+
*
|
|
112
|
+
* @defaultValue true
|
|
113
|
+
*/
|
|
114
|
+
includeExtensions?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly
|
|
117
|
+
* when sending HTTP requests to your GraphQL endpoint. The function must
|
|
118
|
+
* conform to the signature of `fetch`.
|
|
119
|
+
*
|
|
120
|
+
* By default, the Fetch API is used unless it isn't available in your
|
|
121
|
+
* runtime environment.
|
|
122
|
+
*
|
|
123
|
+
* See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).
|
|
124
|
+
*/
|
|
125
|
+
fetch?: typeof fetch;
|
|
126
|
+
/**
|
|
127
|
+
* An object representing headers to include in every HTTP request.
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
*
|
|
131
|
+
* ```json
|
|
132
|
+
* {
|
|
133
|
+
* "Authorization": "Bearer 1234"
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
headers?: Record<string, string>;
|
|
138
|
+
/**
|
|
139
|
+
* If `true`, header names won't be automatically normalized to lowercase.
|
|
140
|
+
* This allows for non-http-spec-compliant servers that might expect
|
|
141
|
+
* capitalized header names.
|
|
142
|
+
*
|
|
143
|
+
* @defaultValue false
|
|
144
|
+
*/
|
|
145
|
+
preserveHeaderCase?: boolean;
|
|
146
|
+
/**
|
|
147
|
+
* The credentials policy to use for each `fetch` call.
|
|
148
|
+
*/
|
|
149
|
+
credentials?: RequestCredentials;
|
|
150
|
+
/**
|
|
151
|
+
* Any overrides of the fetch options argument to pass to the fetch call.
|
|
152
|
+
*
|
|
153
|
+
* An object containing options to use for each call to `fetch`. If a
|
|
154
|
+
* particular option is not included in this object, the default value of
|
|
155
|
+
* that option is used.
|
|
156
|
+
*
|
|
157
|
+
* > [!NOTE]
|
|
158
|
+
* > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard
|
|
159
|
+
* > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).
|
|
160
|
+
*
|
|
161
|
+
* See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
|
|
162
|
+
*/
|
|
163
|
+
fetchOptions?: RequestInit;
|
|
164
|
+
/**
|
|
165
|
+
* If `true`, unused variables from the operation will not be stripped from
|
|
166
|
+
* the request and will instead be sent to the GraphQL endpoint.
|
|
167
|
+
*
|
|
168
|
+
* @remarks
|
|
169
|
+
* Unused variables are likely to trigger server-side validation errors,
|
|
170
|
+
* per https://spec.graphql.org/draft/#sec-All-Variables-Used.
|
|
171
|
+
* `includeUnusedVariables` can be useful if your server deviates
|
|
172
|
+
* from the GraphQL specification by not strictly enforcing that rule.
|
|
173
|
+
*
|
|
174
|
+
* @defaultValue false
|
|
175
|
+
*/
|
|
176
|
+
includeUnusedVariables?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* A function to use when transforming a GraphQL document into a string. It
|
|
179
|
+
* accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`
|
|
180
|
+
* function as arguments, and is expected to return a string. This option
|
|
181
|
+
* enables you to, for example, use `stripIgnoredCharacters` to remove
|
|
182
|
+
* whitespace from queries.
|
|
183
|
+
*
|
|
184
|
+
* By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* import { stripIgnoredCharacters } from "graphql";
|
|
190
|
+
*
|
|
191
|
+
* const httpLink = new HttpLink({
|
|
192
|
+
* uri: "/graphql",
|
|
193
|
+
* print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),
|
|
194
|
+
* });
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
print?: BaseHttpLink.Printer;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Options provided to the `BaseHttpLink` constructor.
|
|
202
|
+
*
|
|
203
|
+
* > [!NOTE]
|
|
204
|
+
* > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).
|
|
205
|
+
* > Context options override the options passed to the constructor. Treat
|
|
206
|
+
* > these options as default values that are used when the request context
|
|
207
|
+
* > does not override the value.
|
|
208
|
+
*/
|
|
209
|
+
interface Options extends Shared.Options {
|
|
210
|
+
/**
|
|
211
|
+
* If `true`, the link uses an HTTP `GET` request when sending query
|
|
212
|
+
* operations to your GraphQL endpoint. Mutation operations continue to use
|
|
213
|
+
* `POST` requests. If you want all operations to use `GET` requests,
|
|
214
|
+
* set `fetchOptions.method` instead.
|
|
215
|
+
*
|
|
216
|
+
* @defaultValue false
|
|
217
|
+
*/
|
|
218
|
+
useGETForQueries?: boolean;
|
|
219
|
+
}
|
|
220
|
+
interface Body {
|
|
221
|
+
query?: string;
|
|
222
|
+
operationName?: string;
|
|
223
|
+
variables?: Record<string, any>;
|
|
224
|
+
extensions?: Record<string, any>;
|
|
225
|
+
}
|
|
226
|
+
type Printer = (node: ASTNode, originalPrint: typeof print) => string;
|
|
227
|
+
type UriFunction = (operation: ApolloLink.Operation) => string;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* `BaseHttpLink` is a terminating link that sends a GraphQL operation to a
|
|
231
|
+
* remote endpoint over HTTP. It serves as a base link to `HttpLink`.
|
|
232
|
+
*
|
|
233
|
+
* @remarks
|
|
234
|
+
*
|
|
235
|
+
* `BaseHttpLink` supports both POST and GET requests, and you can configure
|
|
236
|
+
* HTTP options on a per-operation basis. You can use these options for
|
|
237
|
+
* authentication, persisted queries, dynamic URIs, and other granular updates.
|
|
238
|
+
*
|
|
239
|
+
* > [!NOTE]
|
|
240
|
+
* > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you
|
|
241
|
+
* > need to disable client awareness features and would like to tree-shake
|
|
242
|
+
* > the implementation of `ClientAwarenessLink` out of your app bundle.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
*
|
|
246
|
+
* ```ts
|
|
247
|
+
* import { BaseHttpLink } from "@apollo/client/link/http";
|
|
248
|
+
*
|
|
249
|
+
* const link = new BaseHttpLink({
|
|
250
|
+
* uri: "http://localhost:4000/graphql",
|
|
251
|
+
* headers: {
|
|
252
|
+
* authorization: `Bearer ${token}`,
|
|
253
|
+
* },
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
3
257
|
export declare class BaseHttpLink extends ApolloLink {
|
|
4
|
-
constructor(
|
|
258
|
+
constructor(options?: BaseHttpLink.Options);
|
|
5
259
|
}
|
|
6
|
-
//# sourceMappingURL=BaseHttpLink.d.ts.map
|
|
260
|
+
//# sourceMappingURL=BaseHttpLink.d.ts.map
|
|
@@ -11,11 +11,40 @@ import { rewriteURIForGET } from "./rewriteURIForGET.js";
|
|
|
11
11
|
import { defaultPrinter, fallbackHttpConfig, selectHttpOptionsAndBodyInternal, } from "./selectHttpOptionsAndBody.js";
|
|
12
12
|
import { selectURI } from "./selectURI.js";
|
|
13
13
|
const backupFetch = maybe(() => fetch);
|
|
14
|
+
function noop() { }
|
|
15
|
+
/**
|
|
16
|
+
* `BaseHttpLink` is a terminating link that sends a GraphQL operation to a
|
|
17
|
+
* remote endpoint over HTTP. It serves as a base link to `HttpLink`.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
*
|
|
21
|
+
* `BaseHttpLink` supports both POST and GET requests, and you can configure
|
|
22
|
+
* HTTP options on a per-operation basis. You can use these options for
|
|
23
|
+
* authentication, persisted queries, dynamic URIs, and other granular updates.
|
|
24
|
+
*
|
|
25
|
+
* > [!NOTE]
|
|
26
|
+
* > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you
|
|
27
|
+
* > need to disable client awareness features and would like to tree-shake
|
|
28
|
+
* > the implementation of `ClientAwarenessLink` out of your app bundle.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { BaseHttpLink } from "@apollo/client/link/http";
|
|
34
|
+
*
|
|
35
|
+
* const link = new BaseHttpLink({
|
|
36
|
+
* uri: "http://localhost:4000/graphql",
|
|
37
|
+
* headers: {
|
|
38
|
+
* authorization: `Bearer ${token}`,
|
|
39
|
+
* },
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
14
43
|
export class BaseHttpLink extends ApolloLink {
|
|
15
|
-
constructor(
|
|
44
|
+
constructor(options = {}) {
|
|
16
45
|
let { uri = "/graphql",
|
|
17
46
|
// use default global fetch if nothing passed in
|
|
18
|
-
fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, useGETForQueries, includeUnusedVariables = false, ...requestOptions } =
|
|
47
|
+
fetch: preferredFetch, print = defaultPrinter, includeExtensions, preserveHeaderCase, useGETForQueries, includeUnusedVariables = false, ...requestOptions } = options;
|
|
19
48
|
if (__DEV__) {
|
|
20
49
|
// Make sure at least one of preferredFetch, window.fetch, or backupFetch is
|
|
21
50
|
// defined, so requests won't fail at runtime.
|
|
@@ -48,11 +77,33 @@ export class BaseHttpLink extends ApolloLink {
|
|
|
48
77
|
if (body.variables && !includeUnusedVariables) {
|
|
49
78
|
body.variables = filterOperationVariables(body.variables, operation.query);
|
|
50
79
|
}
|
|
51
|
-
let controller;
|
|
52
|
-
|
|
53
|
-
controller =
|
|
54
|
-
|
|
80
|
+
let controller = new AbortController();
|
|
81
|
+
let cleanupController = () => {
|
|
82
|
+
controller = undefined;
|
|
83
|
+
};
|
|
84
|
+
if (options.signal) {
|
|
85
|
+
const externalSignal = options.signal;
|
|
86
|
+
// in an ideal world we could use `AbortSignal.any` here, but
|
|
87
|
+
// React Native uses https://github.com/mysticatea/abort-controller as
|
|
88
|
+
// a polyfill for `AbortController`, and it does not support `AbortSignal.any`.
|
|
89
|
+
const listener = () => {
|
|
90
|
+
controller?.abort(externalSignal.reason);
|
|
91
|
+
};
|
|
92
|
+
externalSignal.addEventListener("abort", listener, { once: true });
|
|
93
|
+
cleanupController = () => {
|
|
94
|
+
controller?.signal.removeEventListener("abort", cleanupController);
|
|
95
|
+
controller = undefined;
|
|
96
|
+
// on cleanup, we need to stop listening to `options.signal` to avoid memory leaks
|
|
97
|
+
externalSignal.removeEventListener("abort", listener);
|
|
98
|
+
cleanupController = noop;
|
|
99
|
+
};
|
|
100
|
+
// react native also does not support the addEventListener `signal` option
|
|
101
|
+
// so we have to simulate that ourself
|
|
102
|
+
controller.signal.addEventListener("abort", cleanupController, {
|
|
103
|
+
once: true,
|
|
104
|
+
});
|
|
55
105
|
}
|
|
106
|
+
options.signal = controller.signal;
|
|
56
107
|
if (useGETForQueries && !isMutationOperation(operation.query)) {
|
|
57
108
|
options.method = "GET";
|
|
58
109
|
}
|
|
@@ -86,11 +137,11 @@ export class BaseHttpLink extends ApolloLink {
|
|
|
86
137
|
}
|
|
87
138
|
})
|
|
88
139
|
.then(() => {
|
|
89
|
-
|
|
140
|
+
cleanupController();
|
|
90
141
|
observer.complete();
|
|
91
142
|
})
|
|
92
143
|
.catch((err) => {
|
|
93
|
-
|
|
144
|
+
cleanupController();
|
|
94
145
|
observer.error(err);
|
|
95
146
|
});
|
|
96
147
|
return () => {
|
|
@@ -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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qC;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"]}
|
|
1
|
+
{"version":3,"file":"BaseHttpLink.js","sourceRoot":"","sources":["../../../src/link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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 type { ASTNode, print } from \"graphql\";\nimport { 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 {\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);\nfunction noop() {}\n\nexport declare namespace BaseHttpLink {\n /**\n * Options passed to `BaseHttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous\n * non-terminating links in the link chain also can set these values to\n * customize the behavior of `BaseHttpLink` for each operation.\n *\n * > [!NOTE]\n * > Some of these values can also be provided to the `HttpLink` constructor.\n * > If a value is provided to both, the value in `context` takes precedence.\n */\n interface ContextOptions {\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#uri:member} */\n uri?: string | BaseHttpLink.UriFunction;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#headers:member} */\n headers?: Record<string, string>;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#credentials:member} */\n credentials?: RequestCredentials;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#fetchOptions:member} */\n fetchOptions?: RequestInit;\n\n /**\n * An object that configures advanced functionality, such as support for\n * persisted queries.\n */\n http?: BaseHttpLink.HttpOptions;\n }\n\n /**\n * Options passed to `BaseHttpLink` through the `http` property of a request\n * context.\n */\n export interface HttpOptions {\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#includeExtensions:member} */\n includeExtensions?: boolean;\n\n /**\n * If `false`, the GraphQL query string is not included in the request. Set\n * this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).\n *\n * @defaultValue `true`\n */\n includeQuery?: boolean;\n\n /** {@inheritDoc @apollo/client/link/http!BaseHttpLink.Shared.Options#preserveHeaderCase:member} */\n preserveHeaderCase?: boolean;\n\n /**\n * A list of additional `accept` headers to include in the request,\n * as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2\n *\n * @example\n *\n * ```json\n * [\"application/custom+json;q=1.0\"]\n * ```\n */\n accept?: string[];\n }\n\n export namespace Shared {\n /** These options are shared between `BaseHttpLink` and `BaseBatchHttpLink` */\n export interface Options {\n /**\n * The URL of the GraphQL endpoint to send requests to. Can also be a\n * function that accepts an `ApolloLink.Operation` object and returns the\n * string URL to use for that operation.\n *\n * @defaultValue \"/graphql\"\n */\n uri?: string | BaseHttpLink.UriFunction;\n\n /**\n * If `true`, includes the `extensions` field in operations sent to your\n * GraphQL endpoint.\n *\n * @defaultValue true\n */\n includeExtensions?: boolean;\n\n /**\n * A function to use instead of calling the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) directly\n * when sending HTTP requests to your GraphQL endpoint. The function must\n * conform to the signature of `fetch`.\n *\n * By default, the Fetch API is used unless it isn't available in your\n * runtime environment.\n *\n * See [Customizing `fetch`](https://apollographql.com/docs/react/api/link/introduction#customizing-fetch).\n */\n fetch?: typeof fetch;\n\n /**\n * An object representing headers to include in every HTTP request.\n *\n * @example\n *\n * ```json\n * {\n * \"Authorization\": \"Bearer 1234\"\n * }\n * ```\n */\n headers?: Record<string, string>;\n\n /**\n * If `true`, header names won't be automatically normalized to lowercase.\n * This allows for non-http-spec-compliant servers that might expect\n * capitalized header names.\n *\n * @defaultValue false\n */\n preserveHeaderCase?: boolean;\n\n /**\n * The credentials policy to use for each `fetch` call.\n */\n credentials?: RequestCredentials;\n\n /**\n * Any overrides of the fetch options argument to pass to the fetch call.\n *\n * An object containing options to use for each call to `fetch`. If a\n * particular option is not included in this object, the default value of\n * that option is used.\n *\n * > [!NOTE]\n * > If you set `fetchOptions.method` to `GET`, `HttpLink` follows [standard\n * > GraphQL HTTP GET encoding](http://graphql.org/learn/serving-over-http/#get-request).\n *\n * See [available options](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)\n */\n fetchOptions?: RequestInit;\n\n /**\n * If `true`, unused variables from the operation will not be stripped from\n * the request and will instead be sent to the GraphQL endpoint.\n *\n * @remarks\n * Unused variables are likely to trigger server-side validation errors,\n * per https://spec.graphql.org/draft/#sec-All-Variables-Used.\n * `includeUnusedVariables` can be useful if your server deviates\n * from the GraphQL specification by not strictly enforcing that rule.\n *\n * @defaultValue false\n */\n includeUnusedVariables?: boolean;\n /**\n * A function to use when transforming a GraphQL document into a string. It\n * accepts an `ASTNode` (typically a `DocumentNode`) and the original `print`\n * function as arguments, and is expected to return a string. This option\n * enables you to, for example, use `stripIgnoredCharacters` to remove\n * whitespace from queries.\n *\n * By default the [GraphQL `print` function](https://graphql.org/graphql-js/language/#print) is used.\n *\n * @example\n *\n * ```ts\n * import { stripIgnoredCharacters } from \"graphql\";\n *\n * const httpLink = new HttpLink({\n * uri: \"/graphql\",\n * print: (ast, originalPrint) => stripIgnoredCharacters(originalPrint(ast)),\n * });\n * ```\n */\n print?: BaseHttpLink.Printer;\n }\n }\n\n /**\n * Options provided to the `BaseHttpLink` constructor.\n *\n * > [!NOTE]\n * > Some of these options are also available to override in [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context).\n * > Context options override the options passed to the constructor. Treat\n * > these options as default values that are used when the request context\n * > does not override the value.\n */\n interface Options extends Shared.Options {\n /**\n * If `true`, the link uses an HTTP `GET` request when sending query\n * operations to your GraphQL endpoint. Mutation operations continue to use\n * `POST` requests. If you want all operations to use `GET` requests,\n * set `fetchOptions.method` instead.\n *\n * @defaultValue false\n */\n useGETForQueries?: boolean;\n }\n\n interface Body {\n query?: string;\n operationName?: string;\n variables?: Record<string, any>;\n extensions?: Record<string, any>;\n }\n\n type Printer = (node: ASTNode, originalPrint: typeof print) => string;\n type UriFunction = (operation: ApolloLink.Operation) => string;\n}\n\n/**\n * `BaseHttpLink` is a terminating link that sends a GraphQL operation to a\n * remote endpoint over HTTP. It serves as a base link to `HttpLink`.\n *\n * @remarks\n *\n * `BaseHttpLink` supports both POST and GET requests, and you can configure\n * HTTP options on a per-operation basis. You can use these options for\n * authentication, persisted queries, dynamic URIs, and other granular updates.\n *\n * > [!NOTE]\n * > Prefer using `HttpLink` over `BaseHttpLink`. Use `BaseHttpLink` when you\n * > need to disable client awareness features and would like to tree-shake\n * > the implementation of `ClientAwarenessLink` out of your app bundle.\n *\n * @example\n *\n * ```ts\n * import { BaseHttpLink } from \"@apollo/client/link/http\";\n *\n * const link = new BaseHttpLink({\n * uri: \"http://localhost:4000/graphql\",\n * headers: {\n * authorization: `Bearer ${token}`,\n * },\n * });\n * ```\n */\nexport class BaseHttpLink extends ApolloLink {\n constructor(options: BaseHttpLink.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 } = options;\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 = new AbortController();\n let cleanupController = () => {\n controller = undefined;\n };\n if (options.signal) {\n const externalSignal: AbortSignal = options.signal;\n // in an ideal world we could use `AbortSignal.any` here, but\n // React Native uses https://github.com/mysticatea/abort-controller as\n // a polyfill for `AbortController`, and it does not support `AbortSignal.any`.\n\n const listener = () => {\n controller?.abort(externalSignal.reason);\n };\n externalSignal.addEventListener(\"abort\", listener, { once: true });\n cleanupController = () => {\n controller?.signal.removeEventListener(\"abort\", cleanupController);\n controller = undefined;\n // on cleanup, we need to stop listening to `options.signal` to avoid memory leaks\n externalSignal.removeEventListener(\"abort\", listener);\n cleanupController = noop;\n };\n // react native also does not support the addEventListener `signal` option\n // so we have to simulate that ourself\n controller.signal.addEventListener(\"abort\", cleanupController, {\n once: true,\n });\n }\n options.signal = controller.signal;\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 cleanupController();\n observer.complete();\n })\n .catch((err) => {\n cleanupController();\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,7 +1,6 @@
|
|
|
1
|
-
import type { ASTNode } from "graphql";
|
|
2
1
|
import { ApolloLink } from "@apollo/client/link";
|
|
3
2
|
import { ClientAwarenessLink } from "@apollo/client/link/client-awareness";
|
|
4
|
-
import
|
|
3
|
+
import { BaseHttpLink } from "./BaseHttpLink.js";
|
|
5
4
|
export declare namespace HttpLink {
|
|
6
5
|
/**
|
|
7
6
|
* Options passed to `HttpLink` through [request context](https://apollographql.com/docs/react/api/link/introduction#managing-context). Previous
|
|
@@ -12,192 +11,7 @@ export declare namespace HttpLink {
|
|
|
12
11
|
* > Some of these values can also be provided to the `HttpLink` constructor.
|
|
13
12
|
* > If a value is provided to both, the value in `context` takes precedence.
|
|
14
13
|
*/
|
|
15
|
-
interface ContextOptions {
|
|
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;
|
|
24
|
-
/**
|
|
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
|
-
*/
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
/**
|
|
37
|
-
* The credentials policy to use for each `fetch` call.
|
|
38
|
-
*/
|
|
39
|
-
credentials?: RequestCredentials;
|
|
40
|
-
/**
|
|
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
|
-
*/
|
|
53
|
-
fetchOptions?: RequestInit;
|
|
54
|
-
/**
|
|
55
|
-
* An object that configures advanced `HttpLink` functionality, such as
|
|
56
|
-
* support for persisted queries.
|
|
57
|
-
*/
|
|
58
|
-
http?: HttpLink.HttpOptions;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Options passed to `HttpLink` through the `http` property of a request
|
|
62
|
-
* context.
|
|
63
|
-
*/
|
|
64
|
-
interface HttpOptions {
|
|
65
|
-
/**
|
|
66
|
-
* If `true`, includes the `extensions` field in operations sent to your
|
|
67
|
-
* GraphQL endpoint.
|
|
68
|
-
*
|
|
69
|
-
* @defaultValue true
|
|
70
|
-
*/
|
|
71
|
-
includeExtensions?: boolean;
|
|
72
|
-
/**
|
|
73
|
-
* If `false`, the GraphQL query string is not included in the request. Set
|
|
74
|
-
* this option if you're sending a request that uses a [persisted query](https://www.apollographql.com/docs/react/api/link/persisted-queries/).
|
|
75
|
-
*
|
|
76
|
-
* @defaultValue true
|
|
77
|
-
*/
|
|
78
|
-
includeQuery?: boolean;
|
|
79
|
-
/**
|
|
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
|
-
*/
|
|
86
|
-
preserveHeaderCase?: boolean;
|
|
87
|
-
/**
|
|
88
|
-
* A list of additional `accept` headers to include in the request,
|
|
89
|
-
* as defined in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
|
|
90
|
-
*
|
|
91
|
-
* @example
|
|
92
|
-
*
|
|
93
|
-
* ```json
|
|
94
|
-
* ["application/custom+json;q=1.0"]
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
accept?: string[];
|
|
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
|
-
}
|
|
14
|
+
interface ContextOptions extends BaseHttpLink.ContextOptions, ClientAwarenessLink.ContextOptions {
|
|
201
15
|
}
|
|
202
16
|
/**
|
|
203
17
|
* Options provided to the `HttpLink` constructor.
|
|
@@ -208,25 +22,8 @@ export declare namespace HttpLink {
|
|
|
208
22
|
* > these options as default values that are used when the request context
|
|
209
23
|
* > does not override the value.
|
|
210
24
|
*/
|
|
211
|
-
interface Options extends
|
|
212
|
-
/**
|
|
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.
|
|
217
|
-
*
|
|
218
|
-
* @defaultValue false
|
|
219
|
-
*/
|
|
220
|
-
useGETForQueries?: boolean;
|
|
221
|
-
}
|
|
222
|
-
interface Body {
|
|
223
|
-
query?: string;
|
|
224
|
-
operationName?: string;
|
|
225
|
-
variables?: Record<string, any>;
|
|
226
|
-
extensions?: Record<string, any>;
|
|
25
|
+
interface Options extends BaseHttpLink.Options, ClientAwarenessLink.Options {
|
|
227
26
|
}
|
|
228
|
-
type Printer = (node: ASTNode, originalPrint: typeof print) => string;
|
|
229
|
-
type UriFunction = (operation: ApolloLink.Operation) => string;
|
|
230
27
|
}
|
|
231
28
|
/**
|
|
232
29
|
* `HttpLink` is a terminating link that sends a GraphQL operation to a remote
|
|
@@ -251,11 +48,11 @@ export declare namespace HttpLink {
|
|
|
251
48
|
* ```
|
|
252
49
|
*/
|
|
253
50
|
export declare class HttpLink extends ApolloLink {
|
|
254
|
-
constructor(options?: HttpLink.Options
|
|
51
|
+
constructor(options?: HttpLink.Options);
|
|
255
52
|
}
|
|
256
53
|
/**
|
|
257
54
|
* @deprecated
|
|
258
55
|
* Use `HttpLink` from `@apollo/client/link/http` instead.
|
|
259
56
|
*/
|
|
260
|
-
export declare const createHttpLink: (
|
|
261
|
-
//# sourceMappingURL=HttpLink.d.ts.map
|
|
57
|
+
export declare const createHttpLink: (options?: HttpLink.Options) => HttpLink;
|
|
58
|
+
//# sourceMappingURL=HttpLink.d.ts.map
|