@apollo/client 3.8.0-alpha.8 → 3.8.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/apollo-client.cjs +1064 -680
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +49 -34
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +49 -34
- package/cache/core/cache.d.ts +5 -4
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js +1 -0
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +2 -2
- package/cache/core/types/Cache.d.ts.map +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +6 -5
- package/cache/core/types/DataProxy.d.ts.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +3 -3
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +5 -5
- package/cache/inmemory/entityStore.d.ts.map +1 -1
- package/cache/inmemory/entityStore.js +2 -2
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.d.ts +1 -1
- package/cache/inmemory/fragmentRegistry.d.ts.map +1 -1
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +6 -5
- package/cache/inmemory/helpers.d.ts.map +1 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +9 -7
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +14 -15
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.d.ts +1 -1
- package/cache/inmemory/key-extractor.d.ts.map +1 -1
- package/cache/inmemory/key-extractor.js +2 -2
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/policies.d.ts +7 -6
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +20 -9
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.d.ts +1 -1
- package/cache/inmemory/reactiveVars.d.ts.map +1 -1
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +6 -6
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +10 -5
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +6 -6
- package/cache/inmemory/types.d.ts.map +1 -1
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +6 -6
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +7 -8
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/config/jest/setup.d.ts +1 -0
- package/config/jest/setup.d.ts.map +1 -1
- package/config/jest/setup.js +3 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.d.ts +15 -12
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +28 -20
- package/core/ApolloClient.js.map +1 -1
- package/core/DocumentTransform.d.ts +24 -0
- package/core/DocumentTransform.d.ts.map +1 -0
- package/core/DocumentTransform.js +68 -0
- package/core/DocumentTransform.js.map +1 -0
- package/core/LocalState.d.ts +7 -9
- package/core/LocalState.d.ts.map +1 -1
- package/core/LocalState.js +6 -10
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +11 -8
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +48 -28
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +9 -9
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +15 -11
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +115 -108
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +342 -176
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +342 -176
- package/core/equalByQuery.d.ts +4 -0
- package/core/equalByQuery.d.ts.map +1 -0
- package/{react/hooks/compareResults.js → core/equalByQuery.js} +14 -10
- package/core/equalByQuery.js.map +1 -0
- package/core/index.d.ts +2 -1
- package/core/index.d.ts.map +1 -1
- package/core/index.js +2 -1
- package/core/index.js.map +1 -1
- package/core/networkStatus.d.ts +1 -0
- package/core/networkStatus.d.ts.map +1 -1
- package/core/networkStatus.js +3 -0
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +14 -14
- package/core/types.d.ts.map +1 -1
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +6 -7
- package/core/watchQueryOptions.d.ts.map +1 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +642 -0
- package/dev/dev.cjs.map +1 -0
- package/dev/dev.cjs.native.js +642 -0
- package/dev/index.d.ts +4 -0
- package/dev/index.d.ts.map +1 -0
- package/dev/index.js +4 -0
- package/dev/index.js.map +1 -0
- package/dev/loadDevMessages.d.ts +2 -0
- package/dev/loadDevMessages.d.ts.map +1 -0
- package/dev/loadDevMessages.js +6 -0
- package/dev/loadDevMessages.js.map +1 -0
- package/dev/loadErrorMessageHandler.d.ts +3 -0
- package/dev/loadErrorMessageHandler.d.ts.map +1 -0
- package/dev/loadErrorMessageHandler.js +26 -0
- package/dev/loadErrorMessageHandler.js.map +1 -0
- package/dev/loadErrorMessages.d.ts +2 -0
- package/dev/loadErrorMessages.d.ts.map +1 -0
- package/dev/loadErrorMessages.js +6 -0
- package/dev/loadErrorMessages.js.map +1 -0
- package/dev/package.json +8 -0
- package/errors/errors.cjs +17 -17
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +17 -17
- package/errors/index.d.ts +26 -10
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +17 -19
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.d.ts +13 -0
- package/invariantErrorCodes.d.ts.map +1 -0
- package/invariantErrorCodes.js +331 -144
- package/invariantErrorCodes.js.map +1 -0
- package/link/batch/batchLink.d.ts +4 -3
- package/link/batch/batchLink.d.ts.map +1 -1
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.d.ts +1 -1
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs +23 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +23 -2
- package/link/batch-http/batchHttpLink.d.ts +3 -2
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +7 -2
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/context/index.d.ts +3 -2
- package/link/context/index.d.ts.map +1 -1
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +3 -2
- package/link/core/ApolloLink.d.ts.map +1 -1
- package/link/core/ApolloLink.js +3 -13
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +2 -12
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +2 -12
- package/link/core/types.d.ts +8 -3
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/error/index.d.ts +4 -3
- package/link/error/index.d.ts.map +1 -1
- package/link/error/index.js.map +1 -1
- package/link/http/HttpLink.d.ts +3 -2
- package/link/http/HttpLink.d.ts.map +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js +2 -2
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.d.ts +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +21 -20
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/http.cjs +73 -43
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +73 -43
- package/link/http/iterators/nodeStream.d.ts +1 -1
- package/link/http/iterators/nodeStream.d.ts.map +1 -1
- package/link/http/iterators/nodeStream.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
- package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +47 -26
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/responseIterator.d.ts +1 -1
- package/link/http/responseIterator.d.ts.map +1 -1
- package/link/http/responseIterator.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +1 -1
- package/link/http/rewriteURIForGET.d.ts.map +1 -1
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +3 -2
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.d.ts +1 -1
- package/link/http/selectURI.d.ts.map +1 -1
- package/link/http/selectURI.js.map +1 -1
- package/link/http/serializeFetchParameter.d.ts +1 -1
- package/link/http/serializeFetchParameter.d.ts.map +1 -1
- package/link/http/serializeFetchParameter.js +2 -2
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.d.ts +4 -3
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +16 -20
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +15 -19
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +15 -19
- package/link/remove-typename/index.d.ts +2 -0
- package/link/remove-typename/index.d.ts.map +1 -0
- package/link/remove-typename/index.js +2 -0
- package/link/remove-typename/index.js.map +1 -0
- package/link/remove-typename/package.json +8 -0
- package/link/remove-typename/remove-typename.cjs +82 -0
- package/link/remove-typename/remove-typename.cjs.map +1 -0
- package/link/remove-typename/remove-typename.cjs.native.js +82 -0
- package/link/remove-typename/removeTypenameFromVariables.d.ts +11 -0
- package/link/remove-typename/removeTypenameFromVariables.d.ts.map +1 -0
- package/link/remove-typename/removeTypenameFromVariables.js +74 -0
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -0
- package/link/retry/delayFunction.d.ts +1 -1
- package/link/retry/delayFunction.d.ts.map +1 -1
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retryFunction.d.ts +1 -1
- package/link/retry/retryFunction.d.ts.map +1 -1
- package/link/retry/retryFunction.js.map +1 -1
- package/link/retry/retryLink.d.ts +4 -3
- package/link/retry/retryLink.d.ts.map +1 -1
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +3 -2
- package/link/schema/index.d.ts.map +1 -1
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.d.ts +2 -1
- package/link/subscriptions/index.d.ts.map +1 -1
- package/link/subscriptions/index.js +8 -3
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +8 -3
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +8 -3
- package/link/utils/createOperation.d.ts +1 -1
- package/link/utils/createOperation.d.ts.map +1 -1
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/filterOperationVariables.d.ts +5 -0
- package/link/utils/filterOperationVariables.d.ts.map +1 -0
- package/link/utils/filterOperationVariables.js +18 -0
- package/link/utils/filterOperationVariables.js.map +1 -0
- package/link/utils/index.d.ts +1 -0
- package/link/utils/index.d.ts.map +1 -1
- package/link/utils/index.js +1 -0
- package/link/utils/index.js.map +1 -1
- package/link/utils/throwServerError.d.ts +1 -1
- package/link/utils/throwServerError.d.ts.map +1 -1
- package/link/utils/throwServerError.js.map +1 -1
- package/link/utils/toPromise.d.ts +1 -1
- package/link/utils/toPromise.d.ts.map +1 -1
- package/link/utils/toPromise.js +1 -1
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/transformOperation.d.ts +1 -1
- package/link/utils/transformOperation.d.ts.map +1 -1
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/utils.cjs +20 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +20 -2
- package/link/utils/validateOperation.d.ts +1 -1
- package/link/utils/validateOperation.d.ts.map +1 -1
- package/link/utils/validateOperation.js +2 -2
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +5 -3
- package/link/ws/index.d.ts.map +1 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +37 -34
- package/react/cache/QueryReference.d.ts +34 -0
- package/react/cache/QueryReference.d.ts.map +1 -0
- package/react/cache/QueryReference.js +107 -0
- package/react/cache/QueryReference.js.map +1 -0
- package/react/cache/SuspenseCache.d.ts +10 -13
- package/react/cache/SuspenseCache.d.ts.map +1 -1
- package/react/cache/SuspenseCache.js +18 -41
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/cache/types.d.ts +2 -0
- package/react/cache/types.d.ts.map +1 -0
- package/react/cache/types.js +2 -0
- package/react/cache/types.js.map +1 -0
- package/react/components/Mutation.d.ts +2 -2
- package/react/components/Mutation.d.ts.map +1 -1
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.d.ts +2 -2
- package/react/components/Query.d.ts.map +1 -1
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.d.ts +2 -2
- package/react/components/Subscription.d.ts.map +1 -1
- package/react/components/Subscription.js.map +1 -1
- package/react/components/types.d.ts +4 -4
- package/react/components/types.d.ts.map +1 -1
- package/react/components/types.js.map +1 -1
- package/react/context/ApolloConsumer.d.ts +1 -1
- package/react/context/ApolloConsumer.d.ts.map +1 -1
- package/react/context/ApolloConsumer.js +2 -3
- package/react/context/ApolloConsumer.js.map +1 -1
- package/react/context/ApolloContext.d.ts +10 -3
- package/react/context/ApolloContext.d.ts.map +1 -1
- package/react/context/ApolloContext.js +10 -8
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.d.ts +2 -2
- package/react/context/ApolloProvider.d.ts.map +1 -1
- package/react/context/ApolloProvider.js +8 -13
- package/react/context/ApolloProvider.js.map +1 -1
- package/react/context/context.cjs +18 -22
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +18 -22
- package/react/context/index.d.ts +1 -1
- package/react/context/index.d.ts.map +1 -1
- package/react/context/index.js +1 -1
- package/react/context/index.js.map +1 -1
- package/react/hoc/graphql.d.ts +3 -3
- package/react/hoc/graphql.d.ts.map +1 -1
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts +2 -2
- package/react/hoc/hoc-utils.d.ts.map +1 -1
- package/react/hoc/hoc-utils.js +2 -3
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs +2 -4
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +2 -4
- package/react/hoc/mutation-hoc.d.ts +4 -4
- package/react/hoc/mutation-hoc.d.ts.map +1 -1
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.d.ts +2 -2
- package/react/hoc/query-hoc.d.ts.map +1 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts +2 -2
- package/react/hoc/subscription-hoc.d.ts.map +1 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/types.d.ts +4 -4
- package/react/hoc/types.d.ts.map +1 -1
- package/react/hoc/types.js.map +1 -1
- package/react/hoc/withApollo.d.ts +1 -1
- package/react/hoc/withApollo.d.ts.map +1 -1
- package/react/hoc/withApollo.js +2 -3
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +226 -216
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +226 -216
- package/react/hooks/index.d.ts +2 -1
- package/react/hooks/index.d.ts.map +1 -1
- package/react/hooks/index.js +2 -1
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/internal/__use.d.ts +4 -0
- package/react/hooks/internal/__use.d.ts.map +1 -0
- package/react/hooks/internal/__use.js +17 -0
- package/react/hooks/internal/__use.js.map +1 -0
- package/react/hooks/internal/index.d.ts +2 -0
- package/react/hooks/internal/index.d.ts.map +1 -1
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.d.ts +1 -1
- package/react/hooks/internal/useDeepMemo.d.ts.map +1 -1
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +2 -2
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts +2 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.d.ts.map +1 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.js +11 -0
- package/react/hooks/internal/useStrictModeSafeCleanupEffect.js.map +1 -0
- package/react/hooks/useApolloClient.d.ts +1 -1
- package/react/hooks/useApolloClient.d.ts.map +1 -1
- package/react/hooks/useApolloClient.js +2 -4
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +18 -0
- package/react/hooks/useBackgroundQuery.d.ts.map +1 -0
- package/react/hooks/useBackgroundQuery.js +69 -0
- package/react/hooks/useBackgroundQuery.js.map +1 -0
- package/react/hooks/useFragment.d.ts +14 -9
- package/react/hooks/useFragment.d.ts.map +1 -1
- package/react/hooks/useFragment.js +2 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +4 -4
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -22
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +4 -4
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +3 -2
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +6 -6
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +30 -29
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReactiveVar.d.ts +1 -1
- package/react/hooks/useReactiveVar.d.ts.map +1 -1
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +4 -4
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +27 -19
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseCache.d.ts +1 -1
- package/react/hooks/useSuspenseCache.d.ts.map +1 -1
- package/react/hooks/useSuspenseCache.js +2 -4
- package/react/hooks/useSuspenseCache.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +39 -7
- package/react/hooks/useSuspenseQuery.d.ts.map +1 -1
- package/react/hooks/useSuspenseQuery.js +68 -144
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.d.ts.map +1 -1
- package/react/index.js +1 -1
- package/react/index.js.map +1 -1
- package/react/parser/index.d.ts +1 -1
- package/react/parser/index.d.ts.map +1 -1
- package/react/parser/index.js +20 -17
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +19 -16
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +19 -16
- package/react/react.cjs +116 -35
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +116 -35
- package/react/ssr/RenderPromises.d.ts +2 -2
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/renderToStringWithData.d.ts +1 -1
- package/react/ssr/renderToStringWithData.d.ts.map +1 -1
- package/react/ssr/renderToStringWithData.js.map +1 -1
- package/react/types/types.d.ts +10 -13
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +1 -1
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +1 -1
- package/testing/core/itAsync.js.map +1 -1
- package/testing/core/mocking/mockClient.d.ts +2 -2
- package/testing/core/mocking/mockClient.d.ts.map +1 -1
- package/testing/core/mocking/mockClient.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +2 -1
- package/testing/core/mocking/mockLink.d.ts.map +1 -1
- package/testing/core/mocking/mockLink.js +3 -3
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +1 -1
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -2
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/testing/core/mocking/mockWatchQuery.d.ts +2 -2
- package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -1
- package/testing/core/mocking/mockWatchQuery.js.map +1 -1
- package/testing/core/observableToPromise.d.ts +2 -2
- package/testing/core/observableToPromise.d.ts.map +1 -1
- package/testing/core/observableToPromise.js.map +1 -1
- package/testing/core/subscribeAndCount.d.ts +1 -1
- package/testing/core/subscribeAndCount.d.ts.map +1 -1
- package/testing/core/subscribeAndCount.js.map +1 -1
- package/testing/matchers/index.d.ts +2 -0
- package/testing/matchers/index.d.ts.map +1 -0
- package/testing/matchers/index.js +6 -0
- package/testing/matchers/index.js.map +1 -0
- package/testing/matchers/toMatchDocument.d.ts +4 -0
- package/testing/matchers/toMatchDocument.d.ts.map +1 -0
- package/testing/matchers/toMatchDocument.js +34 -0
- package/testing/matchers/toMatchDocument.js.map +1 -0
- package/testing/react/MockedProvider.d.ts +8 -7
- package/testing/react/MockedProvider.d.ts.map +1 -1
- package/testing/react/MockedProvider.js +7 -6
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +7 -51
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +7 -51
- package/utilities/common/compact.d.ts +1 -1
- package/utilities/common/compact.d.ts.map +1 -1
- package/utilities/common/compact.js.map +1 -1
- package/utilities/common/errorHandling.d.ts +1 -1
- package/utilities/common/errorHandling.d.ts.map +1 -1
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.d.ts +2 -1
- package/utilities/common/incrementalResult.d.ts.map +1 -1
- package/utilities/common/incrementalResult.js +4 -0
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.d.ts.map +1 -1
- package/utilities/common/mergeOptions.js +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/common/objects.d.ts +1 -0
- package/utilities/common/objects.d.ts.map +1 -1
- package/utilities/common/objects.js +6 -0
- package/utilities/common/objects.js.map +1 -1
- package/utilities/common/omitDeep.d.ts +3 -0
- package/utilities/common/omitDeep.d.ts.map +1 -0
- package/utilities/common/omitDeep.js +41 -0
- package/utilities/common/omitDeep.js.map +1 -0
- package/utilities/common/responseIterator.d.ts +2 -2
- package/utilities/common/responseIterator.d.ts.map +1 -1
- package/utilities/common/responseIterator.js.map +1 -1
- package/utilities/common/stringifyForDisplay.d.ts +1 -1
- package/utilities/common/stringifyForDisplay.d.ts.map +1 -1
- package/utilities/common/stringifyForDisplay.js +3 -2
- package/utilities/common/stringifyForDisplay.js.map +1 -1
- package/utilities/common/stripTypename.d.ts +2 -0
- package/utilities/common/stripTypename.d.ts.map +1 -0
- package/utilities/common/stripTypename.js +5 -0
- package/utilities/common/stripTypename.js.map +1 -0
- package/utilities/globals/global.d.ts +6 -3
- package/utilities/globals/global.d.ts.map +1 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +67 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +67 -1
- package/utilities/globals/index.d.ts +2 -2
- package/utilities/globals/index.d.ts.map +1 -1
- package/utilities/globals/index.js +2 -2
- package/utilities/globals/index.js.map +1 -1
- package/utilities/globals/invariantWrappers.d.ts +24 -0
- package/utilities/globals/invariantWrappers.d.ts.map +1 -0
- package/utilities/globals/invariantWrappers.js +53 -0
- package/utilities/globals/invariantWrappers.js.map +1 -0
- package/utilities/graphql/directives.d.ts +1 -1
- package/utilities/graphql/directives.d.ts.map +1 -1
- package/utilities/graphql/directives.js +6 -7
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js +8 -5
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts +1 -1
- package/utilities/graphql/getFromAST.d.ts.map +1 -1
- package/utilities/graphql/getFromAST.js +16 -12
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/operations.d.ts +5 -0
- package/utilities/graphql/operations.d.ts.map +1 -0
- package/utilities/graphql/operations.js +16 -0
- package/utilities/graphql/operations.js.map +1 -0
- package/utilities/graphql/storeUtils.d.ts +2 -2
- package/utilities/graphql/storeUtils.d.ts.map +1 -1
- package/utilities/graphql/storeUtils.js +16 -7
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js +30 -21
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +6 -0
- package/utilities/index.d.ts.map +1 -1
- package/utilities/index.js +4 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +2 -1
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/Observable.d.ts +2 -1
- package/utilities/observables/Observable.d.ts.map +1 -1
- package/utilities/observables/Observable.js +1 -1
- package/utilities/observables/Observable.js.map +1 -1
- package/utilities/observables/asyncMap.d.ts.map +1 -1
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/observables/iteration.d.ts +1 -1
- package/utilities/observables/iteration.d.ts.map +1 -1
- package/utilities/observables/iteration.js.map +1 -1
- package/utilities/policies/pagination.d.ts +1 -1
- package/utilities/policies/pagination.d.ts.map +1 -1
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/promises/decoration.d.ts +17 -0
- package/utilities/promises/decoration.d.ts.map +1 -0
- package/utilities/promises/decoration.js +37 -0
- package/utilities/promises/decoration.js.map +1 -0
- package/utilities/types/DeepOmit.d.ts +10 -0
- package/utilities/types/DeepOmit.d.ts.map +1 -0
- package/utilities/types/DeepOmit.js +2 -0
- package/utilities/types/DeepOmit.js.map +1 -0
- package/utilities/types/DeepPartial.d.ts +12 -0
- package/utilities/types/DeepPartial.d.ts.map +1 -0
- package/utilities/types/DeepPartial.js +2 -0
- package/utilities/types/DeepPartial.js.map +1 -0
- package/utilities/types/Primitive.d.ts +2 -0
- package/utilities/types/Primitive.d.ts.map +1 -0
- package/utilities/types/Primitive.js +2 -0
- package/utilities/types/Primitive.js.map +1 -0
- package/utilities/utilities.cjs +188 -48
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +188 -48
- package/version.js +1 -1
- package/cache/inmemory/__mocks__/optimism.d.ts +0 -2
- package/cache/inmemory/__mocks__/optimism.d.ts.map +0 -1
- package/cache/inmemory/__mocks__/optimism.js +0 -14
- package/cache/inmemory/__mocks__/optimism.js.map +0 -1
- package/react/hooks/compareResults.d.ts +0 -3
- package/react/hooks/compareResults.d.ts.map +0 -1
- package/react/hooks/compareResults.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ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AAU,SAAS,kBAAkB;IAErC,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IAC3D,OAAO,EAAE,wBAAwB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;CACtD;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EACL,UAAU,SAAS,kBAAkB,EACrC,EACA,KAAK,EACL,OAAO,GACR,EAAE,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,GAAG,iBAAiB,CACvE,UAAU,EACV,KAAK,CACN,CAgBA"}
|
|
@@ -1,181 +1,105 @@
|
|
|
1
|
-
import { __assign
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
2
|
import { invariant, __DEV__ } from "../../utilities/globals/index.js";
|
|
3
|
-
import { useRef,
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { compact, isNonEmptyArray, hasDirectives, } from "../../utilities/index.js";
|
|
3
|
+
import { useRef, useCallback, useMemo, useEffect, useState } from 'react';
|
|
4
|
+
import { ApolloError } from "../../core/index.js";
|
|
5
|
+
import { isNonEmptyArray } from "../../utilities/index.js";
|
|
7
6
|
import { useApolloClient } from "./useApolloClient.js";
|
|
8
7
|
import { DocumentType, verifyDocumentType } from "../parser/index.js";
|
|
9
|
-
import { useDeepMemo,
|
|
8
|
+
import { useDeepMemo, useStrictModeSafeCleanupEffect, __use } from "./internal/index.js";
|
|
10
9
|
import { useSuspenseCache } from "./useSuspenseCache.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
'cache-first',
|
|
14
|
-
'network-only',
|
|
15
|
-
'no-cache',
|
|
16
|
-
'cache-and-network',
|
|
17
|
-
];
|
|
18
|
-
var DEFAULT_FETCH_POLICY = 'cache-first';
|
|
19
|
-
var DEFAULT_SUSPENSE_POLICY = 'always';
|
|
20
|
-
var DEFAULT_ERROR_POLICY = 'none';
|
|
21
|
-
export function useSuspenseQuery_experimental(query, options) {
|
|
10
|
+
import { canonicalStringify } from "../../cache/index.js";
|
|
11
|
+
export function useSuspenseQuery(query, options) {
|
|
22
12
|
if (options === void 0) { options = Object.create(null); }
|
|
23
|
-
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
24
13
|
var client = useApolloClient(options.client);
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
var
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
return
|
|
32
|
-
})
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (result.error &&
|
|
39
|
-
(result.error.networkError || allowsThrownErrors)) {
|
|
40
|
-
throw result.error;
|
|
41
|
-
}
|
|
42
|
-
if (result.loading) {
|
|
43
|
-
if (!cacheEntry) {
|
|
44
|
-
cacheEntry = suspenseCache.add(query, variables, {
|
|
45
|
-
promise: maybeWrapConcastWithCustomPromise(observable.reobserveAsConcast(watchQueryOptions), { deferred: deferred }),
|
|
46
|
-
observable: observable,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
var hasUsableResult = usePartialResult ||
|
|
50
|
-
(fetchPolicy === 'cache-and-network' && hasFullResult);
|
|
51
|
-
if (!hasUsableResult && !cacheEntry.fulfilled) {
|
|
52
|
-
throw cacheEntry.promise;
|
|
53
|
-
}
|
|
14
|
+
var suspenseCache = useSuspenseCache(options.suspenseCache);
|
|
15
|
+
var watchQueryOptions = useWatchQueryOptions({ query: query, options: options });
|
|
16
|
+
var variables = watchQueryOptions.variables;
|
|
17
|
+
var _a = options.queryKey, queryKey = _a === void 0 ? [] : _a;
|
|
18
|
+
var cacheKey = [client, query, canonicalStringify(variables)].concat(queryKey);
|
|
19
|
+
var queryRef = suspenseCache.getQueryRef(cacheKey, function () {
|
|
20
|
+
return client.watchQuery(watchQueryOptions);
|
|
21
|
+
});
|
|
22
|
+
var _b = useState(function () { return new Map([[queryRef.key, queryRef.promise]]); }), promiseCache = _b[0], setPromiseCache = _b[1];
|
|
23
|
+
var promise = promiseCache.get(queryRef.key);
|
|
24
|
+
if (!promise) {
|
|
25
|
+
promise = queryRef.promise;
|
|
26
|
+
promiseCache.set(queryRef.key, promise);
|
|
54
27
|
}
|
|
28
|
+
useTrackedQueryRefs(queryRef);
|
|
55
29
|
useEffect(function () {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
suspenseCache.remove(previousOpts.query, previousOpts.variables);
|
|
60
|
-
suspenseCache.add(query, variables, {
|
|
61
|
-
promise: observable.reobserve({ query: query, variables: variables }),
|
|
62
|
-
observable: observable,
|
|
30
|
+
return queryRef.listen(function (promise) {
|
|
31
|
+
setPromiseCache(function (promiseCache) {
|
|
32
|
+
return new Map(promiseCache).set(queryRef.key, promise);
|
|
63
33
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
34
|
+
});
|
|
35
|
+
}, [queryRef]);
|
|
36
|
+
var result = __use(promise);
|
|
37
|
+
var fetchMore = useCallback(function (options) {
|
|
38
|
+
var promise = queryRef.fetchMore(options);
|
|
39
|
+
setPromiseCache(function (previousPromiseCache) {
|
|
40
|
+
return new Map(previousPromiseCache).set(queryRef.key, promise);
|
|
41
|
+
});
|
|
42
|
+
return promise;
|
|
43
|
+
}, [queryRef]);
|
|
44
|
+
var refetch = useCallback(function (variables) {
|
|
45
|
+
var promise = queryRef.refetch(variables);
|
|
46
|
+
setPromiseCache(function (previousPromiseCache) {
|
|
47
|
+
return new Map(previousPromiseCache).set(queryRef.key, promise);
|
|
48
|
+
});
|
|
49
|
+
return promise;
|
|
50
|
+
}, [queryRef]);
|
|
51
|
+
var subscribeToMore = useCallback(function (options) { return queryRef.observable.subscribeToMore(options); }, [queryRef]);
|
|
72
52
|
return useMemo(function () {
|
|
73
53
|
return {
|
|
74
54
|
client: client,
|
|
75
55
|
data: result.data,
|
|
76
|
-
error:
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
observable: observable,
|
|
82
|
-
});
|
|
83
|
-
return promise;
|
|
84
|
-
},
|
|
85
|
-
refetch: function (variables) {
|
|
86
|
-
var promise = observable.refetch(variables);
|
|
87
|
-
suspenseCache.add(query, watchQueryOptions.variables, {
|
|
88
|
-
promise: promise,
|
|
89
|
-
observable: observable,
|
|
90
|
-
});
|
|
91
|
-
return promise;
|
|
92
|
-
},
|
|
93
|
-
subscribeToMore: function (options) { return observable.subscribeToMore(options); },
|
|
56
|
+
error: toApolloError(result),
|
|
57
|
+
networkStatus: result.networkStatus,
|
|
58
|
+
fetchMore: fetchMore,
|
|
59
|
+
refetch: refetch,
|
|
60
|
+
subscribeToMore: subscribeToMore,
|
|
94
61
|
};
|
|
95
|
-
}, [client,
|
|
62
|
+
}, [client, fetchMore, refetch, result, subscribeToMore]);
|
|
96
63
|
}
|
|
97
64
|
function validateOptions(options) {
|
|
98
|
-
var query = options.query,
|
|
65
|
+
var query = options.query, fetchPolicy = options.fetchPolicy, returnPartialData = options.returnPartialData;
|
|
99
66
|
verifyDocumentType(query, DocumentType.Query);
|
|
100
67
|
validateFetchPolicy(fetchPolicy);
|
|
101
68
|
validatePartialDataReturn(fetchPolicy, returnPartialData);
|
|
102
69
|
}
|
|
103
70
|
function validateFetchPolicy(fetchPolicy) {
|
|
104
|
-
|
|
71
|
+
if (fetchPolicy === void 0) { fetchPolicy = 'cache-first'; }
|
|
72
|
+
var supportedFetchPolicies = [
|
|
73
|
+
'cache-first',
|
|
74
|
+
'network-only',
|
|
75
|
+
'no-cache',
|
|
76
|
+
'cache-and-network',
|
|
77
|
+
];
|
|
78
|
+
invariant(supportedFetchPolicies.includes(fetchPolicy), 57, fetchPolicy);
|
|
105
79
|
}
|
|
106
80
|
function validatePartialDataReturn(fetchPolicy, returnPartialData) {
|
|
107
81
|
if (fetchPolicy === 'no-cache' && returnPartialData) {
|
|
108
|
-
__DEV__ && invariant.warn(
|
|
82
|
+
__DEV__ && invariant.warn(58);
|
|
109
83
|
}
|
|
110
84
|
}
|
|
111
|
-
function toApolloError(result) {
|
|
85
|
+
export function toApolloError(result) {
|
|
112
86
|
return isNonEmptyArray(result.errors)
|
|
113
87
|
? new ApolloError({ graphQLErrors: result.errors })
|
|
114
88
|
: result.error;
|
|
115
89
|
}
|
|
116
|
-
function
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
resolve(value);
|
|
123
|
-
subscription.unsubscribe();
|
|
124
|
-
},
|
|
125
|
-
error: reject,
|
|
126
|
-
});
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
return concast.promise;
|
|
90
|
+
export function useTrackedQueryRefs(queryRef) {
|
|
91
|
+
var trackedQueryRefs = useRef(new Set());
|
|
92
|
+
trackedQueryRefs.current.add(queryRef);
|
|
93
|
+
useStrictModeSafeCleanupEffect(function () {
|
|
94
|
+
trackedQueryRefs.current.forEach(function (sub) { return sub.dispose(); });
|
|
95
|
+
});
|
|
130
96
|
}
|
|
131
|
-
function useWatchQueryOptions(_a) {
|
|
132
|
-
var query = _a.query, options = _a.options
|
|
133
|
-
var
|
|
134
|
-
var watchQueryOptions = useDeepMemo(function () {
|
|
135
|
-
var errorPolicy = options.errorPolicy, fetchPolicy = options.fetchPolicy, _a = options.suspensePolicy, suspensePolicy = _a === void 0 ? DEFAULT_SUSPENSE_POLICY : _a, variables = options.variables, watchQueryOptions = __rest(options, ["errorPolicy", "fetchPolicy", "suspensePolicy", "variables"]);
|
|
136
|
-
return __assign(__assign({}, watchQueryOptions), { query: query, errorPolicy: errorPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.errorPolicy) || DEFAULT_ERROR_POLICY, fetchPolicy: fetchPolicy || (defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.fetchPolicy) || DEFAULT_FETCH_POLICY, notifyOnNetworkStatusChange: suspensePolicy === 'always', fetchOnFirstSubscribe: false, variables: compact(__assign(__assign({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions.variables), variables)) });
|
|
137
|
-
}, [options, query, defaultOptions]);
|
|
97
|
+
export function useWatchQueryOptions(_a) {
|
|
98
|
+
var query = _a.query, options = _a.options;
|
|
99
|
+
var watchQueryOptions = useDeepMemo(function () { return (__assign(__assign({}, options), { query: query, notifyOnNetworkStatusChange: false, nextFetchPolicy: void 0 })); }, [options, query]);
|
|
138
100
|
if (__DEV__) {
|
|
139
101
|
validateOptions(watchQueryOptions);
|
|
140
102
|
}
|
|
141
103
|
return watchQueryOptions;
|
|
142
104
|
}
|
|
143
|
-
function useIsDeferred(query) {
|
|
144
|
-
return useMemo(function () { return hasDirectives(['defer'], query); }, [query]);
|
|
145
|
-
}
|
|
146
|
-
function useObservableQueryResult(observable) {
|
|
147
|
-
var resultRef = useRef();
|
|
148
|
-
var isMountedRef = useRef(false);
|
|
149
|
-
if (!resultRef.current) {
|
|
150
|
-
resultRef.current = observable.getCurrentResult();
|
|
151
|
-
}
|
|
152
|
-
useIsomorphicLayoutEffect(function () {
|
|
153
|
-
isMountedRef.current = true;
|
|
154
|
-
return function () {
|
|
155
|
-
isMountedRef.current = false;
|
|
156
|
-
};
|
|
157
|
-
}, []);
|
|
158
|
-
return useSyncExternalStore(useCallback(function (forceUpdate) {
|
|
159
|
-
function handleUpdate() {
|
|
160
|
-
var previousResult = resultRef.current;
|
|
161
|
-
var result = observable.getCurrentResult();
|
|
162
|
-
if (previousResult.loading === result.loading &&
|
|
163
|
-
previousResult.networkStatus === result.networkStatus &&
|
|
164
|
-
equal(previousResult.data, result.data)) {
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
resultRef.current = result;
|
|
168
|
-
if (isMountedRef.current) {
|
|
169
|
-
forceUpdate();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
var subscription = observable.subscribe({
|
|
173
|
-
next: handleUpdate,
|
|
174
|
-
error: handleUpdate,
|
|
175
|
-
});
|
|
176
|
-
return function () {
|
|
177
|
-
subscription.unsubscribe();
|
|
178
|
-
};
|
|
179
|
-
}, [observable]), function () { return resultRef.current; }, function () { return resultRef.current; });
|
|
180
|
-
}
|
|
181
105
|
//# sourceMappingURL=useSuspenseQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC1E,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAEL,WAAW,GAQZ,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,OAAO,EAEP,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAK7D,OAAO,EAAE,WAAW,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAc9D,IAAM,wBAAwB,GAA4B;IACxD,aAAa;IACb,cAAc;IACd,UAAU;IACV,mBAAmB;CACpB,CAAC;AAEF,IAAM,oBAAoB,GAAG,aAAa,CAAC;AAC3C,IAAM,uBAAuB,GAAG,QAAQ,CAAC;AACzC,IAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC,MAAM,UAAU,6BAA6B,CAI3C,KAA0D,EAC1D,OAA0E;IAA1E,wBAAA,EAAA,UAAuD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAE1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;QAE5B,OAAO;YACL,YAAY,CAAC,OAAO,GAAG,KAAK,CAAC;QAC/B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,oBAAoB,CACzB,WAAW,CACT,UAAC,WAAW;QACV,SAAS,YAAY;YACnB,IAAM,cAAc,GAAG,SAAS,CAAC,OAAQ,CAAC;YAC1C,IAAM,MAAM,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC;YAE7C,IACE,cAAc,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO;gBACzC,cAAc,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa;gBACrD,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,EACvC;gBACA,OAAO;aACR;YAED,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;YAE3B,IAAI,YAAY,CAAC,OAAO,EAAE;gBACxB,WAAW,EAAE,CAAC;aACf;QACH,CAAC;QAED,IAAM,YAAY,GAAG,UAAU,CAAC,SAAS,CAAC;YACxC,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,YAAY;SACpB,CAAC,CAAC;QAEH,OAAO;YACL,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,UAAU,CAAC,CACb,EACD,cAAM,OAAA,SAAS,CAAC,OAAQ,EAAlB,CAAkB,EACxB,cAAM,OAAA,SAAS,CAAC,OAAQ,EAAlB,CAAkB,CACzB,CAAC;AACJ,CAAC","sourcesContent":["import { invariant, __DEV__ } from '../../utilities/globals';\nimport { useRef, useEffect, useCallback, useMemo, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport {\n ApolloClient,\n ApolloError,\n ApolloQueryResult,\n DocumentNode,\n ObservableQuery,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n WatchQueryFetchPolicy,\n} from '../../core';\nimport {\n compact,\n Concast,\n isNonEmptyArray,\n hasDirectives,\n} from '../../utilities';\nimport { useApolloClient } from './useApolloClient';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport {\n SuspenseQueryHookOptions,\n ObservableQueryFields,\n} from '../types/types';\nimport { useDeepMemo, useIsomorphicLayoutEffect } from './internal';\nimport { useSuspenseCache } from './useSuspenseCache';\nimport { useSyncExternalStore } from './useSyncExternalStore';\n\nexport interface UseSuspenseQueryResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables\n> {\n client: ApolloClient<any>;\n data: TData;\n error: ApolloError | undefined;\n fetchMore: ObservableQueryFields<TData, TVariables>['fetchMore'];\n refetch: ObservableQueryFields<TData, TVariables>['refetch'];\n subscribeToMore: ObservableQueryFields<TData, TVariables>['subscribeToMore'];\n}\n\nconst SUPPORTED_FETCH_POLICIES: WatchQueryFetchPolicy[] = [\n 'cache-first',\n 'network-only',\n 'no-cache',\n 'cache-and-network',\n];\n\nconst DEFAULT_FETCH_POLICY = 'cache-first';\nconst DEFAULT_SUSPENSE_POLICY = 'always';\nconst DEFAULT_ERROR_POLICY = 'none';\n\nexport function useSuspenseQuery_experimental<\n TData = any,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SuspenseQueryHookOptions<TData, TVariables> = Object.create(null)\n): UseSuspenseQueryResult<TData, TVariables> {\n const suspenseCache = useSuspenseCache(options.suspenseCache);\n const client = useApolloClient(options.client);\n const watchQueryOptions = useWatchQueryOptions({ query, options, client });\n const previousWatchQueryOptionsRef = useRef(watchQueryOptions);\n const deferred = useIsDeferred(query);\n\n const { fetchPolicy, errorPolicy, returnPartialData, variables } =\n watchQueryOptions;\n\n let cacheEntry = suspenseCache.lookup(query, variables);\n\n const [observable] = useState(() => {\n return cacheEntry?.observable || client.watchQuery(watchQueryOptions);\n });\n\n const result = useObservableQueryResult(observable);\n\n const hasFullResult = result.data && !result.partial;\n const hasPartialResult = result.data && result.partial;\n const usePartialResult = returnPartialData && hasPartialResult;\n\n const allowsThrownErrors =\n // If we've got a deferred query that errors on an incremental chunk, we\n // will have a partial result before the error is collected. We do not want\n // to throw errors that have been returned from incremental chunks. Instead\n // we offload those errors to the `error` property.\n errorPolicy === 'none' && (!deferred || !hasPartialResult);\n\n if (\n result.error &&\n // Always throw network errors regardless of the error policy\n (result.error.networkError || allowsThrownErrors)\n ) {\n throw result.error;\n }\n\n if (result.loading) {\n // If we don't have a cache entry, but we are in a loading state, we are on\n // the first run of the hook. Kick off a network request so we can suspend\n // immediately\n if (!cacheEntry) {\n cacheEntry = suspenseCache.add(query, variables, {\n promise: maybeWrapConcastWithCustomPromise(\n observable.reobserveAsConcast(watchQueryOptions),\n { deferred }\n ),\n observable,\n });\n }\n\n const hasUsableResult =\n // When we have partial data in the cache, a network request will be kicked\n // off to load the full set of data. Avoid suspending when the request is\n // in flight to return the partial data immediately.\n usePartialResult ||\n // `cache-and-network` kicks off a network request even with a full set of\n // data in the cache, which means the loading state will be set to `true`.\n // Avoid suspending in this case.\n (fetchPolicy === 'cache-and-network' && hasFullResult);\n\n if (!hasUsableResult && !cacheEntry.fulfilled) {\n throw cacheEntry.promise;\n }\n }\n\n useEffect(() => {\n const { variables, query } = watchQueryOptions;\n const previousOpts = previousWatchQueryOptionsRef.current;\n\n if (variables !== previousOpts.variables || query !== previousOpts.query) {\n suspenseCache.remove(previousOpts.query, previousOpts.variables);\n\n suspenseCache.add(query, variables, {\n promise: observable.reobserve({ query, variables }),\n observable,\n });\n\n previousWatchQueryOptionsRef.current = watchQueryOptions;\n }\n }, [watchQueryOptions]);\n\n useEffect(() => {\n return () => {\n suspenseCache.remove(query, variables);\n };\n }, []);\n\n return useMemo(() => {\n return {\n client,\n data: result.data,\n error: errorPolicy === 'ignore' ? void 0 : toApolloError(result),\n fetchMore: (options) => {\n const promise = observable.fetchMore(options);\n\n suspenseCache.add(query, watchQueryOptions.variables, {\n promise,\n observable,\n });\n\n return promise;\n },\n refetch: (variables?: Partial<TVariables>) => {\n const promise = observable.refetch(variables);\n\n suspenseCache.add(query, watchQueryOptions.variables, {\n promise,\n observable,\n });\n\n return promise;\n },\n subscribeToMore: (options) => observable.subscribeToMore(options),\n };\n }, [client, result, observable, errorPolicy]);\n}\n\nfunction validateOptions(options: WatchQueryOptions) {\n const {\n query,\n fetchPolicy = DEFAULT_FETCH_POLICY,\n returnPartialData,\n } = options;\n\n verifyDocumentType(query, DocumentType.Query);\n validateFetchPolicy(fetchPolicy);\n validatePartialDataReturn(fetchPolicy, returnPartialData);\n}\n\nfunction validateFetchPolicy(fetchPolicy: WatchQueryFetchPolicy) {\n invariant(\n SUPPORTED_FETCH_POLICIES.includes(fetchPolicy),\n `The fetch policy \\`${fetchPolicy}\\` is not supported with suspense.`\n );\n}\n\nfunction validatePartialDataReturn(\n fetchPolicy: WatchQueryFetchPolicy,\n returnPartialData: boolean | undefined\n) {\n if (fetchPolicy === 'no-cache' && returnPartialData) {\n invariant.warn(\n 'Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.'\n );\n }\n}\n\nfunction toApolloError(result: ApolloQueryResult<any>) {\n return isNonEmptyArray(result.errors)\n ? new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nfunction maybeWrapConcastWithCustomPromise<TData>(\n concast: Concast<ApolloQueryResult<TData>>,\n { deferred }: { deferred: boolean }\n): Promise<ApolloQueryResult<TData>> {\n if (deferred) {\n return new Promise((resolve, reject) => {\n // Unlike `concast.promise`, we want to resolve the promise on the initial\n // chunk of the deferred query. This allows the component to unsuspend\n // when we get the initial set of data, rather than waiting until all\n // chunks have been loaded.\n const subscription = concast.subscribe({\n next: (value) => {\n resolve(value);\n subscription.unsubscribe();\n },\n error: reject,\n });\n });\n }\n\n return concast.promise;\n}\n\ninterface UseWatchQueryOptionsHookOptions<\n TData,\n TVariables extends OperationVariables\n> {\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n options: SuspenseQueryHookOptions<TData, TVariables>;\n client: ApolloClient<any>;\n}\n\nfunction useWatchQueryOptions<TData, TVariables extends OperationVariables>({\n query,\n options,\n client,\n}: UseWatchQueryOptionsHookOptions<TData, TVariables>): WatchQueryOptions<\n TVariables,\n TData\n> {\n const { watchQuery: defaultOptions } = client.defaultOptions;\n\n const watchQueryOptions = useDeepMemo<\n WatchQueryOptions<TVariables, TData>\n >(() => {\n const {\n errorPolicy,\n fetchPolicy,\n suspensePolicy = DEFAULT_SUSPENSE_POLICY,\n variables,\n ...watchQueryOptions\n } = options;\n\n return {\n ...watchQueryOptions,\n query,\n errorPolicy:\n errorPolicy || defaultOptions?.errorPolicy || DEFAULT_ERROR_POLICY,\n fetchPolicy:\n fetchPolicy || defaultOptions?.fetchPolicy || DEFAULT_FETCH_POLICY,\n notifyOnNetworkStatusChange: suspensePolicy === 'always',\n // By default, `ObservableQuery` will run `reobserve` the first time\n // something `subscribe`s to the observable, which kicks off a network\n // request. This creates a problem for suspense because we need to begin\n // fetching the data immediately so we can throw the promise on the first\n // render. Since we don't subscribe until after we've unsuspended, we need\n // to avoid kicking off another network request for the same data we just\n // fetched. This option toggles that behavior off to avoid the `reobserve`\n // when the observable is first subscribed to.\n fetchOnFirstSubscribe: false,\n variables: compact({ ...defaultOptions?.variables, ...variables }),\n };\n }, [options, query, defaultOptions]);\n\n if (__DEV__) {\n validateOptions(watchQueryOptions);\n }\n\n return watchQueryOptions;\n}\n\nfunction useIsDeferred(query: DocumentNode) {\n return useMemo(() => hasDirectives(['defer'], query), [query]);\n}\n\nfunction useObservableQueryResult<TData>(observable: ObservableQuery<TData>) {\n const resultRef = useRef<ApolloQueryResult<TData>>();\n const isMountedRef = useRef(false);\n\n if (!resultRef.current) {\n resultRef.current = observable.getCurrentResult();\n }\n\n // React keeps refs and effects from useSyncExternalStore around after the\n // component initially mounts even if the component re-suspends. We need to\n // track when the component suspends/unsuspends to ensure we don't try and\n // update the component while its suspended since the observable's\n // `next` function is called before the promise resolved.\n //\n // Unlike useEffect, useLayoutEffect will run its cleanup and initialization\n // functions each time a component is suspended.\n useIsomorphicLayoutEffect(() => {\n isMountedRef.current = true;\n\n return () => {\n isMountedRef.current = false;\n };\n }, []);\n\n return useSyncExternalStore(\n useCallback(\n (forceUpdate) => {\n function handleUpdate() {\n const previousResult = resultRef.current!;\n const result = observable.getCurrentResult();\n\n if (\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n resultRef.current = result;\n\n if (isMountedRef.current) {\n forceUpdate();\n }\n }\n\n const subscription = observable.subscribe({\n next: handleUpdate,\n error: handleUpdate,\n });\n\n return () => {\n subscription.unsubscribe();\n };\n },\n [observable]\n ),\n () => resultRef.current!,\n () => resultRef.current!\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAY1E,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAM7D,OAAO,EAAE,WAAW,EAAE,8BAA8B,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAiGjD,MAAM,UAAU,gBAAgB,CAI9B,KAA0D,EAC1D,OAGuB;IAHvB,wBAAA,EAAA,UAGI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAEvB,IAAM,M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;IAE3D,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEvC,8BAA8B,CAAC;QAC7B,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,UAAC,GAAG,IAAK,OAAA,GAAG,CAAC,OAAO,EAAE,EAAb,CAAa,CAAC,CAAC;IAC3D,CAAC,CAAC,CAAC;AACL,CAAC;AAUD,MAAM,UAAU,oBAAoB,CAGlC,EAGmD;QAFnD,KAAK,WAAA,EACL,OAAO,aAAA;IAKP,IAAM,iBAAiB,GAAG,WAAW,CACnC,cAAM,OAAA,uBACD,OAAO,KACV,KAAK,OAAA,EACL,2BAA2B,EAAE,KAAK,EAClC,eAAe,EAAE,KAAK,CAAC,IACvB,EALI,CAKJ,EACF,CAAC,OAAO,EAAE,KAAK,CAAC,CACjB,CAAC;IAEF,IAAI,OAAO,EAAE;QACX,eAAe,CAAC,iBAAiB,CAAC,CAAC;KACpC;IAED,OAAO,iBAAiB,CAAC;AAC3B,CAAC","sourcesContent":["import { invariant, __DEV__ } from '../../utilities/globals';\nimport { useRef, useCallback, useMemo, useEffect, useState } from 'react';\nimport type {\n ApolloClient,\n ApolloQueryResult,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n WatchQueryFetchPolicy,\n NetworkStatus,\n FetchMoreQueryOptions,\n} from '../../core';\nimport { ApolloError } from '../../core';\nimport type { DeepPartial } from '../../utilities';\nimport { isNonEmptyArray } from '../../utilities';\nimport { useApolloClient } from './useApolloClient';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport type {\n SuspenseQueryHookOptions,\n ObservableQueryFields,\n NoInfer,\n} from '../types/types';\nimport { useDeepMemo, useStrictModeSafeCleanupEffect, __use } from './internal';\nimport { useSuspenseCache } from './useSuspenseCache';\nimport type { QueryReference } from '../cache/QueryReference';\nimport { canonicalStringify } from '../../cache';\n\nexport interface UseSuspenseQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n> {\n client: ApolloClient<any>;\n data: TData;\n error: ApolloError | undefined;\n fetchMore: FetchMoreFunction<TData, TVariables>;\n networkStatus: NetworkStatus;\n refetch: RefetchFunction<TData, TVariables>;\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n}\n\nexport type FetchMoreFunction<TData, TVariables extends OperationVariables> = (\n fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> & {\n updateQuery?: (\n previousQueryResult: TData,\n options: {\n fetchMoreResult: TData;\n variables: TVariables;\n }\n ) => TData;\n }\n) => Promise<ApolloQueryResult<TData>>;\n\nexport type RefetchFunction<\n TData,\n TVariables extends OperationVariables\n> = ObservableQueryFields<TData, TVariables>['refetch'];\n\nexport type SubscribeToMoreFunction<\n TData,\n TVariables extends OperationVariables\n> = ObservableQueryFields<TData, TVariables>['subscribeToMore'];\n\nexport type Version = 'main' | 'network';\n\nexport function useSuspenseQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<SuspenseQueryHookOptions<TData>, 'variables'>\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SuspenseQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> &\n TOptions\n): UseSuspenseQueryResult<\n TOptions['errorPolicy'] extends 'ignore' | 'all'\n ? TOptions['returnPartialData'] extends true\n ? DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions['returnPartialData'] extends true\n ? DeepPartial<TData>\n : TData,\n TVariables\n>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SuspenseQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> & {\n returnPartialData: true;\n errorPolicy: 'ignore' | 'all';\n }\n): UseSuspenseQueryResult<DeepPartial<TData> | undefined, TVariables>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SuspenseQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> & {\n errorPolicy: 'ignore' | 'all';\n }\n): UseSuspenseQueryResult<TData | undefined, TVariables>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SuspenseQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>> & {\n returnPartialData: true;\n }\n): UseSuspenseQueryResult<DeepPartial<TData>, TVariables>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SuspenseQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n): UseSuspenseQueryResult<TData, TVariables>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SuspenseQueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): UseSuspenseQueryResult<TData, TVariables> {\n const client = useApolloClient(options.client);\n const suspenseCache = useSuspenseCache(options.suspenseCache);\n const watchQueryOptions = useWatchQueryOptions({ query, options });\n const { variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n const cacheKey = (\n [client, query, canonicalStringify(variables)] as any[]\n ).concat(queryKey);\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions)\n );\n\n const [promiseCache, setPromiseCache] = useState(\n () => new Map([[queryRef.key, queryRef.promise]])\n );\n\n let promise = promiseCache.get(queryRef.key);\n\n if (!promise) {\n promise = queryRef.promise;\n promiseCache.set(queryRef.key, promise);\n }\n\n useTrackedQueryRefs(queryRef);\n\n useEffect(() => {\n return queryRef.listen((promise) => {\n setPromiseCache((promiseCache) =>\n new Map(promiseCache).set(queryRef.key, promise)\n );\n });\n }, [queryRef]);\n\n const result = __use(promise);\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setPromiseCache((previousPromiseCache) =>\n new Map(previousPromiseCache).set(queryRef.key, promise)\n );\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setPromiseCache((previousPromiseCache) =>\n new Map(previousPromiseCache).set(queryRef.key, promise)\n );\n\n return promise;\n },\n [queryRef]\n );\n\n const subscribeToMore: SubscribeToMoreFunction<TData, TVariables> =\n useCallback(\n (options) => queryRef.observable.subscribeToMore(options),\n [queryRef]\n );\n\n return useMemo(() => {\n return {\n client,\n data: result.data,\n error: toApolloError(result),\n networkStatus: result.networkStatus,\n fetchMore,\n refetch,\n subscribeToMore,\n };\n }, [client, fetchMore, refetch, result, subscribeToMore]);\n}\n\nfunction validateOptions(options: WatchQueryOptions) {\n const { query, fetchPolicy, returnPartialData } = options;\n\n verifyDocumentType(query, DocumentType.Query);\n validateFetchPolicy(fetchPolicy);\n validatePartialDataReturn(fetchPolicy, returnPartialData);\n}\n\nfunction validateFetchPolicy(\n fetchPolicy: WatchQueryFetchPolicy = 'cache-first'\n) {\n const supportedFetchPolicies: WatchQueryFetchPolicy[] = [\n 'cache-first',\n 'network-only',\n 'no-cache',\n 'cache-and-network',\n ];\n\n invariant(\n supportedFetchPolicies.includes(fetchPolicy),\n `The fetch policy \\`%s\\` is not supported with suspense.`,\n fetchPolicy\n );\n}\n\nfunction validatePartialDataReturn(\n fetchPolicy: WatchQueryFetchPolicy | undefined,\n returnPartialData: boolean | undefined\n) {\n if (fetchPolicy === 'no-cache' && returnPartialData) {\n invariant.warn(\n 'Using `returnPartialData` with a `no-cache` fetch policy has no effect. To read partial data from the cache, consider using an alternate fetch policy.'\n );\n }\n}\n\nexport function toApolloError(result: ApolloQueryResult<any>) {\n return isNonEmptyArray(result.errors)\n ? new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nexport function useTrackedQueryRefs(queryRef: QueryReference) {\n const trackedQueryRefs = useRef(new Set<QueryReference>());\n\n trackedQueryRefs.current.add(queryRef);\n\n useStrictModeSafeCleanupEffect(() => {\n trackedQueryRefs.current.forEach((sub) => sub.dispose());\n });\n}\n\ninterface UseWatchQueryOptionsHookOptions<\n TData,\n TVariables extends OperationVariables\n> {\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n options: SuspenseQueryHookOptions<TData, TVariables>;\n}\n\nexport function useWatchQueryOptions<\n TData,\n TVariables extends OperationVariables\n>({\n query,\n options,\n}: UseWatchQueryOptionsHookOptions<TData, TVariables>): WatchQueryOptions<\n TVariables,\n TData\n> {\n const watchQueryOptions = useDeepMemo<WatchQueryOptions<TVariables, TData>>(\n () => ({\n ...options,\n query,\n notifyOnNetworkStatusChange: false,\n nextFetchPolicy: void 0,\n }),\n [options, query]\n );\n\n if (__DEV__) {\n validateOptions(watchQueryOptions);\n }\n\n return watchQueryOptions;\n}\n"]}
|
|
@@ -10,7 +10,7 @@ export var useSyncExternalStore = realHook || (function (subscribe, getSnapshot,
|
|
|
10
10
|
!didWarnUncachedGetSnapshot &&
|
|
11
11
|
value !== getSnapshot()) {
|
|
12
12
|
didWarnUncachedGetSnapshot = true;
|
|
13
|
-
__DEV__ && invariant.error(
|
|
13
|
+
__DEV__ && invariant.error(59);
|
|
14
14
|
}
|
|
15
15
|
var _a = React.useState({ inst: { value: value, getSnapshot: getSnapshot } }), inst = _a[0].inst, forceUpdate = _a[1];
|
|
16
16
|
if (canUseLayoutEffect) {
|
package/react/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../utilities/globals';
|
|
2
2
|
export { ApolloProvider, ApolloConsumer, getApolloContext, resetApolloContext, ApolloContextValue } from './context';
|
|
3
3
|
export * from './hooks';
|
|
4
|
-
export
|
|
4
|
+
export { SuspenseCache } from './cache';
|
|
5
5
|
export { DocumentType, IDocumentDefinition, operationName, parser } from './parser';
|
|
6
6
|
export * from './types/types';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/react/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAEnB,cAAc,SAAS,CAAC;AACxB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAEnB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,MAAM,EACP,MAAM,UAAU,CAAC;AAElB,cAAc,eAAe,CAAC"}
|
package/react/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../utilities/globals/index.js";
|
|
2
2
|
export { ApolloProvider, ApolloConsumer, getApolloContext, resetApolloContext } from "./context/index.js";
|
|
3
3
|
export * from "./hooks/index.js";
|
|
4
|
-
export
|
|
4
|
+
export { SuspenseCache } from "./cache/index.js";
|
|
5
5
|
export { DocumentType, operationName, parser } from "./parser/index.js";
|
|
6
6
|
export * from "./types/types.js";
|
|
7
7
|
//# sourceMappingURL=index.js.map
|
package/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,WAAW,CAAC;AAEnB,cAAc,SAAS,CAAC;AACxB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAE9B,OAAO,EACL,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAEnB,MAAM,WAAW,CAAC;AAEnB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,OAAO,EACL,YAAY,EAEZ,aAAa,EACb,MAAM,EACP,MAAM,UAAU,CAAC;AAElB,cAAc,eAAe,CAAC","sourcesContent":["import '../utilities/globals';\n\nexport {\n ApolloProvider,\n ApolloConsumer,\n getApolloContext,\n resetApolloContext,\n ApolloContextValue\n} from './context';\n\nexport * from './hooks';\nexport { SuspenseCache } from './cache';\n\nexport {\n DocumentType,\n IDocumentDefinition,\n operationName,\n parser\n} from './parser';\n\nexport * from './types/types';\n"]}
|
package/react/parser/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EAEZ,sBAAsB,EAEvB,MAAM,SAAS,CAAC;AAEjB,oBAAY,YAAY;IACtB,KAAK,IAAA;IACL,QAAQ,IAAA;IACR,YAAY,IAAA;CACb;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;CAClD;AAID,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,UAc/C;AAGD,wBAAgB,MAAM,CAAC,QAAQ,EAAE,YAAY,GAAG,mBAAmB,CAyFlE;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,QAY5E"}
|
package/react/parser/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { invariant
|
|
1
|
+
import { invariant } from "../../utilities/globals/index.js";
|
|
2
2
|
export var DocumentType;
|
|
3
3
|
(function (DocumentType) {
|
|
4
4
|
DocumentType[DocumentType["Query"] = 0] = "Query";
|
|
@@ -26,9 +26,7 @@ export function parser(document) {
|
|
|
26
26
|
if (cached)
|
|
27
27
|
return cached;
|
|
28
28
|
var variables, type, name;
|
|
29
|
-
|
|
30
|
-
"DocumentNode. You may need to use 'graphql-tag' or another method " +
|
|
31
|
-
"to convert your operation into a document") : invariant(!!document && !!document.kind, 35);
|
|
29
|
+
invariant(!!document && !!document.kind, 60, document);
|
|
32
30
|
var fragments = [];
|
|
33
31
|
var queries = [];
|
|
34
32
|
var mutations = [];
|
|
@@ -53,14 +51,16 @@ export function parser(document) {
|
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
(queries.length || mutations.length || subscriptions.length),
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
invariant(!fragments.length ||
|
|
55
|
+
(queries.length || mutations.length || subscriptions.length), 61);
|
|
56
|
+
invariant(
|
|
57
|
+
queries.length + mutations.length + subscriptions.length <= 1,
|
|
58
|
+
62,
|
|
59
|
+
document,
|
|
60
|
+
queries.length,
|
|
61
|
+
subscriptions.length,
|
|
62
|
+
mutations.length
|
|
63
|
+
);
|
|
64
64
|
type = queries.length ? DocumentType.Query : DocumentType.Mutation;
|
|
65
65
|
if (!queries.length && !mutations.length)
|
|
66
66
|
type = DocumentType.Subscription;
|
|
@@ -69,9 +69,7 @@ export function parser(document) {
|
|
|
69
69
|
: mutations.length
|
|
70
70
|
? mutations
|
|
71
71
|
: subscriptions;
|
|
72
|
-
|
|
73
|
-
"".concat(definitions.length, " definitions. ") +
|
|
74
|
-
"You can use 'compose' to join multiple operation types to a component") : invariant(definitions.length === 1, 38);
|
|
72
|
+
invariant(definitions.length === 1, 63, document, definitions.length);
|
|
75
73
|
var definition = definitions[0];
|
|
76
74
|
variables = definition.variableDefinitions || [];
|
|
77
75
|
if (definition.name && definition.name.kind === 'Name') {
|
|
@@ -88,7 +86,12 @@ export function verifyDocumentType(document, type) {
|
|
|
88
86
|
var operation = parser(document);
|
|
89
87
|
var requiredOperationName = operationName(type);
|
|
90
88
|
var usedOperationName = operationName(operation.type);
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
invariant(
|
|
90
|
+
operation.type === type,
|
|
91
|
+
64,
|
|
92
|
+
requiredOperationName,
|
|
93
|
+
requiredOperationName,
|
|
94
|
+
usedOperationName
|
|
95
|
+
);
|
|
93
96
|
}
|
|
94
97
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/react/parser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AASpD,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iDAAK,CAAA;IACL,uDAAQ,CAAA;IACR,+DAAY,CAAA;AACd,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAQD,IAAM,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AAExB,MAAM,UAAU,aAAa,CAAC,IAAkB;IAC9C,IAAI,IAAI,CAAC;IACT,QAAQ,IAAI,EAAE;QACZ,KAAK,YAAY,CAAC,KAAK;YACrB,IAAI,GAAG,OAAO,CAAC;YACf,MAAM;QACR,KAAK,YAAY,CAAC,QAAQ;YACxB,IAAI,GAAG,UAAU,CAAC;YAClB,MAAM;QACR,KAAK,YAAY,CAAC,YAAY;YAC5B,IAAI,GA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SAAS,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CACP,SAAS,CAAC,IAAI,KAAK,IAAI,EACvB,kCAAkC;QAChC,gCAAgC,EAChC,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,CACpB,CAAC;AACJ,CAAC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport type {\n DocumentNode,\n DefinitionNode,\n VariableDefinitionNode,\n OperationDefinitionNode\n} from 'graphql';\n\nexport enum DocumentType {\n Query,\n Mutation,\n Subscription\n}\n\nexport interface IDocumentDefinition {\n type: DocumentType;\n name: string;\n variables: ReadonlyArray<VariableDefinitionNode>;\n}\n\nconst cache = new Map();\n\nexport function operationName(type: DocumentType) {\n let name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\n\n// This parser is mostly used to safety check incoming documents.\nexport function parser(document: DocumentNode): IDocumentDefinition {\n const cached = cache.get(document);\n if (cached) return cached;\n\n let variables, type, name;\n\n invariant(\n !!document && !!document.kind,\n `Argument of %s passed to parser was not a valid GraphQL ` +\n `DocumentNode. You may need to use 'graphql-tag' or another method ` +\n `to convert your operation into a document`,\n document\n );\n\n const fragments: DefinitionNode[] = []\n const queries: DefinitionNode[] = []\n const mutations: DefinitionNode[] = []\n const subscriptions: DefinitionNode[] = []\n\n for (const x of document.definitions) {\n if (x.kind === 'FragmentDefinition') {\n fragments.push(x);\n continue\n }\n\n if (x.kind === 'OperationDefinition') {\n switch (x.operation) {\n case 'query':\n queries.push(x);\n break;\n case 'mutation':\n mutations.push(x);\n break;\n case 'subscription':\n subscriptions.push(x);\n break;\n }\n }\n }\n\n invariant(\n !fragments.length ||\n (queries.length || mutations.length || subscriptions.length),\n `Passing only a fragment to 'graphql' is not yet supported. ` +\n `You must include a query, subscription or mutation as well`\n );\n\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n `react-apollo only supports a query, subscription, or a mutation per HOC. ` +\n `%s had %s queries, %s ` +\n `subscriptions and %s mutations. ` +\n `You can use 'compose' to join multiple operation types to a component`,\n document,\n queries.length,\n subscriptions.length,\n mutations.length\n );\n\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length) type = DocumentType.Subscription;\n\n const definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n\n invariant(\n definitions.length === 1,\n `react-apollo only supports one definition per HOC. %s had ` +\n `%s definitions. ` +\n `You can use 'compose' to join multiple operation types to a component`,\n document,\n definitions.length\n );\n\n const definition = definitions[0] as OperationDefinitionNode;\n variables = definition.variableDefinitions || [];\n\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n } else {\n name = 'data'; // fallback to using data if no name\n }\n\n const payload = { name, type, variables };\n cache.set(document, payload);\n return payload;\n}\n\nexport function verifyDocumentType(document: DocumentNode, type: DocumentType) {\n const operation = parser(document);\n const requiredOperationName = operationName(type);\n const usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n `Running a %s requires a graphql ` +\n `%s, but a %s was used instead.`,\n requiredOperationName,\n requiredOperationName,\n usedOperationName\n );\n}\n\n"]}
|
package/react/parser/parser.cjs
CHANGED
|
@@ -31,9 +31,7 @@ function parser(document) {
|
|
|
31
31
|
if (cached)
|
|
32
32
|
return cached;
|
|
33
33
|
var variables, type, name;
|
|
34
|
-
globals.
|
|
35
|
-
"DocumentNode. You may need to use 'graphql-tag' or another method " +
|
|
36
|
-
"to convert your operation into a document") : globals.invariant(!!document && !!document.kind, 35);
|
|
34
|
+
globals.invariant(!!document && !!document.kind, 60, document);
|
|
37
35
|
var fragments = [];
|
|
38
36
|
var queries = [];
|
|
39
37
|
var mutations = [];
|
|
@@ -58,14 +56,16 @@ function parser(document) {
|
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
}
|
|
61
|
-
globals.
|
|
62
|
-
(queries.length || mutations.length || subscriptions.length),
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
59
|
+
globals.invariant(!fragments.length ||
|
|
60
|
+
(queries.length || mutations.length || subscriptions.length), 61);
|
|
61
|
+
globals.invariant(
|
|
62
|
+
queries.length + mutations.length + subscriptions.length <= 1,
|
|
63
|
+
62,
|
|
64
|
+
document,
|
|
65
|
+
queries.length,
|
|
66
|
+
subscriptions.length,
|
|
67
|
+
mutations.length
|
|
68
|
+
);
|
|
69
69
|
type = queries.length ? exports.DocumentType.Query : exports.DocumentType.Mutation;
|
|
70
70
|
if (!queries.length && !mutations.length)
|
|
71
71
|
type = exports.DocumentType.Subscription;
|
|
@@ -74,9 +74,7 @@ function parser(document) {
|
|
|
74
74
|
: mutations.length
|
|
75
75
|
? mutations
|
|
76
76
|
: subscriptions;
|
|
77
|
-
globals.
|
|
78
|
-
"".concat(definitions.length, " definitions. ") +
|
|
79
|
-
"You can use 'compose' to join multiple operation types to a component") : globals.invariant(definitions.length === 1, 38);
|
|
77
|
+
globals.invariant(definitions.length === 1, 63, document, definitions.length);
|
|
80
78
|
var definition = definitions[0];
|
|
81
79
|
variables = definition.variableDefinitions || [];
|
|
82
80
|
if (definition.name && definition.name.kind === 'Name') {
|
|
@@ -93,8 +91,13 @@ function verifyDocumentType(document, type) {
|
|
|
93
91
|
var operation = parser(document);
|
|
94
92
|
var requiredOperationName = operationName(type);
|
|
95
93
|
var usedOperationName = operationName(operation.type);
|
|
96
|
-
globals.
|
|
97
|
-
|
|
94
|
+
globals.invariant(
|
|
95
|
+
operation.type === type,
|
|
96
|
+
64,
|
|
97
|
+
requiredOperationName,
|
|
98
|
+
requiredOperationName,
|
|
99
|
+
usedOperationName
|
|
100
|
+
);
|
|
98
101
|
}
|
|
99
102
|
|
|
100
103
|
exports.operationName = operationName;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.cjs","sources":["index.js"],"sourcesContent":["import { invariant
|
|
1
|
+
{"version":3,"file":"parser.cjs","sources":["index.js"],"sourcesContent":["import { invariant } from '../../utilities/globals';\nexport var DocumentType;\n(function (DocumentType) {\n DocumentType[DocumentType[\"Query\"] = 0] = \"Query\";\n DocumentType[DocumentType[\"Mutation\"] = 1] = \"Mutation\";\n DocumentType[DocumentType[\"Subscription\"] = 2] = \"Subscription\";\n})(DocumentType || (DocumentType = {}));\nvar cache = new Map();\nexport function operationName(type) {\n var name;\n switch (type) {\n case DocumentType.Query:\n name = 'Query';\n break;\n case DocumentType.Mutation:\n name = 'Mutation';\n break;\n case DocumentType.Subscription:\n name = 'Subscription';\n break;\n }\n return name;\n}\nexport function parser(document) {\n var cached = cache.get(document);\n if (cached)\n return cached;\n var variables, type, name;\n invariant(!!document && !!document.kind, 60, document);\n var fragments = [];\n var queries = [];\n var mutations = [];\n var subscriptions = [];\n for (var _i = 0, _a = document.definitions; _i < _a.length; _i++) {\n var x = _a[_i];\n if (x.kind === 'FragmentDefinition') {\n fragments.push(x);\n continue;\n }\n if (x.kind === 'OperationDefinition') {\n switch (x.operation) {\n case 'query':\n queries.push(x);\n break;\n case 'mutation':\n mutations.push(x);\n break;\n case 'subscription':\n subscriptions.push(x);\n break;\n }\n }\n }\n invariant(!fragments.length ||\n (queries.length || mutations.length || subscriptions.length), 61);\n invariant(\n queries.length + mutations.length + subscriptions.length <= 1,\n 62,\n document,\n queries.length,\n subscriptions.length,\n mutations.length\n );\n type = queries.length ? DocumentType.Query : DocumentType.Mutation;\n if (!queries.length && !mutations.length)\n type = DocumentType.Subscription;\n var definitions = queries.length\n ? queries\n : mutations.length\n ? mutations\n : subscriptions;\n invariant(definitions.length === 1, 63, document, definitions.length);\n var definition = definitions[0];\n variables = definition.variableDefinitions || [];\n if (definition.name && definition.name.kind === 'Name') {\n name = definition.name.value;\n }\n else {\n name = 'data';\n }\n var payload = { name: name, type: type, variables: variables };\n cache.set(document, payload);\n return payload;\n}\nexport function verifyDocumentType(document, type) {\n var operation = parser(document);\n var requiredOperationName = operationName(type);\n var usedOperationName = operationName(operation.type);\n invariant(\n operation.type === type,\n 64,\n requiredOperationName,\n requiredOperationName,\n usedOperationName\n );\n}\n//# sourceMappingURL=index.js.map"],"names":["DocumentType","invariant"],"mappings":";;;;;;AACWA,8BAAa;AACxB,CAAC,UAAU,YAAY,EAAE;AACzB,IAAI,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC;AACtD,IAAI,YAAY,CAAC,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC;AAC5D,IAAI,YAAY,CAAC,YAAY,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC;AACpE,CAAC,EAAEA,oBAAY,KAAKA,oBAAY,GAAG,EAAE,CAAC,CAAC,CAAC;AACxC,IAAI,KAAK,GAAG,IAAI,GAAG,EAAE,CAAC;AACf,SAAS,aAAa,CAAC,IAAI,EAAE;AACpC,IAAI,IAAI,IAAI,CAAC;AACb,IAAI,QAAQ,IAAI;AAChB,QAAQ,KAAKA,oBAAY,CAAC,KAAK;AAC/B,YAAY,IAAI,GAAG,OAAO,CAAC;AAC3B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,QAAQ;AAClC,YAAY,IAAI,GAAG,UAAU,CAAC;AAC9B,YAAY,MAAM;AAClB,QAAQ,KAAKA,oBAAY,CAAC,YAAY;AACtC,YAAY,IAAI,GAAG,cAAc,CAAC;AAClC,YAAY,MAAM;AAClB,KAAK;AACL,IAAI,OAAO,IAAI,CAAC;AAChB,CAAC;AACM,SAAS,MAAM,CAAC,QAAQ,EAAE;AACjC,IAAI,IAAI,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACrC,IAAI,IAAI,MAAM;AACd,QAAQ,OAAO,MAAM,CAAC;AACtB,IAAI,IAAI,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC;AAC9B,IAAIC,iB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