@apollo/client 3.4.17 → 3.5.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/README.md +1 -1
- package/{apollo-client.cjs.js → apollo-client.cjs} +1219 -1280
- package/apollo-client.cjs.map +1 -0
- package/apollo-client.min.cjs +1 -0
- package/cache/{cache.cjs.js → cache.cjs} +757 -601
- package/cache/cache.cjs.map +1 -0
- package/cache/core/cache.d.ts +6 -4
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js +28 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +12 -10
- 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 +4 -0
- 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 +8 -5
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js +6 -11
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/helpers.js +1 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +4 -4
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +12 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.d.ts +9 -0
- package/cache/inmemory/key-extractor.d.ts.map +1 -0
- package/cache/inmemory/key-extractor.js +118 -0
- package/cache/inmemory/key-extractor.js.map +1 -0
- package/cache/inmemory/policies.d.ts +7 -3
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +47 -118
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +2 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +54 -42
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +8 -3
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +166 -95
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/cache/package.json +2 -1
- package/core/ApolloClient.d.ts +0 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +3 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +1 -1
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +19 -14
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -2
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +0 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +10 -10
- package/core/QueryManager.js.map +1 -1
- package/core/{core.cjs.js → core.cjs} +38 -34
- package/core/core.cjs.map +1 -0
- package/core/package.json +2 -1
- package/errors/{errors.cjs.js → errors.cjs} +3 -3
- package/errors/errors.cjs.map +1 -0
- package/errors/index.d.ts +3 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +2 -2
- package/errors/index.js.map +1 -1
- package/errors/package.json +2 -1
- package/invariantErrorCodes.js +84 -104
- package/link/batch/{batch.cjs.js → batch.cjs} +2 -2
- package/link/batch/batch.cjs.map +1 -0
- package/link/batch/batchLink.d.ts +0 -1
- package/link/batch/batchLink.d.ts.map +1 -1
- package/link/batch/batching.d.ts +0 -1
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +1 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch/package.json +2 -1
- package/link/batch-http/{batch-http.cjs.js → batch-http.cjs} +3 -3
- package/link/batch-http/batch-http.cjs.map +1 -0
- package/link/batch-http/batchHttpLink.d.ts +0 -1
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +3 -3
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/package.json +2 -1
- package/link/context/{context.cjs.js → context.cjs} +1 -1
- package/link/context/context.cjs.map +1 -0
- package/link/context/index.js.map +1 -1
- package/link/context/package.json +2 -1
- package/link/core/ApolloLink.d.ts +2 -3
- package/link/core/ApolloLink.d.ts.map +1 -1
- package/link/core/ApolloLink.js +1 -1
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/{core.cjs.js → core.cjs} +2 -2
- package/link/core/core.cjs.map +1 -0
- package/link/core/package.json +2 -1
- package/link/core/types.d.ts +4 -7
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/error/{error.cjs.js → error.cjs} +2 -2
- package/link/error/error.cjs.map +1 -0
- package/link/error/index.d.ts +5 -7
- package/link/error/index.d.ts.map +1 -1
- package/link/error/index.js +1 -1
- package/link/error/index.js.map +1 -1
- package/link/error/package.json +2 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +3 -3
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/{http.cjs.js → http.cjs} +28 -15
- package/link/http/http.cjs.map +1 -0
- package/link/http/index.d.ts +1 -1
- package/link/http/index.d.ts.map +1 -1
- package/link/http/index.js +1 -1
- package/link/http/index.js.map +1 -1
- package/link/http/package.json +2 -1
- package/link/http/parseAndCheckHttpResponse.js +3 -3
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/rewriteURIForGET.js +1 -1
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +11 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +20 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +3 -3
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/package.json +2 -1
- package/link/persisted-queries/{persisted-queries.cjs.js → persisted-queries.cjs} +3 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -0
- package/link/retry/package.json +2 -1
- package/link/retry/{retry.cjs.js → retry.cjs} +1 -1
- package/link/retry/retry.cjs.map +1 -0
- package/link/retry/retryLink.d.ts +0 -1
- package/link/retry/retryLink.d.ts.map +1 -1
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +0 -1
- package/link/schema/index.d.ts.map +1 -1
- package/link/schema/index.js +8 -1
- package/link/schema/index.js.map +1 -1
- package/link/schema/package.json +2 -1
- package/link/schema/{schema.cjs.js → schema.cjs} +9 -2
- package/link/schema/schema.cjs.map +1 -0
- package/link/utils/fromError.d.ts +0 -1
- package/link/utils/fromError.d.ts.map +1 -1
- package/link/utils/fromPromise.d.ts +0 -1
- package/link/utils/fromPromise.d.ts.map +1 -1
- package/link/utils/package.json +2 -1
- package/link/utils/toPromise.d.ts +0 -1
- package/link/utils/toPromise.d.ts.map +1 -1
- package/link/utils/{utils.cjs.js → utils.cjs} +2 -2
- package/link/utils/utils.cjs.map +1 -0
- package/link/utils/validateOperation.js +1 -1
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +0 -1
- package/link/ws/index.d.ts.map +1 -1
- package/link/ws/package.json +2 -1
- package/link/ws/{ws.cjs.js → ws.cjs} +1 -1
- package/link/ws/ws.cjs.map +1 -0
- package/{main.cjs.js → main.cjs} +5 -5
- package/main.cjs.map +1 -0
- package/package.json +20 -19
- package/react/components/Query.js.map +1 -1
- package/react/components/{components.cjs.js → components.cjs} +4 -4
- package/react/components/components.cjs.map +1 -0
- package/react/components/package.json +2 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/{context.cjs.js → context.cjs} +6 -6
- package/react/context/context.cjs.map +1 -0
- package/react/context/index.d.ts +3 -3
- package/react/context/index.d.ts.map +1 -1
- package/react/context/index.js +3 -3
- package/react/context/index.js.map +1 -1
- package/react/context/package.json +2 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/{hoc.cjs.js → hoc.cjs} +12 -12
- package/react/hoc/hoc.cjs.map +1 -0
- package/react/hoc/mutation-hoc.js +2 -2
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/package.json +2 -1
- package/react/hoc/query-hoc.js +1 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +1 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +2 -2
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +502 -0
- package/react/hooks/hooks.cjs.map +1 -0
- package/react/hooks/package.json +2 -1
- package/react/hooks/useApolloClient.d.ts +1 -1
- package/react/hooks/useApolloClient.d.ts.map +1 -1
- package/react/hooks/useApolloClient.js +7 -5
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +56 -2
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +89 -21
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +224 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -7
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +89 -32
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/package.json +2 -1
- package/react/parser/index.d.ts +1 -0
- package/react/parser/index.d.ts.map +1 -1
- package/react/parser/index.js +16 -9
- package/react/parser/index.js.map +1 -1
- package/react/parser/package.json +2 -1
- package/react/parser/{parser.cjs.js → parser.cjs} +18 -10
- package/react/parser/parser.cjs.map +1 -0
- package/react/{react.cjs.js → react.cjs} +3 -3
- package/react/react.cjs.map +1 -0
- package/react/ssr/RenderPromises.d.ts +7 -3
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/package.json +2 -1
- package/react/ssr/{ssr.cjs.js → ssr.cjs} +4 -4
- package/react/ssr/ssr.cjs.map +1 -0
- package/react/types/types.d.ts +7 -18
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/{testing.cjs.js → core/core.cjs} +10 -104
- package/testing/core/core.cjs.map +1 -0
- package/{utilities/testing → testing/core}/index.d.ts +0 -1
- package/testing/core/index.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/index.js +0 -1
- package/testing/core/index.js.map +1 -0
- package/{utilities/testing → testing/core}/itAsync.d.ts +0 -0
- package/testing/core/itAsync.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/itAsync.js +0 -0
- package/testing/core/itAsync.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockClient.d.ts +0 -0
- package/testing/core/mocking/mockClient.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockClient.js +0 -0
- package/testing/core/mocking/mockClient.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockFetch.d.ts +0 -0
- package/testing/core/mocking/mockFetch.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockLink.d.ts +0 -1
- package/testing/core/mocking/mockLink.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockLink.js +5 -5
- package/testing/core/mocking/mockLink.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockQueryManager.d.ts +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockQueryManager.js +1 -1
- package/testing/core/mocking/mockQueryManager.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.d.ts +1 -4
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockWatchQuery.d.ts +1 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockWatchQuery.js +0 -0
- package/testing/core/mocking/mockWatchQuery.js.map +1 -0
- package/{utilities/testing → testing/core}/observableToPromise.d.ts +2 -3
- package/testing/core/observableToPromise.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/observableToPromise.js +1 -1
- package/testing/core/observableToPromise.js.map +1 -0
- package/testing/core/package.json +8 -0
- package/testing/core/subscribeAndCount.d.ts +4 -0
- package/testing/core/subscribeAndCount.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/subscribeAndCount.js +1 -1
- package/testing/core/subscribeAndCount.js.map +1 -0
- package/{utilities/testing → testing/core}/withConsoleSpy.d.ts +0 -0
- package/testing/core/withConsoleSpy.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/withConsoleSpy.js +0 -0
- package/testing/core/withConsoleSpy.js.map +1 -0
- package/{utilities/testing → testing/core}/wrap.d.ts +0 -0
- package/testing/core/wrap.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/wrap.js +0 -0
- package/testing/core/wrap.js.map +1 -0
- package/testing/index.d.ts +2 -1
- package/testing/index.d.ts.map +1 -1
- package/testing/index.js +2 -1
- package/testing/index.js.map +1 -1
- package/testing/package.json +2 -1
- package/{utilities/testing/mocking → testing/react}/MockedProvider.d.ts +5 -5
- package/testing/react/MockedProvider.d.ts.map +1 -0
- package/{utilities/testing/mocking → testing/react}/MockedProvider.js +4 -4
- package/testing/react/MockedProvider.js.map +1 -0
- package/testing/testing.cjs +58 -0
- package/testing/testing.cjs.map +1 -0
- 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/makeUniqueId.js +1 -1
- package/utilities/common/makeUniqueId.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +6 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/globals/fix-graphql.js +1 -1
- package/utilities/globals/global.d.ts.map +1 -1
- package/utilities/globals/global.js +1 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/{globals.cjs.js → globals.cjs} +3 -3
- package/utilities/globals/globals.cjs.map +1 -0
- package/utilities/globals/index.js +1 -1
- package/utilities/globals/package.json +2 -1
- package/utilities/graphql/directives.js +5 -5
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js +4 -4
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/storeUtils.js +6 -6
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/observables/Concast.d.ts +0 -1
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/asyncMap.d.ts +0 -1
- package/utilities/observables/asyncMap.d.ts.map +1 -1
- package/utilities/observables/subclassing.d.ts +0 -1
- package/utilities/observables/subclassing.d.ts.map +1 -1
- package/utilities/package.json +2 -1
- package/utilities/{utilities.cjs.js → utilities.cjs} +31 -26
- package/utilities/utilities.cjs.map +1 -0
- package/version.js +1 -1
- package/apollo-client.cjs.js.map +0 -1
- package/apollo-client.cjs.min.js +0 -1
- package/cache/cache.cjs.js.map +0 -1
- package/core/core.cjs.js.map +0 -1
- package/errors/errors.cjs.js.map +0 -1
- package/link/batch/batch.cjs.js.map +0 -1
- package/link/batch-http/batch-http.cjs.js.map +0 -1
- package/link/context/context.cjs.js.map +0 -1
- package/link/core/core.cjs.js.map +0 -1
- package/link/error/error.cjs.js.map +0 -1
- package/link/http/http.cjs.js.map +0 -1
- package/link/persisted-queries/persisted-queries.cjs.js.map +0 -1
- package/link/retry/retry.cjs.js.map +0 -1
- package/link/schema/schema.cjs.js.map +0 -1
- package/link/utils/utils.cjs.js.map +0 -1
- package/link/ws/ws.cjs.js.map +0 -1
- package/main.cjs.js.map +0 -1
- package/react/components/components.cjs.js.map +0 -1
- package/react/context/context.cjs.js.map +0 -1
- package/react/data/MutationData.d.ts +0 -29
- package/react/data/MutationData.d.ts.map +0 -1
- package/react/data/MutationData.js +0 -115
- package/react/data/MutationData.js.map +0 -1
- package/react/data/OperationData.d.ts +0 -24
- package/react/data/OperationData.d.ts.map +0 -1
- package/react/data/OperationData.js +0 -53
- package/react/data/OperationData.js.map +0 -1
- package/react/data/QueryData.d.ts +0 -44
- package/react/data/QueryData.d.ts.map +0 -1
- package/react/data/QueryData.js +0 -298
- package/react/data/QueryData.js.map +0 -1
- package/react/data/SubscriptionData.d.ts +0 -28
- package/react/data/SubscriptionData.d.ts.map +0 -1
- package/react/data/SubscriptionData.js +0 -122
- package/react/data/SubscriptionData.js.map +0 -1
- package/react/data/data.cjs.js +0 -581
- package/react/data/data.cjs.js.map +0 -1
- package/react/data/index.d.ts +0 -6
- package/react/data/index.d.ts.map +0 -1
- package/react/data/index.js +0 -6
- package/react/data/index.js.map +0 -1
- package/react/data/package.json +0 -7
- package/react/hoc/hoc.cjs.js.map +0 -1
- package/react/hooks/hooks.cjs.js +0 -195
- package/react/hooks/hooks.cjs.js.map +0 -1
- package/react/hooks/utils/useAfterFastRefresh.d.ts +0 -3
- package/react/hooks/utils/useAfterFastRefresh.d.ts.map +0 -1
- package/react/hooks/utils/useAfterFastRefresh.js +0 -19
- package/react/hooks/utils/useAfterFastRefresh.js.map +0 -1
- package/react/hooks/utils/useBaseQuery.d.ts +0 -7
- package/react/hooks/utils/useBaseQuery.d.ts.map +0 -1
- package/react/hooks/utils/useBaseQuery.js +0 -55
- package/react/hooks/utils/useBaseQuery.js.map +0 -1
- package/react/hooks/utils/useDeepMemo.d.ts +0 -2
- package/react/hooks/utils/useDeepMemo.d.ts.map +0 -1
- package/react/hooks/utils/useDeepMemo.js +0 -10
- package/react/hooks/utils/useDeepMemo.js.map +0 -1
- package/react/parser/parser.cjs.js.map +0 -1
- package/react/react.cjs.js.map +0 -1
- package/react/ssr/ssr.cjs.js.map +0 -1
- package/testing/testing.cjs.js.map +0 -1
- package/utilities/globals/globals.cjs.js.map +0 -1
- package/utilities/testing/index.d.ts.map +0 -1
- package/utilities/testing/index.js.map +0 -1
- package/utilities/testing/itAsync.d.ts.map +0 -1
- package/utilities/testing/itAsync.js.map +0 -1
- package/utilities/testing/mocking/MockedProvider.d.ts.map +0 -1
- package/utilities/testing/mocking/MockedProvider.js.map +0 -1
- package/utilities/testing/mocking/mockClient.d.ts.map +0 -1
- package/utilities/testing/mocking/mockClient.js.map +0 -1
- package/utilities/testing/mocking/mockFetch.d.ts.map +0 -1
- package/utilities/testing/mocking/mockFetch.js.map +0 -1
- package/utilities/testing/mocking/mockLink.d.ts.map +0 -1
- package/utilities/testing/mocking/mockLink.js.map +0 -1
- package/utilities/testing/mocking/mockQueryManager.d.ts.map +0 -1
- package/utilities/testing/mocking/mockQueryManager.js.map +0 -1
- package/utilities/testing/mocking/mockSubscriptionLink.d.ts.map +0 -1
- package/utilities/testing/mocking/mockSubscriptionLink.js.map +0 -1
- package/utilities/testing/mocking/mockWatchQuery.d.ts.map +0 -1
- package/utilities/testing/mocking/mockWatchQuery.js.map +0 -1
- package/utilities/testing/observableToPromise.d.ts.map +0 -1
- package/utilities/testing/observableToPromise.js.map +0 -1
- package/utilities/testing/subscribeAndCount.d.ts +0 -5
- package/utilities/testing/subscribeAndCount.d.ts.map +0 -1
- package/utilities/testing/subscribeAndCount.js.map +0 -1
- package/utilities/testing/withConsoleSpy.d.ts.map +0 -1
- package/utilities/testing/withConsoleSpy.js.map +0 -1
- package/utilities/testing/wrap.d.ts.map +0 -1
- package/utilities/testing/wrap.js.map +0 -1
- package/utilities/utilities.cjs.js.map +0 -1
package/react/data/QueryData.js
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { __assign, __extends } from "tslib";
|
|
2
|
-
import { equal } from '@wry/equality';
|
|
3
|
-
import { ApolloError } from "../../errors/index.js";
|
|
4
|
-
import { NetworkStatus, } from "../../core/index.js";
|
|
5
|
-
import { DocumentType } from "../parser/index.js";
|
|
6
|
-
import { OperationData } from "./OperationData.js";
|
|
7
|
-
var QueryData = (function (_super) {
|
|
8
|
-
__extends(QueryData, _super);
|
|
9
|
-
function QueryData(_a) {
|
|
10
|
-
var options = _a.options, context = _a.context, onNewData = _a.onNewData;
|
|
11
|
-
var _this = _super.call(this, options, context) || this;
|
|
12
|
-
_this.runLazy = false;
|
|
13
|
-
_this.previous = Object.create(null);
|
|
14
|
-
_this.runLazyQuery = function (options) {
|
|
15
|
-
_this.cleanup();
|
|
16
|
-
_this.runLazy = true;
|
|
17
|
-
_this.lazyOptions = options;
|
|
18
|
-
_this.onNewData();
|
|
19
|
-
};
|
|
20
|
-
_this.obsRefetch = function (variables) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.refetch(variables); };
|
|
21
|
-
_this.obsFetchMore = function (fetchMoreOptions) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.fetchMore(fetchMoreOptions); };
|
|
22
|
-
_this.obsUpdateQuery = function (mapFn) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.updateQuery(mapFn); };
|
|
23
|
-
_this.obsStartPolling = function (pollInterval) {
|
|
24
|
-
var _a;
|
|
25
|
-
(_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.startPolling(pollInterval);
|
|
26
|
-
};
|
|
27
|
-
_this.obsStopPolling = function () {
|
|
28
|
-
var _a;
|
|
29
|
-
(_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.stopPolling();
|
|
30
|
-
};
|
|
31
|
-
_this.obsSubscribeToMore = function (options) { var _a; return (_a = _this.currentObservable) === null || _a === void 0 ? void 0 : _a.subscribeToMore(options); };
|
|
32
|
-
_this.onNewData = onNewData;
|
|
33
|
-
return _this;
|
|
34
|
-
}
|
|
35
|
-
QueryData.prototype.execute = function () {
|
|
36
|
-
this.refreshClient();
|
|
37
|
-
var _a = this.getOptions(), skip = _a.skip, query = _a.query;
|
|
38
|
-
if (skip || query !== this.previous.query) {
|
|
39
|
-
this.removeQuerySubscription();
|
|
40
|
-
this.removeObservable(!skip);
|
|
41
|
-
this.previous.query = query;
|
|
42
|
-
}
|
|
43
|
-
this.updateObservableQuery();
|
|
44
|
-
return this.getExecuteSsrResult() || this.getExecuteResult();
|
|
45
|
-
};
|
|
46
|
-
QueryData.prototype.executeLazy = function () {
|
|
47
|
-
return !this.runLazy
|
|
48
|
-
? [
|
|
49
|
-
this.runLazyQuery,
|
|
50
|
-
{
|
|
51
|
-
loading: false,
|
|
52
|
-
networkStatus: NetworkStatus.ready,
|
|
53
|
-
called: false,
|
|
54
|
-
data: undefined
|
|
55
|
-
}
|
|
56
|
-
]
|
|
57
|
-
: [this.runLazyQuery, this.execute()];
|
|
58
|
-
};
|
|
59
|
-
QueryData.prototype.fetchData = function () {
|
|
60
|
-
var _this = this;
|
|
61
|
-
var options = this.getOptions();
|
|
62
|
-
if (options.skip || options.ssr === false)
|
|
63
|
-
return false;
|
|
64
|
-
return new Promise(function (resolve) { return _this.startQuerySubscription(resolve); });
|
|
65
|
-
};
|
|
66
|
-
QueryData.prototype.afterExecute = function (_a) {
|
|
67
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.lazy, lazy = _c === void 0 ? false : _c;
|
|
68
|
-
this.isMounted = true;
|
|
69
|
-
var options = this.getOptions();
|
|
70
|
-
if (this.currentObservable && !this.ssrInitiated()) {
|
|
71
|
-
this.startQuerySubscription();
|
|
72
|
-
}
|
|
73
|
-
if (!lazy || this.runLazy) {
|
|
74
|
-
this.handleErrorOrCompleted();
|
|
75
|
-
}
|
|
76
|
-
this.previousOptions = options;
|
|
77
|
-
return this.unmount.bind(this);
|
|
78
|
-
};
|
|
79
|
-
QueryData.prototype.cleanup = function () {
|
|
80
|
-
this.removeQuerySubscription();
|
|
81
|
-
this.removeObservable(true);
|
|
82
|
-
delete this.previous.result;
|
|
83
|
-
};
|
|
84
|
-
QueryData.prototype.getOptions = function () {
|
|
85
|
-
var options = _super.prototype.getOptions.call(this);
|
|
86
|
-
if (this.lazyOptions) {
|
|
87
|
-
options.variables = __assign(__assign({}, options.variables), this.lazyOptions.variables);
|
|
88
|
-
options.context = __assign(__assign({}, options.context), this.lazyOptions.context);
|
|
89
|
-
}
|
|
90
|
-
if (this.runLazy) {
|
|
91
|
-
delete options.skip;
|
|
92
|
-
}
|
|
93
|
-
return options;
|
|
94
|
-
};
|
|
95
|
-
QueryData.prototype.ssrInitiated = function () {
|
|
96
|
-
return this.context && this.context.renderPromises;
|
|
97
|
-
};
|
|
98
|
-
QueryData.prototype.getExecuteSsrResult = function () {
|
|
99
|
-
var _a = this.getOptions(), ssr = _a.ssr, skip = _a.skip;
|
|
100
|
-
var ssrDisabled = ssr === false;
|
|
101
|
-
var fetchDisabled = this.refreshClient().client.disableNetworkFetches;
|
|
102
|
-
var ssrLoading = __assign({ loading: true, networkStatus: NetworkStatus.loading, called: true, data: undefined, stale: false, client: this.client }, this.observableQueryFields());
|
|
103
|
-
if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {
|
|
104
|
-
this.previous.result = ssrLoading;
|
|
105
|
-
return ssrLoading;
|
|
106
|
-
}
|
|
107
|
-
if (this.ssrInitiated()) {
|
|
108
|
-
var result = this.getExecuteResult() || ssrLoading;
|
|
109
|
-
if (result.loading && !skip) {
|
|
110
|
-
this.context.renderPromises.addQueryPromise(this, function () { return null; });
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
QueryData.prototype.prepareObservableQueryOptions = function () {
|
|
116
|
-
var options = this.getOptions();
|
|
117
|
-
this.verifyDocumentType(options.query, DocumentType.Query);
|
|
118
|
-
var displayName = options.displayName || 'Query';
|
|
119
|
-
if (this.ssrInitiated() &&
|
|
120
|
-
(options.fetchPolicy === 'network-only' ||
|
|
121
|
-
options.fetchPolicy === 'cache-and-network')) {
|
|
122
|
-
options.fetchPolicy = 'cache-first';
|
|
123
|
-
}
|
|
124
|
-
return __assign(__assign({}, options), { displayName: displayName, context: options.context });
|
|
125
|
-
};
|
|
126
|
-
QueryData.prototype.initializeObservableQuery = function () {
|
|
127
|
-
if (this.ssrInitiated()) {
|
|
128
|
-
this.currentObservable = this.context.renderPromises.getSSRObservable(this.getOptions());
|
|
129
|
-
}
|
|
130
|
-
if (!this.currentObservable) {
|
|
131
|
-
var observableQueryOptions = this.prepareObservableQueryOptions();
|
|
132
|
-
this.previous.observableQueryOptions = __assign(__assign({}, observableQueryOptions), { children: void 0 });
|
|
133
|
-
this.currentObservable = this.refreshClient().client.watchQuery(__assign({}, observableQueryOptions));
|
|
134
|
-
if (this.ssrInitiated()) {
|
|
135
|
-
this.context.renderPromises.registerSSRObservable(this.currentObservable, observableQueryOptions);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
QueryData.prototype.updateObservableQuery = function () {
|
|
140
|
-
if (!this.currentObservable) {
|
|
141
|
-
this.initializeObservableQuery();
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
var newObservableQueryOptions = __assign(__assign({}, this.prepareObservableQueryOptions()), { children: void 0 });
|
|
145
|
-
if (this.getOptions().skip) {
|
|
146
|
-
this.previous.observableQueryOptions = newObservableQueryOptions;
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
if (!equal(newObservableQueryOptions, this.previous.observableQueryOptions)) {
|
|
150
|
-
this.previous.observableQueryOptions = newObservableQueryOptions;
|
|
151
|
-
this.currentObservable
|
|
152
|
-
.setOptions(newObservableQueryOptions)
|
|
153
|
-
.catch(function () { });
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
QueryData.prototype.startQuerySubscription = function (onNewData) {
|
|
157
|
-
var _this = this;
|
|
158
|
-
if (onNewData === void 0) { onNewData = this.onNewData; }
|
|
159
|
-
if (this.currentSubscription || this.getOptions().skip)
|
|
160
|
-
return;
|
|
161
|
-
this.currentSubscription = this.currentObservable.subscribe({
|
|
162
|
-
next: function (_a) {
|
|
163
|
-
var loading = _a.loading, networkStatus = _a.networkStatus, data = _a.data;
|
|
164
|
-
var previousResult = _this.previous.result;
|
|
165
|
-
if (previousResult &&
|
|
166
|
-
previousResult.loading === loading &&
|
|
167
|
-
previousResult.networkStatus === networkStatus &&
|
|
168
|
-
equal(previousResult.data, data)) {
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
onNewData();
|
|
172
|
-
},
|
|
173
|
-
error: function (error) {
|
|
174
|
-
_this.resubscribeToQuery();
|
|
175
|
-
if (!error.hasOwnProperty('graphQLErrors'))
|
|
176
|
-
throw error;
|
|
177
|
-
var previousResult = _this.previous.result;
|
|
178
|
-
if ((previousResult && previousResult.loading) ||
|
|
179
|
-
!equal(error, _this.previous.error)) {
|
|
180
|
-
_this.previous.error = error;
|
|
181
|
-
onNewData();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
QueryData.prototype.resubscribeToQuery = function () {
|
|
187
|
-
this.removeQuerySubscription();
|
|
188
|
-
var currentObservable = this.currentObservable;
|
|
189
|
-
if (currentObservable) {
|
|
190
|
-
var last = currentObservable["last"];
|
|
191
|
-
try {
|
|
192
|
-
currentObservable.resetLastResults();
|
|
193
|
-
this.startQuerySubscription();
|
|
194
|
-
}
|
|
195
|
-
finally {
|
|
196
|
-
currentObservable["last"] = last;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
QueryData.prototype.getExecuteResult = function () {
|
|
201
|
-
var result = this.observableQueryFields();
|
|
202
|
-
var options = this.getOptions();
|
|
203
|
-
if (options.skip) {
|
|
204
|
-
result = __assign(__assign({}, result), { data: undefined, error: undefined, loading: false, networkStatus: NetworkStatus.ready, called: true });
|
|
205
|
-
}
|
|
206
|
-
else if (this.currentObservable) {
|
|
207
|
-
var currentResult = this.currentObservable.getCurrentResult();
|
|
208
|
-
var data = currentResult.data, loading = currentResult.loading, partial = currentResult.partial, networkStatus = currentResult.networkStatus, errors = currentResult.errors;
|
|
209
|
-
var error = currentResult.error;
|
|
210
|
-
if (errors && errors.length > 0) {
|
|
211
|
-
error = new ApolloError({ graphQLErrors: errors });
|
|
212
|
-
}
|
|
213
|
-
result = __assign(__assign({}, result), { data: data, loading: loading, networkStatus: networkStatus, error: error, called: true });
|
|
214
|
-
if (loading) {
|
|
215
|
-
}
|
|
216
|
-
else if (error) {
|
|
217
|
-
Object.assign(result, {
|
|
218
|
-
data: (this.currentObservable.getLastResult() || {})
|
|
219
|
-
.data
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
var fetchPolicy = this.currentObservable.options.fetchPolicy;
|
|
224
|
-
var partialRefetch = options.partialRefetch;
|
|
225
|
-
if (partialRefetch &&
|
|
226
|
-
partial &&
|
|
227
|
-
(!data || Object.keys(data).length === 0) &&
|
|
228
|
-
fetchPolicy !== 'cache-only') {
|
|
229
|
-
Object.assign(result, {
|
|
230
|
-
loading: true,
|
|
231
|
-
networkStatus: NetworkStatus.loading
|
|
232
|
-
});
|
|
233
|
-
result.refetch();
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
result.client = this.client;
|
|
239
|
-
this.setOptions(options, true);
|
|
240
|
-
var previousResult = this.previous.result;
|
|
241
|
-
this.previous.loading =
|
|
242
|
-
previousResult && previousResult.loading || false;
|
|
243
|
-
result.previousData = previousResult &&
|
|
244
|
-
(previousResult.data || previousResult.previousData);
|
|
245
|
-
this.previous.result = result;
|
|
246
|
-
this.currentObservable && this.currentObservable.resetQueryStoreErrors();
|
|
247
|
-
return result;
|
|
248
|
-
};
|
|
249
|
-
QueryData.prototype.handleErrorOrCompleted = function () {
|
|
250
|
-
if (!this.currentObservable || !this.previous.result)
|
|
251
|
-
return;
|
|
252
|
-
var _a = this.previous.result, data = _a.data, loading = _a.loading, error = _a.error;
|
|
253
|
-
if (!loading) {
|
|
254
|
-
var _b = this.getOptions(), query = _b.query, variables = _b.variables, onCompleted = _b.onCompleted, onError = _b.onError, skip = _b.skip;
|
|
255
|
-
if (this.previousOptions &&
|
|
256
|
-
!this.previous.loading &&
|
|
257
|
-
equal(this.previousOptions.query, query) &&
|
|
258
|
-
equal(this.previousOptions.variables, variables)) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
if (onCompleted && !error && !skip) {
|
|
262
|
-
onCompleted(data);
|
|
263
|
-
}
|
|
264
|
-
else if (onError && error) {
|
|
265
|
-
onError(error);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
QueryData.prototype.removeQuerySubscription = function () {
|
|
270
|
-
if (this.currentSubscription) {
|
|
271
|
-
this.currentSubscription.unsubscribe();
|
|
272
|
-
delete this.currentSubscription;
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
QueryData.prototype.removeObservable = function (andDelete) {
|
|
276
|
-
if (this.currentObservable) {
|
|
277
|
-
this.currentObservable["tearDownQuery"]();
|
|
278
|
-
if (andDelete) {
|
|
279
|
-
delete this.currentObservable;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
};
|
|
283
|
-
QueryData.prototype.observableQueryFields = function () {
|
|
284
|
-
var _a;
|
|
285
|
-
return {
|
|
286
|
-
variables: (_a = this.currentObservable) === null || _a === void 0 ? void 0 : _a.variables,
|
|
287
|
-
refetch: this.obsRefetch,
|
|
288
|
-
fetchMore: this.obsFetchMore,
|
|
289
|
-
updateQuery: this.obsUpdateQuery,
|
|
290
|
-
startPolling: this.obsStartPolling,
|
|
291
|
-
stopPolling: this.obsStopPolling,
|
|
292
|
-
subscribeToMore: this.obsSubscribeToMore
|
|
293
|
-
};
|
|
294
|
-
};
|
|
295
|
-
return QueryData;
|
|
296
|
-
}(OperationData));
|
|
297
|
-
export { QueryData };
|
|
298
|
-
//# sourceMappingURL=QueryData.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryData.js","sourceRoot":"","sources":["../../../src/react/data/QueryData.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,EAEL,aAAa,GAQd,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAQzC,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKhD;IAAkD,6BAEjD;IAgBC,mBAAY,EAQX;YAPC,OAAO,aAAA,EACP,OAAO,aAAA,EACP,SAAS,eAAA;QAHX,YASE,kBAAM,OAAO,EAAE,OAAO,CAAC,SAExB;QAvBO,aAAO,GAAY,KAAK,CAAC;QAEzB,cAAQ,GAQZ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAkGhB,kBAAY,GAAG,UAAC,OAAsC;YAC5D,KAAI,CAAC,OAAO,EAAE,CAAC;YACf,KAAI,CAAC,OAAO,GAAG,IAAI,CAAC;YACpB,KAAI,CAAC,WAAW,GAAG,OAAO,CAAC;YAC3B,KAAI,CAAC,SAAS,EAAE,CAAC;QACnB,CAAC,CAAC;QA6UM,gBAAU,GAAG,UAAC,SAA+B,YACnD,OAAA,MAAA,KAAI,CAAC,iBAAiB,0CAAE,OAAO,CAAC,SAAS,CAAC,CAAA,EAAA,CAAC;QAErC,kBAAY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tB,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,KAAK,CAAC;gBACxC,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,SAAS,CAAC,EAChD;gBACA,OAAO;aACR;YAED,IAAI,WAAW,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,EAAE;gBAClC,WAAW,CAAC,IAAa,CAAC,CAAC;aAC5B;iBAAM,IAAI,OAAO,IAAI,KAAK,EAAE;gBAC3B,OAAO,CAAC,KAAK,CAAC,CAAC;aAChB;SACF;IACH,CAAC;IAEO,2CAAuB,GAA/B;QACE,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC5B,IAAI,CAAC,mBAAmB,CAAC,WAAW,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,mBAAmB,CAAC;SACjC;IACH,CAAC;IAEO,oCAAgB,GAAxB,UAAyB,SAAkB;QACzC,IAAI,IAAI,CAAC,iBAAiB,EAAE;YAC1B,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,EAAE,CAAC;YAC1C,IAAI,SAAS,EAAE;gBACb,OAAO,IAAI,CAAC,iBAAiB,CAAC;aAC/B;SACF;IACH,CAAC;IAoCO,yCAAqB,GAA7B;;QACE,OAAO;YACL,SAAS,EAAE,MAAA,IAAI,CAAC,iBAAiB,0CAAE,SAAS;YAC5C,OAAO,EAAE,IAAI,CAAC,UAAU;YACxB,SAAS,EAAE,IAAI,CAAC,YAAY;YAC5B,WAAW,EAAE,IAAI,CAAC,cAAc;YAChC,YAAY,EAAE,IAAI,CAAC,eAAe;YAClC,WAAW,EAAE,IAAI,CAAC,cAAc;YAChC,eAAe,EAAE,IAAI,CAAC,kBAAkB;SACG,CAAC;IAChD,CAAC;IACH,gBAAC;AAAD,CAAC,AAjfD,CAAkD,aAAa,GAif9D","sourcesContent":["import { equal } from '@wry/equality';\n\nimport { ApolloError } from '../../errors';\n\nimport {\n ApolloClient,\n NetworkStatus,\n FetchMoreQueryOptions,\n SubscribeToMoreOptions,\n ObservableQuery,\n FetchMoreOptions,\n UpdateQueryOptions,\n DocumentNode,\n TypedDocumentNode,\n} from '../../core';\n\nimport {\n ObservableSubscription\n} from '../../utilities';\n\nimport { DocumentType } from '../parser';\nimport {\n QueryResult,\n QueryDataOptions,\n QueryTuple,\n QueryLazyOptions,\n ObservableQueryFields,\n} from '../types/types';\nimport { OperationData } from './OperationData';\n\ntype ObservableQueryOptions<TData, TVars> =\n ReturnType<QueryData<TData, TVars>[\"prepareObservableQueryOptions\"]>;\n\nexport class QueryData<TData, TVariables> extends OperationData<\n QueryDataOptions<TData, TVariables>\n> {\n public onNewData: () => void;\n public currentObservable?: ObservableQuery<TData, TVariables>;\n private currentSubscription?: ObservableSubscription;\n private runLazy: boolean = false;\n private lazyOptions?: QueryLazyOptions<TVariables>;\n private previous: {\n client?: ApolloClient<object>;\n query?: DocumentNode | TypedDocumentNode<TData, TVariables>;\n observableQueryOptions?: ObservableQueryOptions<TData, TVariables>;\n result?: QueryResult<TData, TVariables>;\n loading?: boolean;\n options?: QueryDataOptions<TData, TVariables>;\n error?: ApolloError;\n } = Object.create(null);\n\n constructor({\n options,\n context,\n onNewData\n }: {\n options: QueryDataOptions<TData, TVariables>;\n context: any;\n onNewData: () => void;\n }) {\n super(options, context);\n this.onNewData = onNewData;\n }\n\n public execute(): QueryResult<TData, TVariables> {\n this.refreshClient();\n\n const { skip, query } = this.getOptions();\n if (skip || query !== this.previous.query) {\n this.removeQuerySubscription();\n this.removeObservable(!skip);\n this.previous.query = query;\n }\n\n this.updateObservableQuery();\n\n return this.getExecuteSsrResult() || this.getExecuteResult();\n }\n\n public executeLazy(): QueryTuple<TData, TVariables> {\n return !this.runLazy\n ? [\n this.runLazyQuery,\n {\n loading: false,\n networkStatus: NetworkStatus.ready,\n called: false,\n data: undefined\n }\n ]\n : [this.runLazyQuery, this.execute()];\n }\n\n // For server-side rendering\n public fetchData(): Promise<void> | boolean {\n const options = this.getOptions();\n if (options.skip || options.ssr === false) return false;\n return new Promise(resolve => this.startQuerySubscription(resolve));\n }\n\n public afterExecute({ lazy = false }: { lazy?: boolean } = {}) {\n this.isMounted = true;\n const options = this.getOptions();\n if (this.currentObservable && !this.ssrInitiated()) {\n this.startQuerySubscription();\n }\n\n if (!lazy || this.runLazy) {\n this.handleErrorOrCompleted();\n }\n\n this.previousOptions = options;\n return this.unmount.bind(this);\n }\n\n public cleanup() {\n this.removeQuerySubscription();\n this.removeObservable(true);\n delete this.previous.result;\n }\n\n public getOptions() {\n const options = super.getOptions();\n\n if (this.lazyOptions) {\n options.variables = {\n ...options.variables,\n ...this.lazyOptions.variables\n } as TVariables;\n options.context = {\n ...options.context,\n ...this.lazyOptions.context\n };\n }\n\n // skip is not supported when using lazy query execution.\n if (this.runLazy) {\n delete options.skip;\n }\n\n return options;\n }\n\n public ssrInitiated() {\n return this.context && this.context.renderPromises;\n }\n\n private runLazyQuery = (options?: QueryLazyOptions<TVariables>) => {\n this.cleanup();\n this.runLazy = true;\n this.lazyOptions = options;\n this.onNewData();\n };\n\n private getExecuteSsrResult() {\n const { ssr, skip } = this.getOptions();\n const ssrDisabled = ssr === false;\n const fetchDisabled = this.refreshClient().client.disableNetworkFetches;\n\n const ssrLoading = {\n loading: true,\n networkStatus: NetworkStatus.loading,\n called: true,\n data: undefined,\n stale: false,\n client: this.client,\n ...this.observableQueryFields(),\n } as QueryResult<TData, TVariables>;\n\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n if (ssrDisabled && (this.ssrInitiated() || fetchDisabled)) {\n this.previous.result = ssrLoading;\n return ssrLoading;\n }\n\n if (this.ssrInitiated()) {\n const result = this.getExecuteResult() || ssrLoading;\n if (result.loading && !skip) {\n this.context.renderPromises!.addQueryPromise(this, () => null);\n }\n return result;\n }\n }\n\n private prepareObservableQueryOptions() {\n const options = this.getOptions();\n this.verifyDocumentType(options.query, DocumentType.Query);\n const displayName = options.displayName || 'Query';\n\n // Set the fetchPolicy to cache-first for network-only and cache-and-network\n // fetches for server side renders.\n if (\n this.ssrInitiated() &&\n (options.fetchPolicy === 'network-only' ||\n options.fetchPolicy === 'cache-and-network')\n ) {\n options.fetchPolicy = 'cache-first';\n }\n\n return {\n ...options,\n displayName,\n context: options.context,\n };\n }\n\n private initializeObservableQuery() {\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n if (this.ssrInitiated()) {\n this.currentObservable = this.context!.renderPromises!.getSSRObservable(\n this.getOptions()\n );\n }\n\n if (!this.currentObservable) {\n const observableQueryOptions = this.prepareObservableQueryOptions();\n\n this.previous.observableQueryOptions = {\n ...observableQueryOptions,\n children: void 0,\n };\n this.currentObservable = this.refreshClient().client.watchQuery({\n ...observableQueryOptions\n });\n\n if (this.ssrInitiated()) {\n this.context!.renderPromises!.registerSSRObservable(\n this.currentObservable,\n observableQueryOptions\n );\n }\n }\n }\n\n private updateObservableQuery() {\n // If we skipped initially, we may not have yet created the observable\n if (!this.currentObservable) {\n this.initializeObservableQuery();\n return;\n }\n\n const newObservableQueryOptions = {\n ...this.prepareObservableQueryOptions(),\n children: void 0,\n };\n\n if (this.getOptions().skip) {\n this.previous.observableQueryOptions = newObservableQueryOptions;\n return;\n }\n\n if (\n !equal(newObservableQueryOptions, this.previous.observableQueryOptions)\n ) {\n this.previous.observableQueryOptions = newObservableQueryOptions;\n this.currentObservable\n .setOptions(newObservableQueryOptions)\n // The error will be passed to the child container, so we don't\n // need to log it here. We could conceivably log something if\n // an option was set. OTOH we don't log errors w/ the original\n // query. See https://github.com/apollostack/react-apollo/issues/404\n .catch(() => {});\n }\n }\n\n // Setup a subscription to watch for Apollo Client `ObservableQuery` changes.\n // When new data is received, and it doesn't match the data that was used\n // during the last `QueryData.execute` call (and ultimately the last query\n // component render), trigger the `onNewData` callback. If not specified,\n // `onNewData` will fallback to the default `QueryData.onNewData` function\n // (which usually leads to a query component re-render).\n private startQuerySubscription(onNewData: () => void = this.onNewData) {\n if (this.currentSubscription || this.getOptions().skip) return;\n\n this.currentSubscription = this.currentObservable!.subscribe({\n next: ({ loading, networkStatus, data }) => {\n const previousResult = this.previous.result;\n\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === loading &&\n previousResult.networkStatus === networkStatus &&\n equal(previousResult.data, data)\n ) {\n return;\n }\n\n onNewData();\n },\n error: error => {\n this.resubscribeToQuery();\n if (!error.hasOwnProperty('graphQLErrors')) throw error;\n\n const previousResult = this.previous.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, this.previous.error)\n ) {\n this.previous.error = error;\n onNewData();\n }\n }\n });\n }\n\n private resubscribeToQuery() {\n this.removeQuerySubscription();\n\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n const { currentObservable } = this;\n if (currentObservable) {\n const last = currentObservable[\"last\"];\n try {\n currentObservable.resetLastResults();\n this.startQuerySubscription();\n } finally {\n currentObservable[\"last\"] = last;\n }\n }\n }\n\n private getExecuteResult(): QueryResult<TData, TVariables> {\n let result = this.observableQueryFields() as QueryResult<TData, TVariables>;\n const options = this.getOptions();\n\n // When skipping a query (ie. we're not querying for data but still want\n // to render children), make sure the `data` is cleared out and\n // `loading` is set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate\n // that previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client\n // 4.0 to address this.\n if (options.skip) {\n result = {\n ...result,\n data: undefined,\n error: undefined,\n loading: false,\n networkStatus: NetworkStatus.ready,\n called: true,\n };\n } else if (this.currentObservable) {\n // Fetch the current result (if any) from the store.\n const currentResult = this.currentObservable.getCurrentResult();\n const { data, loading, partial, networkStatus, errors } = currentResult;\n let { error } = currentResult;\n\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n if (errors && errors.length > 0) {\n error = new ApolloError({ graphQLErrors: errors });\n }\n\n result = {\n ...result,\n data,\n loading,\n networkStatus,\n error,\n called: true\n };\n\n if (loading) {\n // Fall through without modifying result...\n } else if (error) {\n Object.assign(result, {\n data: (this.currentObservable.getLastResult() || ({} as any))\n .data\n });\n } else {\n const { fetchPolicy } = this.currentObservable.options;\n const { partialRefetch } = options;\n if (\n partialRefetch &&\n partial &&\n (!data || Object.keys(data).length === 0) &&\n fetchPolicy !== 'cache-only'\n ) {\n // When a `Query` component is mounted, and a mutation is executed\n // that returns the same ID as the mounted `Query`, but has less\n // fields in its result, Apollo Client's `QueryManager` returns the\n // data as `undefined` since a hit can't be found in the cache.\n // This can lead to application errors when the UI elements rendered by\n // the original `Query` component are expecting certain data values to\n // exist, and they're all of a sudden stripped away. To help avoid\n // this we'll attempt to refetch the `Query` data.\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.loading\n });\n result.refetch();\n return result;\n }\n }\n }\n\n result.client = this.client;\n // Store options as this.previousOptions.\n this.setOptions(options, true);\n\n const previousResult = this.previous.result;\n\n this.previous.loading =\n previousResult && previousResult.loading || false;\n\n // Ensure the returned result contains previousData as a separate\n // property, to give developers the flexibility of leveraging outdated\n // data while new data is loading from the network. Falling back to\n // previousResult.previousData when previousResult.data is falsy here\n // allows result.previousData to persist across multiple results.\n result.previousData = previousResult &&\n (previousResult.data || previousResult.previousData);\n\n this.previous.result = result;\n\n // Any query errors that exist are now available in `result`, so we'll\n // remove the original errors from the `ObservableQuery` query store to\n // make sure they aren't re-displayed on subsequent (potentially error\n // free) requests/responses.\n this.currentObservable && this.currentObservable.resetQueryStoreErrors();\n\n return result;\n }\n\n private handleErrorOrCompleted() {\n if (!this.currentObservable || !this.previous.result) return;\n\n const { data, loading, error } = this.previous.result;\n\n if (!loading) {\n const {\n query,\n variables,\n onCompleted,\n onError,\n skip\n } = this.getOptions();\n\n // No changes, so we won't call onError/onCompleted.\n if (\n this.previousOptions &&\n !this.previous.loading &&\n equal(this.previousOptions.query, query) &&\n equal(this.previousOptions.variables, variables)\n ) {\n return;\n }\n\n if (onCompleted && !error && !skip) {\n onCompleted(data as TData);\n } else if (onError && error) {\n onError(error);\n }\n }\n }\n\n private removeQuerySubscription() {\n if (this.currentSubscription) {\n this.currentSubscription.unsubscribe();\n delete this.currentSubscription;\n }\n }\n\n private removeObservable(andDelete: boolean) {\n if (this.currentObservable) {\n this.currentObservable[\"tearDownQuery\"]();\n if (andDelete) {\n delete this.currentObservable;\n }\n }\n }\n\n private obsRefetch = (variables?: Partial<TVariables>) =>\n this.currentObservable?.refetch(variables);\n\n private obsFetchMore = (\n fetchMoreOptions: FetchMoreQueryOptions<TVariables, TData> &\n FetchMoreOptions<TData, TVariables>\n ) => this.currentObservable?.fetchMore(fetchMoreOptions);\n\n private obsUpdateQuery = <TVars = TVariables>(\n mapFn: (\n previousQueryResult: TData,\n options: UpdateQueryOptions<TVars>\n ) => TData\n ) => this.currentObservable?.updateQuery(mapFn);\n\n private obsStartPolling = (pollInterval: number) => {\n this.currentObservable?.startPolling(pollInterval);\n };\n\n private obsStopPolling = () => {\n this.currentObservable?.stopPolling();\n };\n\n private obsSubscribeToMore = <\n TSubscriptionData = TData,\n TSubscriptionVariables = TVariables\n >(\n options: SubscribeToMoreOptions<\n TData,\n TSubscriptionVariables,\n TSubscriptionData\n >\n ) => this.currentObservable?.subscribeToMore(options);\n\n private observableQueryFields() {\n return {\n variables: this.currentObservable?.variables,\n refetch: this.obsRefetch,\n fetchMore: this.obsFetchMore,\n updateQuery: this.obsUpdateQuery,\n startPolling: this.obsStartPolling,\n stopPolling: this.obsStopPolling,\n subscribeToMore: this.obsSubscribeToMore\n } as ObservableQueryFields<TData, TVariables>;\n }\n}\n"]}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { OperationData } from './OperationData';
|
|
2
|
-
import { SubscriptionDataOptions, SubscriptionResult } from '../types/types';
|
|
3
|
-
export declare class SubscriptionData<TData = any, TVariables = any> extends OperationData<SubscriptionDataOptions<TData, TVariables>> {
|
|
4
|
-
private setResult;
|
|
5
|
-
private currentObservable;
|
|
6
|
-
constructor({ options, context, setResult }: {
|
|
7
|
-
options: SubscriptionDataOptions<TData, TVariables>;
|
|
8
|
-
context: any;
|
|
9
|
-
setResult: any;
|
|
10
|
-
});
|
|
11
|
-
execute(result: SubscriptionResult<TData>): {
|
|
12
|
-
variables: TVariables | undefined;
|
|
13
|
-
loading: boolean;
|
|
14
|
-
data?: TData | undefined;
|
|
15
|
-
error?: import("../..").ApolloError | undefined;
|
|
16
|
-
};
|
|
17
|
-
afterExecute(): void;
|
|
18
|
-
cleanup(): void;
|
|
19
|
-
private initialize;
|
|
20
|
-
private startSubscription;
|
|
21
|
-
private getLoadingResult;
|
|
22
|
-
private updateResult;
|
|
23
|
-
private updateCurrentData;
|
|
24
|
-
private updateError;
|
|
25
|
-
private completeSubscription;
|
|
26
|
-
private endSubscription;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=SubscriptionData.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionData.d.ts","sourceRoot":"","sources":["../../../src/react/data/SubscriptionData.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAEL,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,gBAAgB,CAAC;AAExB,qBAAa,gBAAgB,CAC3B,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,GAAG,CAChB,SAAQ,aAAa,CAAC,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACjE,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,iBAAiB,CAAqC;gBAElD,EACV,OAAO,EACP,OAAO,EACP,SAAS,EACV,EAAE;QACD,OAAO,EAAE,uBAAuB,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACpD,OAAO,EAAE,GAAG,CAAC;QACb,SAAS,EAAE,GAAG,CAAC;KAChB;IAMM,OAAO,CAAC,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC;;;;;;IAwCzC,YAAY;IAIZ,OAAO;IAKd,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,iBAAiB;IAWzB,OAAO,CAAC,gBAAgB;IAQxB,OAAO,CAAC,YAAY;IAMpB,OAAO,CAAC,iBAAiB;IAiBzB,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,oBAAoB;IAW5B,OAAO,CAAC,eAAe;CAMxB"}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { __assign, __extends } from "tslib";
|
|
2
|
-
import { equal } from '@wry/equality';
|
|
3
|
-
import { OperationData } from "./OperationData.js";
|
|
4
|
-
var SubscriptionData = (function (_super) {
|
|
5
|
-
__extends(SubscriptionData, _super);
|
|
6
|
-
function SubscriptionData(_a) {
|
|
7
|
-
var options = _a.options, context = _a.context, setResult = _a.setResult;
|
|
8
|
-
var _this = _super.call(this, options, context) || this;
|
|
9
|
-
_this.currentObservable = {};
|
|
10
|
-
_this.setResult = setResult;
|
|
11
|
-
_this.initialize(options);
|
|
12
|
-
return _this;
|
|
13
|
-
}
|
|
14
|
-
SubscriptionData.prototype.execute = function (result) {
|
|
15
|
-
if (this.getOptions().skip === true) {
|
|
16
|
-
this.cleanup();
|
|
17
|
-
return {
|
|
18
|
-
loading: false,
|
|
19
|
-
error: undefined,
|
|
20
|
-
data: undefined,
|
|
21
|
-
variables: this.getOptions().variables
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
var currentResult = result;
|
|
25
|
-
if (this.refreshClient().isNew) {
|
|
26
|
-
currentResult = this.getLoadingResult();
|
|
27
|
-
}
|
|
28
|
-
var shouldResubscribe = this.getOptions().shouldResubscribe;
|
|
29
|
-
if (typeof shouldResubscribe === 'function') {
|
|
30
|
-
shouldResubscribe = !!shouldResubscribe(this.getOptions());
|
|
31
|
-
}
|
|
32
|
-
if (shouldResubscribe !== false &&
|
|
33
|
-
this.previousOptions &&
|
|
34
|
-
Object.keys(this.previousOptions).length > 0 &&
|
|
35
|
-
(this.previousOptions.subscription !== this.getOptions().subscription ||
|
|
36
|
-
!equal(this.previousOptions.variables, this.getOptions().variables) ||
|
|
37
|
-
this.previousOptions.skip !== this.getOptions().skip)) {
|
|
38
|
-
this.cleanup();
|
|
39
|
-
currentResult = this.getLoadingResult();
|
|
40
|
-
}
|
|
41
|
-
this.initialize(this.getOptions());
|
|
42
|
-
this.startSubscription();
|
|
43
|
-
this.previousOptions = this.getOptions();
|
|
44
|
-
return __assign(__assign({}, currentResult), { variables: this.getOptions().variables });
|
|
45
|
-
};
|
|
46
|
-
SubscriptionData.prototype.afterExecute = function () {
|
|
47
|
-
this.isMounted = true;
|
|
48
|
-
};
|
|
49
|
-
SubscriptionData.prototype.cleanup = function () {
|
|
50
|
-
this.endSubscription();
|
|
51
|
-
delete this.currentObservable.query;
|
|
52
|
-
};
|
|
53
|
-
SubscriptionData.prototype.initialize = function (options) {
|
|
54
|
-
if (this.currentObservable.query || this.getOptions().skip === true)
|
|
55
|
-
return;
|
|
56
|
-
this.currentObservable.query = this.refreshClient().client.subscribe({
|
|
57
|
-
query: options.subscription,
|
|
58
|
-
variables: options.variables,
|
|
59
|
-
fetchPolicy: options.fetchPolicy,
|
|
60
|
-
context: options.context,
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
SubscriptionData.prototype.startSubscription = function () {
|
|
64
|
-
if (this.currentObservable.subscription)
|
|
65
|
-
return;
|
|
66
|
-
this.currentObservable.subscription = this.currentObservable.query.subscribe({
|
|
67
|
-
next: this.updateCurrentData.bind(this),
|
|
68
|
-
error: this.updateError.bind(this),
|
|
69
|
-
complete: this.completeSubscription.bind(this)
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
SubscriptionData.prototype.getLoadingResult = function () {
|
|
73
|
-
return {
|
|
74
|
-
loading: true,
|
|
75
|
-
error: undefined,
|
|
76
|
-
data: undefined
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
SubscriptionData.prototype.updateResult = function (result) {
|
|
80
|
-
if (this.isMounted) {
|
|
81
|
-
this.setResult(result);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
SubscriptionData.prototype.updateCurrentData = function (result) {
|
|
85
|
-
var onSubscriptionData = this.getOptions().onSubscriptionData;
|
|
86
|
-
this.updateResult({
|
|
87
|
-
data: result.data,
|
|
88
|
-
loading: false,
|
|
89
|
-
error: undefined
|
|
90
|
-
});
|
|
91
|
-
if (onSubscriptionData) {
|
|
92
|
-
onSubscriptionData({
|
|
93
|
-
client: this.refreshClient().client,
|
|
94
|
-
subscriptionData: result
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
SubscriptionData.prototype.updateError = function (error) {
|
|
99
|
-
this.updateResult({
|
|
100
|
-
error: error,
|
|
101
|
-
loading: false
|
|
102
|
-
});
|
|
103
|
-
};
|
|
104
|
-
SubscriptionData.prototype.completeSubscription = function () {
|
|
105
|
-
var _this = this;
|
|
106
|
-
Promise.resolve().then(function () {
|
|
107
|
-
var onSubscriptionComplete = _this.getOptions().onSubscriptionComplete;
|
|
108
|
-
if (onSubscriptionComplete)
|
|
109
|
-
onSubscriptionComplete();
|
|
110
|
-
_this.endSubscription();
|
|
111
|
-
});
|
|
112
|
-
};
|
|
113
|
-
SubscriptionData.prototype.endSubscription = function () {
|
|
114
|
-
if (this.currentObservable.subscription) {
|
|
115
|
-
this.currentObservable.subscription.unsubscribe();
|
|
116
|
-
delete this.currentObservable.subscription;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
return SubscriptionData;
|
|
120
|
-
}(OperationData));
|
|
121
|
-
export { SubscriptionData };
|
|
122
|
-
//# sourceMappingURL=SubscriptionData.js.map
|
|
@@ -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,CAAC;IAEO,+CAAoB,GAA5B;QAAA,iBASC;QALC,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC;YACb,IAAA,sBAAsB,GAAK,KAAI,CAAC,UAAU,EAAE,uBAAtB,CAAuB;YACrD,IAAI,sBAAsB;gBAAE,sBAAsB,EAAE,CAAC;YACrD,KAAI,CAAC,eAAe,EAAE,CAAC;QACzB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,0CAAe,GAAvB;QACE,IAAI,IAAI,CAAC,iBAAiB,CAAC,YAAY,EAAE;YACvC,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,WAAW,EAAE,CAAC;YAClD,OAAO,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC;SAC5C;IACH,CAAC;IACH,uBAAC;AAAD,CAAC,AAlJD,CAGU,aAAa,GA+ItB","sourcesContent":["import { equal } from '@wry/equality';\n\nimport { OperationData } from './OperationData';\nimport {\n SubscriptionCurrentObservable,\n SubscriptionDataOptions,\n SubscriptionResult\n} from '../types/types';\n\nexport class SubscriptionData<\n TData = any,\n TVariables = any\n> extends OperationData<SubscriptionDataOptions<TData, TVariables>> {\n private setResult: any;\n private currentObservable: SubscriptionCurrentObservable = {};\n\n constructor({\n options,\n context,\n setResult\n }: {\n options: SubscriptionDataOptions<TData, TVariables>;\n context: any;\n setResult: any;\n }) {\n super(options, context);\n this.setResult = setResult;\n this.initialize(options);\n }\n\n public execute(result: SubscriptionResult<TData>) {\n if (this.getOptions().skip === true) {\n this.cleanup();\n return {\n loading: false,\n error: undefined,\n data: undefined,\n variables: this.getOptions().variables\n };\n }\n\n let currentResult = result;\n if (this.refreshClient().isNew) {\n currentResult = this.getLoadingResult();\n }\n\n let { shouldResubscribe } = this.getOptions();\n if (typeof shouldResubscribe === 'function') {\n shouldResubscribe = !!shouldResubscribe(this.getOptions());\n }\n\n if (\n shouldResubscribe !== false &&\n this.previousOptions &&\n Object.keys(this.previousOptions).length > 0 &&\n (this.previousOptions.subscription !== this.getOptions().subscription ||\n !equal(this.previousOptions.variables, this.getOptions().variables) ||\n this.previousOptions.skip !== this.getOptions().skip)\n ) {\n this.cleanup();\n currentResult = this.getLoadingResult();\n }\n\n this.initialize(this.getOptions());\n this.startSubscription();\n\n this.previousOptions = this.getOptions();\n return { ...currentResult, variables: this.getOptions().variables };\n }\n\n public afterExecute() {\n this.isMounted = true;\n }\n\n public cleanup() {\n this.endSubscription();\n delete this.currentObservable.query;\n }\n\n private initialize(options: SubscriptionDataOptions<TData, TVariables>) {\n if (this.currentObservable.query || this.getOptions().skip === true) return;\n this.currentObservable.query = this.refreshClient().client.subscribe({\n query: options.subscription,\n variables: options.variables,\n fetchPolicy: options.fetchPolicy,\n context: options.context,\n });\n }\n\n private startSubscription() {\n if (this.currentObservable.subscription) return;\n this.currentObservable.subscription = this.currentObservable.query!.subscribe(\n {\n next: this.updateCurrentData.bind(this),\n error: this.updateError.bind(this),\n complete: this.completeSubscription.bind(this)\n }\n );\n }\n\n private getLoadingResult() {\n return {\n loading: true,\n error: undefined,\n data: undefined\n } as SubscriptionResult<TData>;\n }\n\n private updateResult(result: SubscriptionResult) {\n if (this.isMounted) {\n this.setResult(result);\n }\n }\n\n private updateCurrentData(result: SubscriptionResult<TData>) {\n const { onSubscriptionData } = this.getOptions();\n\n this.updateResult({\n data: result.data,\n loading: false,\n error: undefined\n });\n\n if (onSubscriptionData) {\n onSubscriptionData({\n client: this.refreshClient().client,\n subscriptionData: result\n });\n }\n }\n\n private updateError(error: any) {\n this.updateResult({\n error,\n loading: false\n });\n }\n\n private completeSubscription() {\n // We have to defer this endSubscription call, because otherwise multiple\n // subscriptions for the same component will cause infinite rendering.\n // See https://github.com/apollographql/apollo-client/pull/7917\n Promise.resolve().then(() => {\n const { onSubscriptionComplete } = this.getOptions();\n if (onSubscriptionComplete) onSubscriptionComplete();\n this.endSubscription();\n });\n }\n\n private endSubscription() {\n if (this.currentObservable.subscription) {\n this.currentObservable.subscription.unsubscribe();\n delete this.currentObservable.subscription;\n }\n }\n}\n"]}
|