@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
|
@@ -8,19 +8,24 @@ type MakeRequiredVariablesOptional<TVariables extends OperationVariables, TConfi
|
|
|
8
8
|
export declare namespace useMutation {
|
|
9
9
|
interface Options<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache, TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>> {
|
|
10
10
|
/**
|
|
11
|
-
* By providing either an object or a callback function that, when invoked after
|
|
11
|
+
* By providing either an object or a callback function that, when invoked after
|
|
12
|
+
* a mutation, allows you to return optimistic data and optionally skip updates
|
|
13
|
+
* via the `IGNORE` sentinel object, Apollo Client caches this temporary
|
|
14
|
+
* (and potentially incorrect) response until the mutation completes, enabling
|
|
15
|
+
* more responsive UI updates.
|
|
12
16
|
*
|
|
13
17
|
* For more information, see [Optimistic mutation results](https://www.apollographql.com/docs/react/performance/optimistic-ui/).
|
|
14
18
|
*
|
|
15
|
-
* @docGroup
|
|
16
|
-
*
|
|
17
|
-
* 3. Caching options
|
|
19
|
+
* @docGroup 3. Caching options
|
|
18
20
|
*/
|
|
19
21
|
optimisticResponse?: Unmasked<NoInfer<TData>> | ((vars: TVariables, { IGNORE }: {
|
|
20
22
|
IGNORE: IgnoreModifier;
|
|
21
23
|
}) => Unmasked<NoInfer<TData>> | IgnoreModifier);
|
|
22
24
|
/**
|
|
23
|
-
* A `MutationQueryReducersMap`, which is map from query names to
|
|
25
|
+
* A `MutationQueryReducersMap`, which is map from query names to
|
|
26
|
+
* mutation query reducers. Briefly, this map defines how to incorporate the
|
|
27
|
+
* results of the mutation into the results of queries that are currently
|
|
28
|
+
* being watched by your application.
|
|
24
29
|
*/
|
|
25
30
|
updateQueries?: MutationQueryReducersMap<TData>;
|
|
26
31
|
/**
|
|
@@ -32,9 +37,7 @@ export declare namespace useMutation {
|
|
|
32
37
|
*
|
|
33
38
|
* - A string indicating the operation name of the query to refetch
|
|
34
39
|
*
|
|
35
|
-
* @docGroup
|
|
36
|
-
*
|
|
37
|
-
* 1. Operation options
|
|
40
|
+
* @docGroup 1. Operation options
|
|
38
41
|
*/
|
|
39
42
|
refetchQueries?: ((result: NormalizedExecutionResult<Unmasked<TData>>) => InternalRefetchQueriesInclude) | InternalRefetchQueriesInclude;
|
|
40
43
|
/**
|
|
@@ -42,9 +45,7 @@ export declare namespace useMutation {
|
|
|
42
45
|
*
|
|
43
46
|
* The default value is `false` (queries are refetched asynchronously).
|
|
44
47
|
*
|
|
45
|
-
* @docGroup
|
|
46
|
-
*
|
|
47
|
-
* 1. Operation options
|
|
48
|
+
* @docGroup 1. Operation options
|
|
48
49
|
*/
|
|
49
50
|
awaitRefetchQueries?: boolean;
|
|
50
51
|
/**
|
|
@@ -52,9 +53,7 @@ export declare namespace useMutation {
|
|
|
52
53
|
*
|
|
53
54
|
* For more information, see [Updating the cache after a mutation](https://www.apollographql.com/docs/react/data/mutations#updating-the-cache-after-a-mutation).
|
|
54
55
|
*
|
|
55
|
-
* @docGroup
|
|
56
|
-
*
|
|
57
|
-
* 3. Caching options
|
|
56
|
+
* @docGroup 3. Caching options
|
|
58
57
|
*/
|
|
59
58
|
update?: MutationUpdaterFunction<TData, TVariables, TCache>;
|
|
60
59
|
/**
|
|
@@ -62,9 +61,7 @@ export declare namespace useMutation {
|
|
|
62
61
|
*
|
|
63
62
|
* Returning a `Promise` from `onQueryUpdated` will cause the final mutation `Promise` to await the returned `Promise`. Returning `false` causes the query to be ignored.
|
|
64
63
|
*
|
|
65
|
-
* @docGroup
|
|
66
|
-
*
|
|
67
|
-
* 1. Operation options
|
|
64
|
+
* @docGroup 1. Operation options
|
|
68
65
|
*/
|
|
69
66
|
onQueryUpdated?: OnQueryUpdated<any>;
|
|
70
67
|
/**
|
|
@@ -74,9 +71,7 @@ export declare namespace useMutation {
|
|
|
74
71
|
*
|
|
75
72
|
* The default value is `none`, meaning that the mutation result includes error details but _not_ partial results.
|
|
76
73
|
*
|
|
77
|
-
* @docGroup
|
|
78
|
-
*
|
|
79
|
-
* 1. Operation options
|
|
74
|
+
* @docGroup 1. Operation options
|
|
80
75
|
*/
|
|
81
76
|
errorPolicy?: ErrorPolicy;
|
|
82
77
|
/**
|
|
@@ -84,17 +79,13 @@ export declare namespace useMutation {
|
|
|
84
79
|
*
|
|
85
80
|
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
|
86
81
|
*
|
|
87
|
-
* @docGroup
|
|
88
|
-
*
|
|
89
|
-
* 1. Operation options
|
|
82
|
+
* @docGroup 1. Operation options
|
|
90
83
|
*/
|
|
91
84
|
variables?: TConfiguredVariables;
|
|
92
85
|
/**
|
|
93
86
|
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
94
87
|
*
|
|
95
|
-
* @docGroup
|
|
96
|
-
*
|
|
97
|
-
* 2. Networking options
|
|
88
|
+
* @docGroup 2. Networking options
|
|
98
89
|
*/
|
|
99
90
|
context?: DefaultContext;
|
|
100
91
|
/**
|
|
@@ -104,13 +95,17 @@ export declare namespace useMutation {
|
|
|
104
95
|
*
|
|
105
96
|
* Unlike queries, mutations _do not_ support [fetch policies](https://www.apollographql.com/docs/react/data/queries/#setting-a-fetch-policy) besides `network-only` and `no-cache`.
|
|
106
97
|
*
|
|
107
|
-
* @docGroup
|
|
108
|
-
*
|
|
109
|
-
* 3. Caching options
|
|
98
|
+
* @docGroup 3. Caching options
|
|
110
99
|
*/
|
|
111
100
|
fetchPolicy?: MutationFetchPolicy;
|
|
112
101
|
/**
|
|
113
|
-
* To avoid retaining sensitive information from mutation root field
|
|
102
|
+
* To avoid retaining sensitive information from mutation root field
|
|
103
|
+
* arguments, Apollo Client v3.4+ automatically clears any `ROOT_MUTATION`
|
|
104
|
+
* fields from the cache after each mutation finishes. If you need this
|
|
105
|
+
* information to remain in the cache, you can prevent the removal by passing
|
|
106
|
+
* `keepRootFields: true` to the mutation. `ROOT_MUTATION` result data are
|
|
107
|
+
* also passed to the mutation `update` function, so we recommend obtaining
|
|
108
|
+
* the results that way, rather than using this option, if possible.
|
|
114
109
|
*/
|
|
115
110
|
keepRootFields?: boolean;
|
|
116
111
|
/**
|
|
@@ -118,9 +113,7 @@ export declare namespace useMutation {
|
|
|
118
113
|
*
|
|
119
114
|
* By default, the instance that's passed down via context is used, but you can provide a different instance here.
|
|
120
115
|
*
|
|
121
|
-
* @docGroup
|
|
122
|
-
*
|
|
123
|
-
* 2. Networking options
|
|
116
|
+
* @docGroup 2. Networking options
|
|
124
117
|
*/
|
|
125
118
|
client?: ApolloClient;
|
|
126
119
|
/**
|
|
@@ -128,9 +121,7 @@ export declare namespace useMutation {
|
|
|
128
121
|
*
|
|
129
122
|
* The default value is `true`.
|
|
130
123
|
*
|
|
131
|
-
* @docGroup
|
|
132
|
-
*
|
|
133
|
-
* 2. Networking options
|
|
124
|
+
* @docGroup 2. Networking options
|
|
134
125
|
*/
|
|
135
126
|
notifyOnNetworkStatusChange?: boolean;
|
|
136
127
|
/**
|
|
@@ -138,9 +129,7 @@ export declare namespace useMutation {
|
|
|
138
129
|
*
|
|
139
130
|
* This function is passed the mutation's result `data` and any options passed to the mutation.
|
|
140
131
|
*
|
|
141
|
-
* @docGroup
|
|
142
|
-
*
|
|
143
|
-
* 1. Operation options
|
|
132
|
+
* @docGroup 1. Operation options
|
|
144
133
|
*/
|
|
145
134
|
onCompleted?: (data: MaybeMasked<TData>, clientOptions?: Options<TData, TVariables, TCache>) => void;
|
|
146
135
|
/**
|
|
@@ -148,9 +137,7 @@ export declare namespace useMutation {
|
|
|
148
137
|
*
|
|
149
138
|
* This function is passed an [`ApolloError`](https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/errors/index.ts#L36-L39) object that contains either a `networkError` object or a `graphQLErrors` array, depending on the error(s) that occurred, as well as any options passed the mutation.
|
|
150
139
|
*
|
|
151
|
-
* @docGroup
|
|
152
|
-
*
|
|
153
|
-
* 1. Operation options
|
|
140
|
+
* @docGroup 1. Operation options
|
|
154
141
|
*/
|
|
155
142
|
onError?: (error: ErrorLike, clientOptions?: Options<TData, TVariables, TCache>) => void;
|
|
156
143
|
}
|
|
@@ -195,9 +182,7 @@ export declare namespace useMutation {
|
|
|
195
182
|
*
|
|
196
183
|
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
|
197
184
|
*
|
|
198
|
-
* @docGroup
|
|
199
|
-
*
|
|
200
|
-
* 1. Operation options
|
|
185
|
+
* @docGroup 1. Operation options
|
|
201
186
|
*/
|
|
202
187
|
variables?: TVariables;
|
|
203
188
|
}
|
|
@@ -208,9 +193,7 @@ export declare namespace useMutation {
|
|
|
208
193
|
*
|
|
209
194
|
* Each key in the object corresponds to a variable name, and that key's value corresponds to the variable value.
|
|
210
195
|
*
|
|
211
|
-
* @docGroup
|
|
212
|
-
*
|
|
213
|
-
* 1. Operation options
|
|
196
|
+
* @docGroup 1. Operation options
|
|
214
197
|
*/
|
|
215
198
|
variables: TVariables;
|
|
216
199
|
}
|
|
@@ -220,13 +203,8 @@ export declare namespace useMutation {
|
|
|
220
203
|
/**
|
|
221
204
|
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
222
205
|
*
|
|
223
|
-
* @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
|
|
224
|
-
*
|
|
225
|
-
* @param options - Options to control how the mutation is executed.
|
|
226
|
-
*
|
|
227
|
-
* @returns A tuple in the form of `[mutate, result]`
|
|
228
|
-
*
|
|
229
206
|
* @example
|
|
207
|
+
*
|
|
230
208
|
* ```jsx
|
|
231
209
|
* import { gql, useMutation } from "@apollo/client";
|
|
232
210
|
*
|
|
@@ -263,6 +241,10 @@ export declare namespace useMutation {
|
|
|
263
241
|
* );
|
|
264
242
|
* }
|
|
265
243
|
* ```
|
|
244
|
+
*
|
|
245
|
+
* @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
|
|
246
|
+
* @param options - Options to control how the mutation is executed.
|
|
247
|
+
* @returns A tuple in the form of `[mutate, result]`
|
|
266
248
|
*/
|
|
267
249
|
function useMutation<TData = unknown, TVariables extends OperationVariables = OperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useMutation.Options<TData, TVariables>): useMutation.ResultTuple<TData, TVariables>;
|
|
268
250
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAmJvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OASC;IAMD,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAExC,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAErC,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;QACvB,MAAM;QACN,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;QACf,MAAM;QACN,QAAQ;QACR,OAAO;KACR,CAAC,CAAC;IAEH,yBAAyB,CAAC,GAAG,EAAE;QAC7B,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC5D,CAAC,CAAC,CAA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QACd,CAAC,CACF,CAAC;IACN,CAAC,EACD,EAAE,CACH,CAAC;IAEF,MAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QACnC,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YACvD,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;YACtD,SAAS,CAAC,MAAM,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACnB,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAEzB,OAAO,GAAG,EAAE;YACV,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAc,EAAE,EAAE,KAAK,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAoB;IAC/C,OAAO;QACL,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type { NoInfer, Prettify } from \"@apollo/client/utilities/internal\";\nimport { mergeOptions } from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export interface Result<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache>,\n result: Result<TData>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache>;\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client!useMutation:function(1)} */\n export function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<TData, TVariables>\n ): useMutation.ResultTuple<TData, TVariables>;\n }\n}\n\n/**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\nexport function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions as any);\n\n return client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<TData, OperationVariables>\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n}\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAqB/B,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAmJvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OASC;IAMD,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,KAAK,CAAC,QAAQ,CAExC,GAAG,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;I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O,EAAE,KAAK;QACd,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type { NoInfer, Prettify } from \"@apollo/client/utilities/internal\";\nimport { mergeOptions } from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export interface Result<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache>,\n result: Result<TData>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache>;\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useMutation:function(1)} */\n export function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<TData, TVariables>\n ): useMutation.ResultTuple<TData, TVariables>;\n }\n}\n\n/**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\nexport function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions as any);\n\n return client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<TData, OperationVariables>\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n}\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"]}
|
|
@@ -12,33 +12,30 @@ export declare namespace useQuery {
|
|
|
12
12
|
*
|
|
13
13
|
* The default value is `cache-first`.
|
|
14
14
|
*
|
|
15
|
-
* @docGroup
|
|
16
|
-
*
|
|
17
|
-
* 3. Caching options
|
|
15
|
+
* @docGroup 3. Caching options
|
|
18
16
|
*/
|
|
19
17
|
fetchPolicy?: WatchQueryFetchPolicy;
|
|
20
18
|
/**
|
|
21
19
|
* Specifies the `FetchPolicy` to be used after this query has completed.
|
|
22
20
|
*
|
|
23
|
-
* @docGroup
|
|
24
|
-
*
|
|
25
|
-
* 3. Caching options
|
|
21
|
+
* @docGroup 3. Caching options
|
|
26
22
|
*/
|
|
27
23
|
nextFetchPolicy?: WatchQueryFetchPolicy | ((this: ApolloClient.WatchQueryOptions<TData, TVariables>, currentFetchPolicy: WatchQueryFetchPolicy, context: InternalTypes.NextFetchPolicyContext<TData, TVariables>) => WatchQueryFetchPolicy);
|
|
28
24
|
/**
|
|
29
|
-
* Defaults to the initial value of options.fetchPolicy, but can be explicitly
|
|
25
|
+
* Defaults to the initial value of options.fetchPolicy, but can be explicitly
|
|
26
|
+
* configured to specify the WatchQueryFetchPolicy to revert back to whenever
|
|
27
|
+
* variables change (unless nextFetchPolicy intervenes).
|
|
30
28
|
*
|
|
31
|
-
* @docGroup
|
|
32
|
-
*
|
|
33
|
-
* 3. Caching options
|
|
29
|
+
* @docGroup 3. Caching options
|
|
34
30
|
*/
|
|
35
31
|
initialFetchPolicy?: WatchQueryFetchPolicy;
|
|
36
32
|
/**
|
|
37
|
-
* Specifies whether a `NetworkStatus.refetch` operation should merge
|
|
38
|
-
*
|
|
39
|
-
*
|
|
33
|
+
* Specifies whether a `NetworkStatus.refetch` operation should merge
|
|
34
|
+
* incoming field data with existing data, or overwrite the existing data.
|
|
35
|
+
* Overwriting is probably preferable, but merging is currently the default
|
|
36
|
+
* behavior, for backwards compatibility with Apollo Client 3.x.
|
|
40
37
|
*
|
|
41
|
-
* 3. Caching options
|
|
38
|
+
* @docGroup 3. Caching options
|
|
42
39
|
*/
|
|
43
40
|
refetchWritePolicy?: RefetchWritePolicy;
|
|
44
41
|
/**
|
|
@@ -48,9 +45,7 @@ export declare namespace useQuery {
|
|
|
48
45
|
*
|
|
49
46
|
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
50
47
|
*
|
|
51
|
-
* @docGroup
|
|
52
|
-
*
|
|
53
|
-
* 1. Operation options
|
|
48
|
+
* @docGroup 1. Operation options
|
|
54
49
|
*/
|
|
55
50
|
errorPolicy?: ErrorPolicy;
|
|
56
51
|
/**
|
|
@@ -58,9 +53,7 @@ export declare namespace useQuery {
|
|
|
58
53
|
*
|
|
59
54
|
* The default value is `0` (no polling).
|
|
60
55
|
*
|
|
61
|
-
* @docGroup
|
|
62
|
-
*
|
|
63
|
-
* 2. Networking options
|
|
56
|
+
* @docGroup 2. Networking options
|
|
64
57
|
*/
|
|
65
58
|
pollInterval?: number;
|
|
66
59
|
/**
|
|
@@ -68,9 +61,7 @@ export declare namespace useQuery {
|
|
|
68
61
|
*
|
|
69
62
|
* The default value is `true`.
|
|
70
63
|
*
|
|
71
|
-
* @docGroup
|
|
72
|
-
*
|
|
73
|
-
* 2. Networking options
|
|
64
|
+
* @docGroup 2. Networking options
|
|
74
65
|
*/
|
|
75
66
|
notifyOnNetworkStatusChange?: boolean;
|
|
76
67
|
/**
|
|
@@ -78,43 +69,36 @@ export declare namespace useQuery {
|
|
|
78
69
|
*
|
|
79
70
|
* The default value is `false`.
|
|
80
71
|
*
|
|
81
|
-
* @docGroup
|
|
82
|
-
*
|
|
83
|
-
* 3. Caching options
|
|
72
|
+
* @docGroup 3. Caching options
|
|
84
73
|
*/
|
|
85
74
|
returnPartialData?: boolean;
|
|
86
75
|
/**
|
|
87
|
-
* A callback function that's called whenever a refetch attempt occurs
|
|
76
|
+
* A callback function that's called whenever a refetch attempt occurs
|
|
77
|
+
* while polling. If the function returns `true`, the refetch is
|
|
78
|
+
* skipped and not reattempted until the next poll interval.
|
|
88
79
|
*
|
|
89
|
-
* @docGroup
|
|
90
|
-
*
|
|
91
|
-
* 2. Networking options
|
|
80
|
+
* @docGroup 2. Networking options
|
|
92
81
|
*/
|
|
93
82
|
skipPollAttempt?: () => boolean;
|
|
94
83
|
/**
|
|
95
84
|
* Pass `false` to skip executing the query during [server-side rendering](https://www.apollographql.com/docs/react/performance/server-side-rendering/).
|
|
96
85
|
*
|
|
97
|
-
* @docGroup
|
|
98
|
-
*
|
|
99
|
-
* 2. Networking options
|
|
86
|
+
* @docGroup 2. Networking options
|
|
100
87
|
*/
|
|
101
88
|
ssr?: boolean;
|
|
102
89
|
/**
|
|
103
90
|
* The instance of `ApolloClient` to use to execute the query.
|
|
104
91
|
*
|
|
105
|
-
* By default, the instance that's passed down via context is used, but you
|
|
92
|
+
* By default, the instance that's passed down via context is used, but you
|
|
93
|
+
* can provide a different instance here.
|
|
106
94
|
*
|
|
107
|
-
* @docGroup
|
|
108
|
-
*
|
|
109
|
-
* 1. Operation options
|
|
95
|
+
* @docGroup 1. Operation options
|
|
110
96
|
*/
|
|
111
97
|
client?: ApolloClient;
|
|
112
98
|
/**
|
|
113
99
|
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
114
100
|
*
|
|
115
|
-
* @docGroup
|
|
116
|
-
*
|
|
117
|
-
* 2. Networking options
|
|
101
|
+
* @docGroup 2. Networking options
|
|
118
102
|
*/
|
|
119
103
|
context?: DefaultContext;
|
|
120
104
|
/**
|
|
@@ -122,9 +106,7 @@ export declare namespace useQuery {
|
|
|
122
106
|
*
|
|
123
107
|
* The default value is `false`.
|
|
124
108
|
*
|
|
125
|
-
* @docGroup
|
|
126
|
-
*
|
|
127
|
-
* 1. Operation options
|
|
109
|
+
* @docGroup 1. Operation options
|
|
128
110
|
*/
|
|
129
111
|
skip?: boolean;
|
|
130
112
|
}
|
|
@@ -139,11 +121,10 @@ export declare namespace useQuery {
|
|
|
139
121
|
namespace Base {
|
|
140
122
|
interface Result<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
|
|
141
123
|
/**
|
|
142
|
-
* The instance of Apollo Client that executed the query.
|
|
143
|
-
*
|
|
144
|
-
* @docGroup
|
|
124
|
+
* The instance of Apollo Client that executed the query.
|
|
125
|
+
* Can be useful for manually executing followup queries or writing data to the cache.
|
|
145
126
|
*
|
|
146
|
-
* 2. Network info
|
|
127
|
+
* @docGroup 2. Network info
|
|
147
128
|
*/
|
|
148
129
|
client: ApolloClient;
|
|
149
130
|
/**
|
|
@@ -155,27 +136,22 @@ export declare namespace useQuery {
|
|
|
155
136
|
*
|
|
156
137
|
* This value is `undefined` if this is the query's first execution.
|
|
157
138
|
*
|
|
158
|
-
* @docGroup
|
|
159
|
-
*
|
|
160
|
-
* 1. Operation data
|
|
139
|
+
* @docGroup 1. Operation data
|
|
161
140
|
*/
|
|
162
141
|
previousData?: MaybeMasked<TData>;
|
|
163
142
|
/**
|
|
164
|
-
* A single ErrorLike object describing the error that occured during the latest
|
|
143
|
+
* A single ErrorLike object describing the error that occured during the latest
|
|
144
|
+
* query execution.
|
|
165
145
|
*
|
|
166
146
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
167
147
|
*
|
|
168
|
-
* @docGroup
|
|
169
|
-
*
|
|
170
|
-
* 1. Operation data
|
|
148
|
+
* @docGroup 1. Operation data
|
|
171
149
|
*/
|
|
172
150
|
error?: ErrorLike;
|
|
173
151
|
/**
|
|
174
152
|
* If `true`, the query is still in flight and results have not yet been returned.
|
|
175
153
|
*
|
|
176
|
-
* @docGroup
|
|
177
|
-
*
|
|
178
|
-
* 2. Network info
|
|
154
|
+
* @docGroup 2. Network info
|
|
179
155
|
*/
|
|
180
156
|
loading: boolean;
|
|
181
157
|
/**
|
|
@@ -183,49 +159,39 @@ export declare namespace useQuery {
|
|
|
183
159
|
*
|
|
184
160
|
* Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option.
|
|
185
161
|
*
|
|
186
|
-
* @docGroup
|
|
187
|
-
*
|
|
188
|
-
* 2. Network info
|
|
162
|
+
* @docGroup 2. Network info
|
|
189
163
|
*/
|
|
190
164
|
networkStatus: NetworkStatus;
|
|
191
165
|
/**
|
|
192
166
|
* A function that instructs the query to begin re-executing at a specified interval (in milliseconds).
|
|
167
|
+
*
|
|
193
168
|
*
|
|
194
|
-
*
|
|
195
|
-
* @docGroup
|
|
196
|
-
*
|
|
197
|
-
* 3. Helper functions
|
|
169
|
+
* @docGroup 3. Helper functions
|
|
198
170
|
*/
|
|
199
171
|
startPolling: (pollInterval: number) => void;
|
|
200
172
|
/**
|
|
201
173
|
* A function that instructs the query to stop polling after a previous call to `startPolling`.
|
|
174
|
+
*
|
|
202
175
|
*
|
|
203
|
-
*
|
|
204
|
-
* @docGroup
|
|
205
|
-
*
|
|
206
|
-
* 3. Helper functions
|
|
176
|
+
* @docGroup 3. Helper functions
|
|
207
177
|
*/
|
|
208
178
|
stopPolling: () => void;
|
|
209
179
|
/**
|
|
210
180
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
211
181
|
*
|
|
212
182
|
* This function returns _another_ function that you can call to terminate the subscription.
|
|
183
|
+
*
|
|
213
184
|
*
|
|
214
|
-
*
|
|
215
|
-
* @docGroup
|
|
216
|
-
*
|
|
217
|
-
* 3. Helper functions
|
|
185
|
+
* @docGroup 3. Helper functions
|
|
218
186
|
*/
|
|
219
187
|
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
|
|
220
188
|
/**
|
|
221
189
|
* A function that enables you to update the query's cached result without executing a followup GraphQL operation.
|
|
222
190
|
*
|
|
223
191
|
* See [using updateQuery and updateFragment](https://www.apollographql.com/docs/react/caching/cache-interaction/#using-updatequery-and-updatefragment) for additional information.
|
|
192
|
+
*
|
|
224
193
|
*
|
|
225
|
-
*
|
|
226
|
-
* @docGroup
|
|
227
|
-
*
|
|
228
|
-
* 3. Helper functions
|
|
194
|
+
* @docGroup 3. Helper functions
|
|
229
195
|
*/
|
|
230
196
|
updateQuery: (mapFn: UpdateQueryMapFn<TData, TVariables>) => void;
|
|
231
197
|
/**
|
|
@@ -235,28 +201,24 @@ export declare namespace useQuery {
|
|
|
235
201
|
*
|
|
236
202
|
* See also [Refetching](https://www.apollographql.com/docs/react/data/queries/#refetching).
|
|
237
203
|
*
|
|
238
|
-
* Returns a `ResultPromise` with an additional `.retain()` method. Calling
|
|
204
|
+
* Returns a `ResultPromise` with an additional `.retain()` method. Calling
|
|
205
|
+
* `.retain()` keeps the network operation running even if the `ObservableQuery`
|
|
206
|
+
* no longer requires the result.
|
|
239
207
|
*
|
|
240
|
-
* @docGroup
|
|
241
|
-
*
|
|
242
|
-
* 3. Helper functions
|
|
208
|
+
* @docGroup 3. Helper functions
|
|
243
209
|
*/
|
|
244
210
|
refetch: (variables?: Partial<TVariables>) => Promise<ApolloClient.QueryResult<MaybeMasked<TData>>>;
|
|
245
211
|
/**
|
|
246
212
|
* An object containing the variables that were provided for the query.
|
|
247
213
|
*
|
|
248
|
-
* @docGroup
|
|
249
|
-
*
|
|
250
|
-
* 1. Operation data
|
|
214
|
+
* @docGroup 1. Operation data
|
|
251
215
|
*/
|
|
252
216
|
variables: TVariables;
|
|
253
217
|
/**
|
|
254
218
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
219
|
+
*
|
|
255
220
|
*
|
|
256
|
-
*
|
|
257
|
-
* @docGroup
|
|
258
|
-
*
|
|
259
|
-
* 3. Helper functions
|
|
221
|
+
* @docGroup 3. Helper functions
|
|
260
222
|
*/
|
|
261
223
|
fetchMore: <TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(fetchMoreOptions: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>) => Promise<ApolloClient.QueryResult<MaybeMasked<TFetchData>>>;
|
|
262
224
|
}
|
|
@@ -278,13 +240,8 @@ export declare namespace useQuery {
|
|
|
278
240
|
*
|
|
279
241
|
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
280
242
|
*
|
|
281
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
282
|
-
*
|
|
283
|
-
* @param options - Options to control how the query is executed.
|
|
284
|
-
*
|
|
285
|
-
* @returns Query result object
|
|
286
|
-
*
|
|
287
243
|
* @example
|
|
244
|
+
*
|
|
288
245
|
* ```jsx
|
|
289
246
|
* import { gql } from "@apollo/client";
|
|
290
247
|
* import { useQuery } from "@apollo/client/react";
|
|
@@ -305,6 +262,10 @@ export declare namespace useQuery {
|
|
|
305
262
|
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
306
263
|
* }
|
|
307
264
|
* ```
|
|
265
|
+
*
|
|
266
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
267
|
+
* @param options - Options to control how the query is executed.
|
|
268
|
+
* @returns Query result object
|
|
308
269
|
*/
|
|
309
270
|
function useQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<TData, TVariables>): useQuery.Result<TData, TVariables>;
|
|
310
271
|
}
|
|
@@ -357,13 +318,8 @@ export declare function useQuery<TData = unknown, TVariables extends OperationVa
|
|
|
357
318
|
*
|
|
358
319
|
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
359
320
|
*
|
|
360
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
361
|
-
*
|
|
362
|
-
* @param options - Options to control how the query is executed.
|
|
363
|
-
*
|
|
364
|
-
* @returns Query result object
|
|
365
|
-
*
|
|
366
321
|
* @example
|
|
322
|
+
*
|
|
367
323
|
* ```jsx
|
|
368
324
|
* import { gql } from "@apollo/client";
|
|
369
325
|
* import { useQuery } from "@apollo/client/react";
|
|
@@ -384,6 +340,10 @@ export declare function useQuery<TData = unknown, TVariables extends OperationVa
|
|
|
384
340
|
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
385
341
|
* }
|
|
386
342
|
* ```
|
|
343
|
+
*
|
|
344
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
345
|
+
* @param options - Options to control how the query is executed.
|
|
346
|
+
* @returns Query result object
|
|
387
347
|
*/
|
|
388
348
|
export declare function useQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
389
349
|
returnPartialData: boolean;
|
|
@@ -397,13 +357,8 @@ export declare function useQuery<TData = unknown, TVariables extends OperationVa
|
|
|
397
357
|
*
|
|
398
358
|
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
399
359
|
*
|
|
400
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
401
|
-
*
|
|
402
|
-
* @param options - Options to control how the query is executed.
|
|
403
|
-
*
|
|
404
|
-
* @returns Query result object
|
|
405
|
-
*
|
|
406
360
|
* @example
|
|
361
|
+
*
|
|
407
362
|
* ```jsx
|
|
408
363
|
* import { gql } from "@apollo/client";
|
|
409
364
|
* import { useQuery } from "@apollo/client/react";
|
|
@@ -424,6 +379,10 @@ export declare function useQuery<TData = unknown, TVariables extends OperationVa
|
|
|
424
379
|
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
425
380
|
* }
|
|
426
381
|
* ```
|
|
382
|
+
*
|
|
383
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
384
|
+
* @param options - Options to control how the query is executed.
|
|
385
|
+
* @returns Query result object
|
|
427
386
|
*/
|
|
428
387
|
export declare function useQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
429
388
|
options?: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|