@apollo/client 4.0.0-rc.4 → 4.0.0-rc.6
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 +63 -0
- package/README.md +40 -40
- package/__cjs/cache/core/cache.cjs +4 -12
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +96 -66
- 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 +28 -31
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +18 -17
- package/__cjs/cache/inmemory/inMemoryCache.cjs +1 -1
- 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/types.d.cts +1 -1
- 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 +137 -117
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +790 -183
- package/__cjs/core/ObservableQuery.cjs +50 -20
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +184 -68
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +5 -4
- package/__cjs/core/QueryManager.cjs +15 -13
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +17 -17
- 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 +9 -5
- package/__cjs/core/types.d.cts +81 -104
- 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 +59 -11
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +146 -11
- package/__cjs/errors/CombinedProtocolErrors.cjs +48 -1
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +126 -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 +50 -8
- package/__cjs/errors/ServerError.cjs.map +1 -1
- package/__cjs/errors/ServerError.d.cts +70 -11
- package/__cjs/errors/ServerParseError.cjs +45 -8
- package/__cjs/errors/ServerParseError.cjs.map +1 -1
- package/__cjs/errors/ServerParseError.d.cts +71 -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/notImplemented.cjs +1 -1
- package/__cjs/invariantErrorCodes.cjs +72 -80
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.cjs +2 -2
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- 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 +1 -1
- package/__cjs/link/core/ApolloLink.cjs +2 -2
- package/__cjs/link/core/types.d.cts +2 -2
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +16 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +13 -2
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +1 -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 -11
- package/__cjs/link/retry/delayFunction.cjs.map +1 -1
- package/__cjs/link/retry/delayFunction.d.cts +1 -1
- package/__cjs/link/retry/retryFunction.cjs.map +1 -1
- package/__cjs/link/retry/retryFunction.d.cts +1 -1
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/utils/validateOperation.cjs +1 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- 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 +814 -82
- package/__cjs/react/hooks/useFragment.cjs +11 -9
- 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 +313 -119
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +230 -44
- package/__cjs/react/hooks/useMutation.cjs +6 -7
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +57 -17
- package/__cjs/react/hooks/useQuery.cjs +1 -35
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +407 -238
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +2 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +25 -1
- 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 +95 -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 +153 -69
- 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 +605 -160
- package/__cjs/react/index.cjs +1 -5
- package/__cjs/react/index.cjs.map +1 -1
- package/__cjs/react/index.d.cts +0 -2
- 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 +1 -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 +11 -11
- 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 +31 -31
- 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 +22 -11
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +3 -2
- 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 +9 -7
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/index.cjs +8 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +4 -0
- package/__cjs/utilities/internal/mergeOptions.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeOptions.d.cts +2 -2
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs +14 -0
- package/__cjs/utilities/internal/removeFragmentSpreads.cjs.map +1 -0
- package/__cjs/utilities/internal/removeFragmentSpreads.d.cts +3 -0
- package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
- package/__cjs/utilities/internal/toQueryResult.d.cts +2 -2
- package/__cjs/utilities/internal/types/DocumentationTypes.cjs +3 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.cjs.map +1 -0
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +96 -0
- package/__cjs/utilities/internal/types/NoInfer.d.cts +31 -25
- 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 +96 -66
- package/cache/core/cache.js +5 -13
- 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 +18 -17
- package/cache/inmemory/entityStore.js +28 -31
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +4 -4
- package/cache/inmemory/inMemoryCache.js +1 -1
- 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/types.d.ts +1 -1
- package/cache/inmemory/types.js.map +1 -1
- 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 +790 -183
- package/core/ApolloClient.js +138 -118
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +184 -68
- package/core/ObservableQuery.js +50 -20
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +5 -4
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +17 -17
- package/core/QueryManager.js +15 -13
- 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 +9 -5
- package/core/index.js.map +1 -1
- package/core/types.d.ts +81 -104
- 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 +147 -12
- package/errors/CombinedGraphQLErrors.js +60 -12
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +127 -3
- package/errors/CombinedProtocolErrors.js +49 -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 +71 -12
- package/errors/ServerError.js +51 -9
- package/errors/ServerError.js.map +1 -1
- package/errors/ServerParseError.d.ts +72 -17
- package/errors/ServerParseError.js +46 -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/notImplemented.js +1 -1
- package/invariantErrorCodes.js +72 -80
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch-http/batchHttpLink.js +1 -1
- 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 +1 -1
- package/link/context/index.js +1 -1
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.js +2 -2
- package/link/core/types.d.ts +2 -2
- package/link/core/types.js.map +1 -1
- package/link/error/index.d.ts +16 -1
- package/link/error/index.js.map +1 -1
- package/link/http/HttpLink.d.ts +13 -2
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.d.ts +11 -11
- package/link/persisted-queries/index.js +2 -2
- package/link/persisted-queries/index.js.map +1 -1
- package/link/retry/delayFunction.d.ts +1 -1
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retryFunction.d.ts +1 -1
- package/link/retry/retryFunction.js.map +1 -1
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.js.map +1 -1
- package/link/utils/validateOperation.js +1 -1
- 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 +814 -82
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +54 -3
- package/react/hooks/useFragment.js +11 -9
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +313 -119
- package/react/hooks/useLazyQuery.js +0 -38
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +230 -44
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +57 -17
- package/react/hooks/useMutation.js +6 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +407 -238
- package/react/hooks/useQuery.js +1 -35
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +25 -1
- 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 +96 -17
- package/react/hooks/useReadQuery.js +29 -0
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +153 -69
- 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 +605 -160
- 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 +814 -82
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +54 -3
- package/react/hooks-compiled/useFragment.js +11 -9
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +313 -119
- package/react/hooks-compiled/useLazyQuery.js +0 -38
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +230 -44
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +57 -17
- package/react/hooks-compiled/useMutation.js +6 -7
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +407 -238
- package/react/hooks-compiled/useQuery.js +1 -35
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +25 -1
- 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 +96 -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 +153 -69
- 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 +605 -160
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/index.compiled.d.ts +0 -2
- package/react/index.compiled.js +0 -2
- package/react/index.compiled.js.map +1 -1
- package/react/index.d.ts +0 -2
- package/react/index.js +0 -2
- 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 +1 -1
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +11 -11
- 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 +31 -31
- 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 +22 -11
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +3 -2
- package/testing/core/mocking/mockLink.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 +9 -7
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/index.d.ts +4 -0
- package/utilities/internal/index.js +3 -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/removeFragmentSpreads.d.ts +3 -0
- package/utilities/internal/removeFragmentSpreads.js +11 -0
- package/utilities/internal/removeFragmentSpreads.js.map +1 -0
- package/utilities/internal/toQueryResult.d.ts +2 -2
- package/utilities/internal/toQueryResult.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +96 -0
- package/utilities/internal/types/DocumentationTypes.js +2 -0
- package/utilities/internal/types/DocumentationTypes.js.map +1 -0
- package/utilities/internal/types/NoInfer.d.ts +31 -25
- package/utilities/internal/types/NoInfer.js.map +1 -1
- 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/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/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<{
|
|
@@ -214,26 +214,66 @@ export declare namespace useMutation {
|
|
|
214
214
|
*/
|
|
215
215
|
variables: TVariables;
|
|
216
216
|
}
|
|
217
|
-
]) => Promise<MutateResult<MaybeMasked<TData>>>;
|
|
218
|
-
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache
|
|
217
|
+
]) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
218
|
+
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache>;
|
|
219
|
+
namespace DocumentationTypes {
|
|
219
220
|
/**
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
* @
|
|
223
|
-
*
|
|
224
|
-
*
|
|
221
|
+
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
222
|
+
*
|
|
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
|
+
* @example
|
|
230
|
+
* ```jsx
|
|
231
|
+
* import { gql, useMutation } from "@apollo/client";
|
|
232
|
+
*
|
|
233
|
+
* const ADD_TODO = gql`
|
|
234
|
+
* mutation AddTodo($type: String!) {
|
|
235
|
+
* addTodo(type: $type) {
|
|
236
|
+
* id
|
|
237
|
+
* type
|
|
238
|
+
* }
|
|
239
|
+
* }
|
|
240
|
+
* `;
|
|
241
|
+
*
|
|
242
|
+
* function AddTodo() {
|
|
243
|
+
* let input;
|
|
244
|
+
* const [addTodo, { data }] = useMutation(ADD_TODO);
|
|
245
|
+
*
|
|
246
|
+
* return (
|
|
247
|
+
* <div>
|
|
248
|
+
* <form
|
|
249
|
+
* onSubmit={(e) => {
|
|
250
|
+
* e.preventDefault();
|
|
251
|
+
* addTodo({ variables: { type: input.value } });
|
|
252
|
+
* input.value = "";
|
|
253
|
+
* }}
|
|
254
|
+
* >
|
|
255
|
+
* <input
|
|
256
|
+
* ref={(node) => {
|
|
257
|
+
* input = node;
|
|
258
|
+
* }}
|
|
259
|
+
* />
|
|
260
|
+
* <button type="submit">Add Todo</button>
|
|
261
|
+
* </form>
|
|
262
|
+
* </div>
|
|
263
|
+
* );
|
|
264
|
+
* }
|
|
265
|
+
* ```
|
|
225
266
|
*/
|
|
226
|
-
mutation
|
|
227
|
-
}
|
|
267
|
+
function useMutation<TData = unknown, TVariables extends OperationVariables = OperationVariables>(mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useMutation.Options<TData, TVariables>): useMutation.ResultTuple<TData, TVariables>;
|
|
268
|
+
}
|
|
228
269
|
}
|
|
229
270
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
271
|
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
233
272
|
*
|
|
234
273
|
* @example
|
|
274
|
+
*
|
|
235
275
|
* ```jsx
|
|
236
|
-
* import { gql, useMutation } from
|
|
276
|
+
* import { gql, useMutation } from "@apollo/client";
|
|
237
277
|
*
|
|
238
278
|
* const ADD_TODO = gql`
|
|
239
279
|
* mutation AddTodo($type: String!) {
|
|
@@ -251,14 +291,14 @@ export declare namespace useMutation {
|
|
|
251
291
|
* return (
|
|
252
292
|
* <div>
|
|
253
293
|
* <form
|
|
254
|
-
* onSubmit={e => {
|
|
294
|
+
* onSubmit={(e) => {
|
|
255
295
|
* e.preventDefault();
|
|
256
296
|
* addTodo({ variables: { type: input.value } });
|
|
257
|
-
* input.value =
|
|
297
|
+
* input.value = "";
|
|
258
298
|
* }}
|
|
259
299
|
* >
|
|
260
300
|
* <input
|
|
261
|
-
* ref={node => {
|
|
301
|
+
* ref={(node) => {
|
|
262
302
|
* input = node;
|
|
263
303
|
* }}
|
|
264
304
|
* />
|
|
@@ -268,7 +308,7 @@ export declare namespace useMutation {
|
|
|
268
308
|
* );
|
|
269
309
|
* }
|
|
270
310
|
* ```
|
|
271
|
-
*
|
|
311
|
+
*
|
|
272
312
|
* @param mutation - A GraphQL mutation document parsed into an AST by `gql`.
|
|
273
313
|
* @param options - Options to control how the mutation is executed.
|
|
274
314
|
* @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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AAG,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 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;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AAM,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"]}
|