@apollo/client 4.0.0-rc.5 → 4.0.0-rc.7
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 +153 -0
- package/README.md +40 -40
- package/__cjs/cache/core/cache.cjs +14 -13
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +77 -71
- package/__cjs/cache/core/types/Cache.cjs +0 -4
- package/__cjs/cache/core/types/Cache.cjs.map +1 -1
- package/__cjs/cache/core/types/Cache.d.cts +200 -15
- package/__cjs/cache/{core/types/DataProxy.cjs → deprecated.cjs} +1 -1
- package/__cjs/cache/deprecated.cjs.map +1 -0
- package/__cjs/cache/deprecated.d.cts +6 -0
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +2 -2
- package/__cjs/cache/inmemory/entityStore.cjs +25 -28
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +17 -16
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +4 -4
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +3 -2
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.d.cts +1 -1
- package/__cjs/core/ApolloClient.cjs +94 -112
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +758 -182
- package/__cjs/core/ObservableQuery.cjs +10 -10
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +131 -112
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +8 -7
- package/__cjs/core/QueryManager.cjs +15 -15
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +20 -20
- package/__cjs/core/deprecated.cjs +3 -0
- package/__cjs/core/deprecated.cjs.map +1 -0
- package/__cjs/core/deprecated.d.cts +29 -0
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +10 -6
- package/__cjs/core/types.d.cts +69 -157
- package/__cjs/core/watchQueryOptions.d.cts +8 -297
- package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
- package/__cjs/dev/setErrorMessageHandler.d.cts +4 -4
- package/__cjs/errors/CombinedGraphQLErrors.cjs +64 -11
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +168 -14
- package/__cjs/errors/CombinedProtocolErrors.cjs +54 -1
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +132 -2
- package/__cjs/errors/LinkError.cjs +45 -2
- package/__cjs/errors/LinkError.cjs.map +1 -1
- package/__cjs/errors/LinkError.d.cts +45 -2
- package/__cjs/errors/LocalStateError.cjs +35 -5
- package/__cjs/errors/LocalStateError.cjs.map +1 -1
- package/__cjs/errors/LocalStateError.d.cts +41 -5
- package/__cjs/errors/ServerError.cjs +51 -8
- package/__cjs/errors/ServerError.cjs.map +1 -1
- package/__cjs/errors/ServerError.d.cts +71 -11
- package/__cjs/errors/ServerParseError.cjs +46 -8
- package/__cjs/errors/ServerParseError.cjs.map +1 -1
- package/__cjs/errors/ServerParseError.d.cts +72 -16
- package/__cjs/errors/UnconventionalError.cjs +46 -2
- package/__cjs/errors/UnconventionalError.cjs.map +1 -1
- package/__cjs/errors/UnconventionalError.d.cts +46 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +4 -4
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- 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 +81 -85
- package/__cjs/link/batch/batchLink.cjs +3 -9
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +2 -3
- package/__cjs/link/batch/batching.cjs +1 -1
- package/__cjs/link/batch/batching.cjs.map +1 -1
- package/__cjs/link/batch/batching.d.cts +7 -7
- package/__cjs/link/batch-http/batchHttpLink.cjs +8 -5
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +1 -2
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +4 -4
- package/__cjs/link/context/index.cjs +1 -1
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +4 -5
- package/__cjs/link/core/ApolloLink.cjs +227 -55
- 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.map +1 -1
- package/__cjs/link/error/index.d.cts +20 -6
- package/__cjs/link/http/BaseHttpLink.cjs +2 -2
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.cjs +4 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +3 -3
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +41 -26
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.d.cts +2 -2
- 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/http/serializeFetchParameter.cjs +1 -1
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +2 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +11 -12
- package/__cjs/link/retry/delayFunction.cjs.map +1 -1
- package/__cjs/link/retry/delayFunction.d.cts +3 -3
- package/__cjs/link/retry/retryFunction.cjs.map +1 -1
- package/__cjs/link/retry/retryFunction.d.cts +4 -4
- package/__cjs/link/retry/retryLink.cjs +2 -2
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +1 -2
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +2 -3
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- package/__cjs/link/subscriptions/index.d.cts +1 -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.map +1 -1
- package/__cjs/link/ws/index.d.cts +1 -2
- package/__cjs/local-state/LocalState.cjs +55 -9
- package/__cjs/local-state/LocalState.cjs.map +1 -1
- package/__cjs/local-state/LocalState.d.cts +94 -0
- package/__cjs/masking/GraphQLCodegenDataMasking.d.cts +6 -7
- package/__cjs/masking/internal/types.d.cts +70 -70
- package/__cjs/masking/maskDefinition.cjs +2 -2
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +3 -3
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/useDeepMemo.cjs +0 -3
- package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs.map +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.d.cts +2 -2
- package/__cjs/react/hooks/internal/wrapHook.cjs +1 -0
- package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
- package/__cjs/react/hooks/internal/wrapHook.d.cts +8 -7
- package/__cjs/react/hooks/useApolloClient.cjs +2 -2
- package/__cjs/react/hooks/useApolloClient.cjs.map +1 -1
- package/__cjs/react/hooks/useApolloClient.d.cts +2 -2
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +850 -90
- package/__cjs/react/hooks/useFragment.cjs +7 -0
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +53 -2
- package/__cjs/react/hooks/useLazyQuery.cjs +0 -38
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +317 -165
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +153 -175
- package/__cjs/react/hooks/useMutation.cjs +6 -7
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +87 -65
- package/__cjs/react/hooks/useQuery.cjs +1 -35
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +207 -103
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +2 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +34 -5
- package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
- package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
- package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
- package/__cjs/react/hooks/useReadQuery.cjs +29 -0
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +92 -16
- package/__cjs/react/hooks/useSubscription.cjs +8 -9
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +108 -33
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +61 -29
- package/__cjs/react/hooks/useSuspenseQuery.cjs +4 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +471 -69
- package/__cjs/react/index.cjs +1 -3
- package/__cjs/react/index.cjs.map +1 -1
- package/__cjs/react/index.d.cts +0 -1
- package/__cjs/react/index.react-server.cjs +1 -3
- package/__cjs/react/index.react-server.cjs.map +1 -1
- package/__cjs/react/index.react-server.d.cts +0 -1
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -3
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +14 -12
- package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.d.cts +2 -2
- package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/getSuspenseCache.d.cts +6 -4
- package/__cjs/react/internal/index.cjs +1 -0
- package/__cjs/react/internal/index.cjs.map +1 -1
- package/__cjs/react/internal/index.d.cts +1 -1
- package/__cjs/react/internal/types.d.cts +3 -3
- package/__cjs/react/query-preloader/createQueryPreloader.cjs +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +60 -51
- package/__cjs/react/ssr/prerenderStatic.cjs +5 -4
- package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
- package/__cjs/react/ssr/prerenderStatic.d.cts +11 -9
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
- package/__cjs/react/types/deprecated.d.cts +1 -1
- package/__cjs/react/types/types.documentation.d.cts +15 -15
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +8 -8
- package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +3 -4
- package/__cjs/testing/core/types/deprecated.d.cts +3 -2
- package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
- package/__cjs/testing/react/MockedProvider.d.cts +2 -3
- package/__cjs/utilities/HKT.d.cts +8 -7
- package/__cjs/utilities/caching/sizes.cjs +3 -3
- package/__cjs/utilities/caching/sizes.cjs.map +1 -1
- package/__cjs/utilities/caching/sizes.d.cts +4 -6
- package/__cjs/utilities/graphql/DocumentTransform.cjs +2 -2
- package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
- package/__cjs/utilities/index.cjs +2 -3
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +1 -2
- package/__cjs/utilities/{shared → internal}/canonicalStringify.cjs +5 -7
- package/__cjs/utilities/internal/canonicalStringify.cjs.map +1 -0
- package/__cjs/utilities/{shared → internal}/canonicalStringify.d.cts +1 -1
- package/__cjs/utilities/internal/checkDocument.cjs +2 -2
- package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/createFragmentMap.cjs.map +1 -1
- package/__cjs/{core → utilities/internal}/equalByQuery.cjs +13 -7
- package/__cjs/utilities/internal/equalByQuery.cjs.map +1 -0
- package/__cjs/utilities/internal/equalByQuery.d.cts +5 -0
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +13 -3
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.d.cts +13 -3
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getStoreKeyName.cjs +1 -2
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +6 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +2 -0
- package/__cjs/utilities/internal/mergeOptions.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeOptions.d.cts +2 -2
- package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
- package/__cjs/utilities/internal/toQueryResult.d.cts +2 -2
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +32 -26
- package/__cjs/utilities/internal/types/NoInfer.d.cts +31 -25
- package/__cjs/utilities/internal/types/VariablesOption.d.cts +2 -6
- package/__cjs/utilities/subscriptions/relay/index.cjs +2 -0
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +77 -71
- package/cache/core/cache.js +15 -14
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +200 -15
- package/cache/core/types/Cache.js +1 -3
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/deprecated.d.ts +6 -0
- package/cache/deprecated.js +2 -0
- package/cache/deprecated.js.map +1 -0
- package/cache/index.d.ts +2 -2
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +17 -16
- package/cache/inmemory/entityStore.js +25 -28
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +4 -4
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.d.ts +3 -2
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/writeToStore.d.ts +1 -1
- package/cache/inmemory/writeToStore.js +4 -4
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +758 -182
- package/core/ApolloClient.js +94 -112
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +131 -112
- package/core/ObservableQuery.js +10 -10
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +8 -7
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +20 -20
- package/core/QueryManager.js +15 -15
- package/core/QueryManager.js.map +1 -1
- package/core/deprecated.d.ts +29 -0
- package/core/deprecated.js +2 -0
- package/core/deprecated.js.map +1 -0
- package/core/index.d.ts +10 -6
- package/core/index.js.map +1 -1
- package/core/types.d.ts +69 -157
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +9 -298
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/setErrorMessageHandler.d.ts +4 -4
- package/dev/setErrorMessageHandler.js.map +1 -1
- package/errors/CombinedGraphQLErrors.d.ts +169 -15
- package/errors/CombinedGraphQLErrors.js +65 -12
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +133 -3
- package/errors/CombinedProtocolErrors.js +55 -2
- package/errors/CombinedProtocolErrors.js.map +1 -1
- package/errors/LinkError.d.ts +45 -2
- package/errors/LinkError.js +45 -2
- package/errors/LinkError.js.map +1 -1
- package/errors/LocalStateError.d.ts +42 -6
- package/errors/LocalStateError.js +36 -6
- package/errors/LocalStateError.js.map +1 -1
- package/errors/ServerError.d.ts +72 -12
- package/errors/ServerError.js +52 -9
- package/errors/ServerError.js.map +1 -1
- package/errors/ServerParseError.d.ts +73 -17
- package/errors/ServerParseError.js +47 -9
- package/errors/ServerParseError.js.map +1 -1
- package/errors/UnconventionalError.d.ts +46 -2
- package/errors/UnconventionalError.js +46 -2
- package/errors/UnconventionalError.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 +1 -1
- 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 +81 -85
- package/link/batch/batchLink.d.ts +2 -3
- package/link/batch/batchLink.js +3 -9
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.d.ts +7 -7
- package/link/batch/batching.js +2 -2
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batchHttpLink.d.ts +1 -2
- package/link/batch-http/batchHttpLink.js +7 -4
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +4 -4
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +4 -5
- package/link/context/index.js +1 -1
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +355 -9
- package/link/core/ApolloLink.js +228 -57
- 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 +20 -6
- package/link/error/index.js.map +1 -1
- package/link/http/BaseHttpLink.js +2 -2
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +3 -3
- package/link/http/HttpLink.js +4 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
- package/link/http/parseAndCheckHttpResponse.js +41 -26
- package/link/http/parseAndCheckHttpResponse.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/http/serializeFetchParameter.js +1 -1
- package/link/index.d.ts +2 -1
- package/link/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +11 -12
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/index.js.map +1 -1
- package/link/retry/delayFunction.d.ts +3 -3
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retryFunction.d.ts +4 -4
- package/link/retry/retryFunction.js.map +1 -1
- package/link/retry/retryLink.d.ts +1 -2
- package/link/retry/retryLink.js +2 -2
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +2 -3
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.d.ts +1 -2
- 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 +1 -2
- package/link/ws/index.js.map +1 -1
- package/local-state/LocalState.d.ts +94 -0
- package/local-state/LocalState.js +55 -9
- package/local-state/LocalState.js.map +1 -1
- package/masking/GraphQLCodegenDataMasking.d.ts +6 -7
- package/masking/GraphQLCodegenDataMasking.js.map +1 -1
- package/masking/internal/types.d.ts +70 -70
- package/masking/internal/types.js.map +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/types.js.map +1 -1
- package/masking/utils.js +3 -3
- package/package.json +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/useDeepMemo.js +0 -3
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/validateSuspenseHookOptions.d.ts +2 -2
- package/react/hooks/internal/validateSuspenseHookOptions.js.map +1 -1
- package/react/hooks/internal/wrapHook.d.ts +8 -7
- package/react/hooks/internal/wrapHook.js +1 -0
- package/react/hooks/internal/wrapHook.js.map +1 -1
- package/react/hooks/useApolloClient.d.ts +2 -2
- package/react/hooks/useApolloClient.js +2 -2
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +850 -90
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +54 -3
- package/react/hooks/useFragment.js +7 -0
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +317 -165
- package/react/hooks/useLazyQuery.js +0 -38
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +153 -175
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +87 -65
- package/react/hooks/useMutation.js +6 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +207 -103
- package/react/hooks/useQuery.js +1 -35
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +34 -5
- package/react/hooks/useQueryRefHandlers.js +2 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReactiveVar.d.ts +2 -1
- package/react/hooks/useReactiveVar.js +2 -1
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +93 -17
- package/react/hooks/useReadQuery.js +29 -0
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +108 -33
- package/react/hooks/useSubscription.js +8 -9
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +62 -30
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +471 -69
- package/react/hooks/useSuspenseQuery.js +4 -1
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/internal/useDeepMemo.js +0 -3
- package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
- package/react/hooks-compiled/internal/validateSuspenseHookOptions.d.ts +2 -2
- package/react/hooks-compiled/internal/validateSuspenseHookOptions.js.map +1 -1
- package/react/hooks-compiled/internal/wrapHook.d.ts +8 -7
- package/react/hooks-compiled/internal/wrapHook.js +1 -0
- package/react/hooks-compiled/internal/wrapHook.js.map +1 -1
- package/react/hooks-compiled/useApolloClient.d.ts +2 -2
- package/react/hooks-compiled/useApolloClient.js +2 -2
- package/react/hooks-compiled/useApolloClient.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +850 -90
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +54 -3
- package/react/hooks-compiled/useFragment.js +7 -0
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +317 -165
- package/react/hooks-compiled/useLazyQuery.js +0 -38
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +153 -175
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +87 -65
- package/react/hooks-compiled/useMutation.js +6 -7
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +207 -103
- package/react/hooks-compiled/useQuery.js +1 -35
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +34 -5
- package/react/hooks-compiled/useQueryRefHandlers.js +2 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReactiveVar.d.ts +2 -1
- package/react/hooks-compiled/useReactiveVar.js +2 -1
- package/react/hooks-compiled/useReactiveVar.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +93 -17
- package/react/hooks-compiled/useReadQuery.js +29 -0
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +108 -33
- package/react/hooks-compiled/useSubscription.js +8 -9
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +62 -30
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +471 -69
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/index.compiled.d.ts +0 -1
- package/react/index.compiled.js +0 -1
- package/react/index.compiled.js.map +1 -1
- package/react/index.d.ts +0 -1
- package/react/index.js +0 -1
- package/react/index.js.map +1 -1
- package/react/index.react-server.d.ts +0 -1
- package/react/index.react-server.js +0 -2
- package/react/index.react-server.js.map +1 -1
- package/react/internal/cache/FragmentReference.d.ts +2 -3
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +14 -12
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/cache/SuspenseCache.d.ts +2 -2
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/getSuspenseCache.d.ts +6 -4
- package/react/internal/cache/getSuspenseCache.js.map +1 -1
- package/react/internal/index.d.ts +1 -1
- package/react/internal/index.js +1 -0
- package/react/internal/index.js.map +1 -1
- package/react/internal/types.d.ts +3 -3
- package/react/internal/types.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +60 -51
- package/react/query-preloader/createQueryPreloader.js +1 -1
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/prerenderStatic.d.ts +11 -9
- package/react/ssr/prerenderStatic.js +5 -4
- package/react/ssr/prerenderStatic.js.map +1 -1
- package/react/ssr/useSSRQuery.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 +15 -15
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +8 -8
- 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/testing/core/types/deprecated.d.ts +3 -2
- package/testing/core/types/deprecated.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +2 -3
- package/testing/react/MockedProvider.js.map +1 -1
- package/utilities/HKT.d.ts +8 -7
- package/utilities/HKT.js.map +1 -1
- package/utilities/caching/sizes.d.ts +4 -6
- package/utilities/caching/sizes.js +3 -3
- package/utilities/caching/sizes.js.map +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/index.d.ts +1 -2
- package/utilities/index.js +1 -2
- package/utilities/index.js.map +1 -1
- package/utilities/{shared → internal}/canonicalStringify.d.ts +1 -1
- package/utilities/{shared → internal}/canonicalStringify.js +4 -6
- package/utilities/internal/canonicalStringify.js.map +1 -0
- package/utilities/internal/checkDocument.js +1 -1
- package/utilities/internal/checkDocument.js.map +1 -1
- package/utilities/internal/createFragmentMap.js.map +1 -1
- package/utilities/internal/equalByQuery.d.ts +5 -0
- package/{core → utilities/internal}/equalByQuery.js +7 -1
- package/utilities/internal/equalByQuery.js.map +1 -0
- package/utilities/internal/getFragmentQueryDocument.d.ts +13 -3
- package/utilities/internal/getFragmentQueryDocument.js +13 -3
- package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/getStoreKeyName.js +1 -2
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/index.d.ts +2 -0
- package/utilities/internal/index.js +2 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/mergeOptions.d.ts +2 -2
- package/utilities/internal/mergeOptions.js.map +1 -1
- package/utilities/internal/toQueryResult.d.ts +2 -2
- package/utilities/internal/toQueryResult.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +32 -26
- package/utilities/internal/types/DocumentationTypes.js.map +1 -1
- package/utilities/internal/types/NoInfer.d.ts +31 -25
- package/utilities/internal/types/NoInfer.js.map +1 -1
- package/utilities/internal/types/VariablesOption.d.ts +2 -6
- package/utilities/subscriptions/relay/index.js +2 -0
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/cache/core/types/DataProxy.cjs.map +0 -1
- package/__cjs/cache/core/types/DataProxy.d.cts +0 -140
- package/__cjs/core/equalByQuery.cjs.map +0 -1
- package/__cjs/core/equalByQuery.d.cts +0 -4
- 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/__cjs/react/context/ApolloConsumer.cjs +0 -16
- package/__cjs/react/context/ApolloConsumer.cjs.map +0 -1
- package/__cjs/react/context/ApolloConsumer.d.cts +0 -10
- package/__cjs/utilities/shared/canonicalStringify.cjs.map +0 -1
- package/cache/core/types/DataProxy.d.ts +0 -140
- package/cache/core/types/DataProxy.js +0 -2
- package/cache/core/types/DataProxy.js.map +0 -1
- package/core/equalByQuery.d.ts +0 -4
- package/core/equalByQuery.js.map +0 -1
- package/link/utils/transformOperation.d.ts +0 -3
- package/link/utils/transformOperation.js +0 -19
- package/link/utils/transformOperation.js.map +0 -1
- package/link/utils/validateOperation.d.ts +0 -3
- package/link/utils/validateOperation.js +0 -18
- package/link/utils/validateOperation.js.map +0 -1
- package/react/context/ApolloConsumer.d.ts +0 -10
- package/react/context/ApolloConsumer.js +0 -11
- package/react/context/ApolloConsumer.js.map +0 -1
- package/utilities/shared/canonicalStringify.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
2
|
-
import type { ApolloCache, ApolloClient, DefaultContext, DocumentNode, ErrorLike, ErrorPolicy, InternalRefetchQueriesInclude, MaybeMasked,
|
|
2
|
+
import type { ApolloCache, ApolloClient, DefaultContext, DocumentNode, ErrorLike, ErrorPolicy, InternalRefetchQueriesInclude, MaybeMasked, MutationFetchPolicy, MutationQueryReducersMap, MutationUpdaterFunction, NormalizedExecutionResult, OnQueryUpdated, OperationVariables, Unmasked } from "@apollo/client";
|
|
3
3
|
import type { IgnoreModifier } from "@apollo/client/cache";
|
|
4
4
|
import type { NoInfer, Prettify } from "@apollo/client/utilities/internal";
|
|
5
5
|
type MakeRequiredVariablesOptional<TVariables extends OperationVariables, TConfiguredVariables extends Partial<TVariables>> = Prettify<{
|
|
@@ -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,32 +193,69 @@ 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
|
}
|
|
217
|
-
]) => Promise<MutateResult<MaybeMasked<TData>>>;
|
|
218
|
-
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache
|
|
200
|
+
]) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
201
|
+
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache>;
|
|
202
|
+
namespace DocumentationTypes {
|
|
219
203
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
*
|
|
224
|
-
*
|
|
204
|
+
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
*
|
|
208
|
+
* ```jsx
|
|
209
|
+
* import { gql, useMutation } from "@apollo/client";
|
|
210
|
+
*
|
|
211
|
+
* const ADD_TODO = gql`
|
|
212
|
+
* mutation AddTodo($type: String!) {
|
|
213
|
+
* addTodo(type: $type) {
|
|
214
|
+
* id
|
|
215
|
+
* type
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* `;
|
|
219
|
+
*
|
|
220
|
+
* function AddTodo() {
|
|
221
|
+
* let input;
|
|
222
|
+
* const [addTodo, { data }] = useMutation(ADD_TODO);
|
|
223
|
+
*
|
|
224
|
+
* return (
|
|
225
|
+
* <div>
|
|
226
|
+
* <form
|
|
227
|
+
* onSubmit={(e) => {
|
|
228
|
+
* e.preventDefault();
|
|
229
|
+
* addTodo({ variables: { type: input.value } });
|
|
230
|
+
* input.value = "";
|
|
231
|
+
* }}
|
|
232
|
+
* >
|
|
233
|
+
* <input
|
|
234
|
+
* ref={(node) => {
|
|
235
|
+
* input = node;
|
|
236
|
+
* }}
|
|
237
|
+
* />
|
|
238
|
+
* <button type="submit">Add Todo</button>
|
|
239
|
+
* </form>
|
|
240
|
+
* </div>
|
|
241
|
+
* );
|
|
242
|
+
* }
|
|
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]`
|
|
225
248
|
*/
|
|
226
|
-
mutation
|
|
227
|
-
}
|
|
249
|
+
function useMutation<TData = unknown, TVariables extends OperationVariables = OperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useMutation.Options<TData, TVariables>): useMutation.ResultTuple<TData, TVariables>;
|
|
250
|
+
}
|
|
228
251
|
}
|
|
229
252
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
253
|
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
233
254
|
*
|
|
234
255
|
* @example
|
|
256
|
+
*
|
|
235
257
|
* ```jsx
|
|
236
|
-
* import { gql, useMutation } from
|
|
258
|
+
* import { gql, useMutation } from "@apollo/client";
|
|
237
259
|
*
|
|
238
260
|
* const ADD_TODO = gql`
|
|
239
261
|
* mutation AddTodo($type: String!) {
|
|
@@ -251,14 +273,14 @@ export declare namespace useMutation {
|
|
|
251
273
|
* return (
|
|
252
274
|
* <div>
|
|
253
275
|
* <form
|
|
254
|
-
* onSubmit={e => {
|
|
276
|
+
* onSubmit={(e) => {
|
|
255
277
|
* e.preventDefault();
|
|
256
278
|
* addTodo({ variables: { type: input.value } });
|
|
257
|
-
* input.value =
|
|
279
|
+
* input.value = "";
|
|
258
280
|
* }}
|
|
259
281
|
* >
|
|
260
282
|
* <input
|
|
261
|
-
* ref={node => {
|
|
283
|
+
* ref={(node) => {
|
|
262
284
|
* input = node;
|
|
263
285
|
* }}
|
|
264
286
|
* />
|
|
@@ -268,7 +290,7 @@ export declare namespace useMutation {
|
|
|
268
290
|
* );
|
|
269
291
|
* }
|
|
270
292
|
* ```
|
|
271
|
-
*
|
|
293
|
+
*
|
|
272
294
|
* @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
|
|
273
295
|
* @param options - Options to control how the mutation is executed.
|
|
274
296
|
* @returns A tuple in the form of `[mutate, result]`
|
|
@@ -4,13 +4,12 @@ import { mergeOptions } from "@apollo/client/utilities/internal";
|
|
|
4
4
|
import { useIsomorphicLayoutEffect } from "./internal/useIsomorphicLayoutEffect.js";
|
|
5
5
|
import { useApolloClient } from "./useApolloClient.js";
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
7
|
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
10
8
|
*
|
|
11
9
|
* @example
|
|
10
|
+
*
|
|
12
11
|
* ```jsx
|
|
13
|
-
* import { gql, useMutation } from
|
|
12
|
+
* import { gql, useMutation } from "@apollo/client";
|
|
14
13
|
*
|
|
15
14
|
* const ADD_TODO = gql`
|
|
16
15
|
* mutation AddTodo($type: String!) {
|
|
@@ -28,14 +27,14 @@ import { useApolloClient } from "./useApolloClient.js";
|
|
|
28
27
|
* return (
|
|
29
28
|
* <div>
|
|
30
29
|
* <form
|
|
31
|
-
* onSubmit={e => {
|
|
30
|
+
* onSubmit={(e) => {
|
|
32
31
|
* e.preventDefault();
|
|
33
32
|
* addTodo({ variables: { type: input.value } });
|
|
34
|
-
* input.value =
|
|
33
|
+
* input.value = "";
|
|
35
34
|
* }}
|
|
36
35
|
* >
|
|
37
36
|
* <input
|
|
38
|
-
* ref={node => {
|
|
37
|
+
* ref={(node) => {
|
|
39
38
|
* input = node;
|
|
40
39
|
* }}
|
|
41
40
|
* />
|
|
@@ -45,7 +44,7 @@ import { useApolloClient } from "./useApolloClient.js";
|
|
|
45
44
|
* );
|
|
46
45
|
* }
|
|
47
46
|
* ```
|
|
48
|
-
*
|
|
47
|
+
*
|
|
49
48
|
* @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
|
|
50
49
|
* @param options - Options to control how the mutation is executed.
|
|
51
50
|
* @returns A tuple in the form of `[mutate, result]`
|
|
@@ -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;AAuB/B,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAC;AAEjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA6IvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;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,CAA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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 MutateResult,\n MutationFetchPolicy,\n MutationOptions,\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<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 /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#mutation:member} */\n // TODO: Remove this option. We shouldn't allow the mutation to be overridden\n // in the mutation function\n mutation?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n };\n}\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 * ```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 * @since 3.0.0\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(clientOptions as MutationOptions<TData, OperationVariables>)\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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AAC,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/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"]}
|