@apollo/client 3.9.0-alpha.4 → 3.9.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/.changeset/README.md +8 -0
- package/.changeset/beige-geese-wink.md +5 -0
- package/.changeset/breezy-spiders-tap.md +38 -0
- package/.changeset/clean-items-smash.md +5 -0
- package/.changeset/cold-llamas-turn.md +8 -0
- package/.changeset/config.json +14 -0
- package/.changeset/dirty-kids-crash.md +5 -0
- package/.changeset/dirty-tigers-matter.md +13 -0
- package/.changeset/forty-cups-shop.md +5 -0
- package/.changeset/friendly-clouds-laugh.md +7 -0
- package/.changeset/hot-ducks-burn.md +5 -0
- package/.changeset/mighty-coats-check.md +47 -0
- package/.changeset/polite-avocados-warn.md +5 -0
- package/.changeset/pre.json +37 -0
- package/.changeset/quick-hats-marry.md +5 -0
- package/.changeset/rare-snakes-melt.md +24 -0
- package/.changeset/shaggy-ears-scream.md +5 -0
- package/.changeset/shaggy-sheep-pull.md +5 -0
- package/.changeset/sixty-boxes-rest.md +8 -0
- package/.changeset/sour-sheep-walk.md +7 -0
- package/.changeset/strong-terms-perform.md +46 -0
- package/.changeset/swift-zoos-collect.md +19 -0
- package/.changeset/thick-mice-collect.md +5 -0
- package/.changeset/thick-tips-cry.md +9 -0
- package/.changeset/thirty-ties-arrive.md +26 -0
- package/.changeset/tough-timers-begin.md +8 -0
- package/.changeset/unlucky-rats-decide.md +5 -0
- package/.changeset/violet-lions-draw.md +5 -0
- package/.changeset/wet-forks-rhyme.md +5 -0
- package/.changeset/wild-dolphins-jog.md +5 -0
- package/.changeset/yellow-flies-repeat.md +5 -0
- package/CHANGELOG.md +3649 -0
- package/apollo-client.cjs +775 -451
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +210 -156
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +210 -156
- package/cache/core/cache.d.ts +19 -0
- package/cache/core/cache.js +28 -7
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +8 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +104 -0
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +5 -1
- package/cache/core/types/common.js +4 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +10 -1
- package/cache/inmemory/entityStore.js +190 -29
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fixPolyfills.js +9 -0
- package/cache/inmemory/fixPolyfills.js.map +1 -1
- package/cache/inmemory/fixPolyfills.native.js +12 -0
- package/cache/inmemory/fixPolyfills.native.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.d.ts +1 -0
- package/cache/inmemory/fragmentRegistry.js +39 -14
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/helpers.js +20 -11
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +9 -0
- package/cache/inmemory/inMemoryCache.js +172 -10
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +72 -4
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/object-canon.js +87 -3
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.js +190 -43
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.js +20 -2
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +4 -0
- package/cache/inmemory/readFromStore.js +65 -12
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +46 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +152 -25
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/config/jest/setup.js +2 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.d.ts +273 -3
- package/core/ApolloClient.js +239 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.d.ts +4 -6
- package/core/LocalState.js +56 -18
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +27 -0
- package/core/ObservableQuery.js +246 -31
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +4 -3
- package/core/QueryInfo.js +122 -13
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +9 -2
- package/core/QueryManager.js +259 -53
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +222 -122
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +222 -122
- package/core/equalByQuery.js +20 -1
- package/core/equalByQuery.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +19 -0
- package/core/index.js.map +1 -1
- package/core/networkStatus.d.ts +39 -0
- package/core/networkStatus.js +39 -0
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +9 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +245 -2
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +10 -119
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +10 -119
- package/dev/loadErrorMessageHandler.js.map +1 -1
- package/errors/errors.cjs +1 -1
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +1 -1
- package/errors/index.js +14 -1
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +6 -8
- package/link/batch/batch.cjs +2 -2
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +2 -2
- package/link/batch/batchLink.d.ts +21 -0
- package/link/batch/batchLink.js +2 -1
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.js +24 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs +3 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +3 -2
- package/link/batch-http/batchHttpLink.d.ts +4 -0
- package/link/batch-http/batchHttpLink.js +53 -2
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/context/context.cjs.map +1 -1
- package/link/context/index.js +1 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +15 -0
- package/link/core/ApolloLink.js +20 -9
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +13 -9
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +13 -9
- package/link/error/error.cjs +1 -1
- package/link/error/error.cjs.map +1 -1
- package/link/error/error.cjs.native.js +1 -1
- package/link/error/index.d.ts +3 -0
- package/link/error/index.js +4 -1
- package/link/error/index.js.map +1 -1
- package/link/http/HttpLink.d.ts +0 -2
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.js +23 -1
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/createSignalIfSupported.d.ts +5 -0
- package/link/http/createSignalIfSupported.js +5 -0
- package/link/http/createSignalIfSupported.js.map +1 -1
- package/link/http/http.cjs +14 -12
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +14 -12
- package/link/http/index.js +2 -1
- package/link/http/index.js.map +1 -1
- package/link/http/iterators/async.d.ts +4 -0
- package/link/http/iterators/async.js +4 -0
- package/link/http/iterators/async.js.map +1 -1
- package/link/http/iterators/nodeStream.d.ts +4 -0
- package/link/http/iterators/nodeStream.js +4 -0
- package/link/http/iterators/nodeStream.js.map +1 -1
- package/link/http/iterators/promise.d.ts +4 -0
- package/link/http/iterators/promise.js +4 -0
- package/link/http/iterators/promise.js.map +1 -1
- package/link/http/iterators/reader.d.ts +4 -0
- package/link/http/iterators/reader.js +4 -0
- package/link/http/iterators/reader.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +51 -10
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/responseIterator.d.ts +4 -0
- package/link/http/responseIterator.js +6 -0
- package/link/http/responseIterator.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +1 -1
- package/link/http/rewriteURIForGET.js +10 -0
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
- package/link/http/selectHttpOptionsAndBody.js +23 -0
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.js.map +1 -1
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.d.ts +11 -1
- package/link/persisted-queries/index.js +62 -7
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +30 -7
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +30 -7
- package/link/remove-typename/remove-typename.cjs +30 -11
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +30 -11
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -1
- package/link/remove-typename/removeTypenameFromVariables.js +31 -12
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/delayFunction.d.ts +29 -0
- package/link/retry/delayFunction.js +6 -0
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retry.cjs +5 -5
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +5 -5
- package/link/retry/retryFunction.d.ts +20 -0
- package/link/retry/retryLink.d.ts +6 -0
- package/link/retry/retryLink.js +31 -6
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +13 -0
- package/link/schema/index.js +3 -3
- package/link/schema/index.js.map +1 -1
- package/link/schema/schema.cjs +3 -3
- package/link/schema/schema.cjs.map +1 -1
- package/link/schema/schema.cjs.native.js +3 -3
- package/link/subscriptions/index.js +35 -2
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +3 -2
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +3 -2
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/filterOperationVariables.js +4 -0
- package/link/utils/filterOperationVariables.js.map +1 -1
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/transformOperation.js +3 -2
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +12 -0
- package/link/ws/index.js +1 -1
- package/link/ws/index.js.map +1 -1
- package/link/ws/ws.cjs +1 -1
- package/link/ws/ws.cjs.map +1 -1
- package/link/ws/ws.cjs.native.js +1 -1
- package/package.json +53 -41
- package/react/cache/QueryReference.d.ts +27 -13
- package/react/cache/QueryReference.js +122 -42
- package/react/cache/QueryReference.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +10 -0
- package/react/cache/SuspenseCache.js +1 -2
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/cache/getSuspenseCache.js.map +1 -1
- package/react/cache/types.d.ts +3 -0
- package/react/cache/types.js.map +1 -1
- package/react/context/ApolloContext.d.ts +5 -0
- package/react/context/ApolloContext.js +10 -3
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/context.cjs +1 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +1 -3
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.js +3 -1
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs +9 -17
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +9 -17
- package/react/hoc/mutation-hoc.js +9 -4
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +10 -4
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +10 -4
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +3 -4
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +230 -98
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +230 -98
- package/react/hooks/index.d.ts +4 -0
- package/react/hooks/index.js +2 -0
- package/react/hooks/index.js.map +1 -1
- package/react/hooks/internal/__use.js +5 -0
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.js +2 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
- package/react/hooks/internal/useRenderGuard.d.ts +2 -0
- package/react/hooks/internal/useRenderGuard.js +17 -0
- package/react/hooks/internal/useRenderGuard.js.map +1 -0
- package/react/hooks/useBackgroundQuery.d.ts +12 -9
- package/react/hooks/useBackgroundQuery.js +14 -11
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +4 -3
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +30 -0
- package/react/hooks/useLoadableQuery.js +61 -0
- package/react/hooks/useLoadableQuery.js.map +1 -0
- package/react/hooks/useMutation.js +8 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +11 -0
- package/react/hooks/useQuery.js +138 -6
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +35 -0
- package/react/hooks/useQueryRefHandlers.js +48 -0
- package/react/hooks/useQueryRefHandlers.js.map +1 -0
- package/react/hooks/useReactiveVar.js +5 -0
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +19 -0
- package/react/hooks/useReadQuery.js +9 -9
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +5 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +22 -22
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +53 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/index.d.ts +2 -0
- package/react/index.js +1 -0
- package/react/index.js.map +1 -1
- package/react/parser/index.d.ts +3 -0
- package/react/parser/index.js +16 -6
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +19 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +19 -5
- package/react/query-preloader/createQueryPreloader.d.ts +253 -0
- package/react/query-preloader/createQueryPreloader.js +29 -0
- package/react/query-preloader/createQueryPreloader.js.map +1 -0
- package/react/react.cjs +248 -1
- package/react/react.cjs.map +1 -1
- package/react/react.cjs.native.js +248 -1
- package/react/ssr/RenderPromises.js +21 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/getDataFromTree.js +18 -3
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/ssr.cjs +6 -4
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/ssr/ssr.cjs.native.js +6 -4
- package/react/types/types.d.ts +129 -1
- package/react/types/types.js.map +1 -1
- package/testing/core/core.cjs +14 -11
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +14 -11
- package/testing/core/itAsync.d.ts +1 -1
- package/testing/core/itAsync.js.map +1 -1
- package/testing/core/mocking/mockFetch.d.ts +2 -2
- package/testing/core/mocking/mockFetch.js +8 -4
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +1 -1
- package/testing/core/mocking/mockLink.js +17 -7
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.js +2 -0
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/testing/core/mocking/mockWatchQuery.js +1 -1
- package/testing/core/mocking/mockWatchQuery.js.map +1 -1
- package/testing/core/observableToPromise.d.ts +17 -3
- package/testing/core/observableToPromise.js +5 -0
- package/testing/core/observableToPromise.js.map +1 -1
- package/testing/core/subscribeAndCount.js +3 -0
- package/testing/core/subscribeAndCount.js.map +1 -1
- package/testing/core/wait.js +2 -2
- package/testing/core/wait.js.map +1 -1
- package/testing/core/withConsoleSpy.d.ts +3 -0
- package/testing/core/withConsoleSpy.js +7 -1
- package/testing/core/withConsoleSpy.js.map +1 -1
- package/testing/core/wrap.js +2 -0
- package/testing/core/wrap.js.map +1 -1
- package/testing/internal/ObservableStream.js +14 -14
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/disposables/disableActWarnings.d.ts +10 -0
- package/testing/internal/disposables/disableActWarnings.js +15 -0
- package/testing/internal/disposables/disableActWarnings.js.map +1 -0
- package/testing/internal/disposables/index.d.ts +1 -0
- package/testing/internal/disposables/index.js +1 -0
- package/testing/internal/disposables/index.js.map +1 -1
- package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
- package/testing/internal/disposables/spyOnConsole.js +2 -0
- package/testing/internal/disposables/spyOnConsole.js.map +1 -1
- package/testing/internal/disposables/withCleanup.d.ts +1 -0
- package/testing/internal/disposables/withCleanup.js +3 -0
- package/testing/internal/disposables/withCleanup.js.map +1 -1
- package/testing/internal/index.d.ts +4 -0
- package/testing/internal/index.js +2 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/profile/Render.d.ts +32 -1
- package/testing/internal/profile/Render.js +14 -2
- package/testing/internal/profile/Render.js.map +1 -1
- package/testing/internal/profile/context.d.ts +10 -0
- package/testing/internal/profile/context.js +14 -0
- package/testing/internal/profile/context.js.map +1 -0
- package/testing/internal/profile/index.d.ts +2 -2
- package/testing/internal/profile/index.js +1 -1
- package/testing/internal/profile/index.js.map +1 -1
- package/testing/internal/profile/profile.d.ts +67 -13
- package/testing/internal/profile/profile.js +153 -79
- package/testing/internal/profile/profile.js.map +1 -1
- package/testing/internal/profile/traces.d.ts +4 -0
- package/testing/internal/profile/traces.js +9 -5
- package/testing/internal/profile/traces.js.map +1 -1
- package/testing/internal/renderHelpers.d.ts +12 -0
- package/testing/internal/renderHelpers.js +22 -0
- package/testing/internal/renderHelpers.js.map +1 -0
- package/testing/internal/scenarios/index.d.ts +41 -0
- package/testing/internal/scenarios/index.js +46 -0
- package/testing/internal/scenarios/index.js.map +1 -0
- package/testing/matchers/ProfiledComponent.js +29 -26
- package/testing/matchers/ProfiledComponent.js.map +1 -1
- package/testing/matchers/index.js +4 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toBeDisposed.d.ts +3 -0
- package/testing/matchers/toBeDisposed.js +26 -0
- package/testing/matchers/toBeDisposed.js.map +1 -0
- package/testing/matchers/toBeGarbageCollected.d.ts +8 -0
- package/testing/matchers/toBeGarbageCollected.js +48 -0
- package/testing/matchers/toBeGarbageCollected.js.map +1 -0
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/testing/matchers/toMatchDocument.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +5 -1
- package/testing/react/MockedProvider.js +6 -2
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +4 -2
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +4 -2
- package/utilities/caching/caches.d.ts +34 -0
- package/utilities/caching/caches.js +64 -0
- package/utilities/caching/caches.js.map +1 -0
- package/utilities/caching/getMemoryInternals.d.ts +76 -0
- package/utilities/caching/getMemoryInternals.js +112 -0
- package/utilities/caching/getMemoryInternals.js.map +1 -0
- package/utilities/caching/index.d.ts +4 -0
- package/utilities/caching/index.js +3 -0
- package/utilities/caching/index.js.map +1 -0
- package/utilities/caching/sizes.d.ts +261 -0
- package/utilities/caching/sizes.js +27 -0
- package/utilities/caching/sizes.js.map +1 -0
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/canUse.js +17 -2
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.d.ts +17 -0
- package/utilities/common/canonicalStringify.js +49 -2
- package/utilities/common/canonicalStringify.js.map +1 -1
- package/utilities/common/cloneDeep.d.ts +3 -0
- package/utilities/common/cloneDeep.js +5 -0
- package/utilities/common/cloneDeep.js.map +1 -1
- package/utilities/common/compact.d.ts +4 -0
- package/utilities/common/compact.js +4 -0
- package/utilities/common/compact.js.map +1 -1
- package/utilities/common/errorHandling.js +1 -3
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.js +3 -0
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/common/makeUniqueId.js +2 -0
- package/utilities/common/makeUniqueId.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +3 -0
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/common/mergeDeep.js +12 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/common/omitDeep.js.map +1 -1
- package/utilities/globals/global.js +7 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +4 -5
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +4 -5
- package/utilities/globals/index.d.ts +4 -0
- package/utilities/globals/index.js +7 -0
- package/utilities/globals/index.js.map +1 -1
- package/utilities/globals/invariantWrappers.d.ts +40 -0
- package/utilities/globals/invariantWrappers.js +11 -3
- package/utilities/globals/invariantWrappers.js.map +1 -1
- package/utilities/globals/maybe.js.map +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +20 -6
- package/utilities/graphql/DocumentTransform.js +54 -29
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/directives.js +3 -0
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts +25 -0
- package/utilities/graphql/fragments.js +36 -0
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts +5 -0
- package/utilities/graphql/getFromAST.js +9 -0
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/print.js +8 -5
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +14 -0
- package/utilities/graphql/storeUtils.js +8 -2
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +106 -7
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/index.d.ts +4 -0
- package/utilities/index.js +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/observables/Concast.d.ts +1 -1
- package/utilities/observables/Concast.js +85 -2
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/Observable.js +6 -0
- package/utilities/observables/Observable.js.map +1 -1
- package/utilities/observables/asyncMap.js +12 -3
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/observables/iteration.js +3 -0
- package/utilities/observables/iteration.js.map +1 -1
- package/utilities/observables/subclassing.js +14 -0
- package/utilities/observables/subclassing.js.map +1 -1
- package/utilities/policies/pagination.js +47 -3
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/promises/decoration.js +1 -0
- package/utilities/promises/decoration.js.map +1 -1
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/utilities/subscriptions/relay/relay.cjs +9 -8
- package/utilities/subscriptions/relay/relay.cjs.map +1 -1
- package/utilities/subscriptions/relay/relay.cjs.native.js +9 -8
- package/utilities/subscriptions/urql/index.js.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs +9 -8
- package/utilities/subscriptions/urql/urql.cjs.map +1 -1
- package/utilities/subscriptions/urql/urql.cjs.native.js +9 -8
- package/utilities/types/DeepOmit.js.map +1 -1
- package/utilities/types/DeepPartial.d.ts +1 -1
- package/utilities/types/DeepPartial.js +4 -0
- package/utilities/types/DeepPartial.js.map +1 -1
- package/utilities/types/IsStrictlyAny.js.map +1 -1
- package/utilities/types/OnlyRequiredProperties.d.ts +7 -0
- package/utilities/types/OnlyRequiredProperties.js +2 -0
- package/utilities/types/OnlyRequiredProperties.js.map +1 -0
- package/utilities/types/TODO.d.ts +3 -0
- package/utilities/types/TODO.js +2 -0
- package/utilities/types/TODO.js.map +1 -0
- package/utilities/utilities.cjs +114 -58
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +114 -58
- package/version.js +1 -1
- package/cache/core/cache.d.ts.map +0 -1
- package/cache/core/types/Cache.d.ts.map +0 -1
- package/cache/core/types/DataProxy.d.ts.map +0 -1
- package/cache/core/types/common.d.ts.map +0 -1
- package/cache/index.d.ts.map +0 -1
- package/cache/inmemory/entityStore.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
- package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
- package/cache/inmemory/helpers.d.ts.map +0 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
- package/cache/inmemory/key-extractor.d.ts.map +0 -1
- package/cache/inmemory/object-canon.d.ts.map +0 -1
- package/cache/inmemory/policies.d.ts.map +0 -1
- package/cache/inmemory/reactiveVars.d.ts.map +0 -1
- package/cache/inmemory/readFromStore.d.ts.map +0 -1
- package/cache/inmemory/types.d.ts.map +0 -1
- package/cache/inmemory/writeToStore.d.ts.map +0 -1
- package/config/jest/setup.d.ts.map +0 -1
- package/core/ApolloClient.d.ts.map +0 -1
- package/core/LocalState.d.ts.map +0 -1
- package/core/ObservableQuery.d.ts.map +0 -1
- package/core/QueryInfo.d.ts.map +0 -1
- package/core/QueryManager.d.ts.map +0 -1
- package/core/equalByQuery.d.ts.map +0 -1
- package/core/index.d.ts.map +0 -1
- package/core/networkStatus.d.ts.map +0 -1
- package/core/types.d.ts.map +0 -1
- package/core/watchQueryOptions.d.ts.map +0 -1
- package/dev/index.d.ts.map +0 -1
- package/dev/loadDevMessages.d.ts.map +0 -1
- package/dev/loadErrorMessageHandler.d.ts.map +0 -1
- package/dev/loadErrorMessages.d.ts.map +0 -1
- package/errors/index.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/invariantErrorCodes.d.ts.map +0 -1
- package/link/batch/batchLink.d.ts.map +0 -1
- package/link/batch/batching.d.ts.map +0 -1
- package/link/batch/index.d.ts.map +0 -1
- package/link/batch-http/batchHttpLink.d.ts.map +0 -1
- package/link/batch-http/index.d.ts.map +0 -1
- package/link/context/index.d.ts.map +0 -1
- package/link/core/ApolloLink.d.ts.map +0 -1
- package/link/core/concat.d.ts.map +0 -1
- package/link/core/empty.d.ts.map +0 -1
- package/link/core/execute.d.ts.map +0 -1
- package/link/core/from.d.ts.map +0 -1
- package/link/core/index.d.ts.map +0 -1
- package/link/core/split.d.ts.map +0 -1
- package/link/core/types.d.ts.map +0 -1
- package/link/error/index.d.ts.map +0 -1
- package/link/http/HttpLink.d.ts.map +0 -1
- package/link/http/checkFetcher.d.ts.map +0 -1
- package/link/http/createHttpLink.d.ts.map +0 -1
- package/link/http/createSignalIfSupported.d.ts.map +0 -1
- package/link/http/index.d.ts.map +0 -1
- package/link/http/iterators/async.d.ts.map +0 -1
- package/link/http/iterators/nodeStream.d.ts.map +0 -1
- package/link/http/iterators/promise.d.ts.map +0 -1
- package/link/http/iterators/reader.d.ts.map +0 -1
- package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
- package/link/http/responseIterator.d.ts.map +0 -1
- package/link/http/rewriteURIForGET.d.ts.map +0 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
- package/link/http/selectURI.d.ts.map +0 -1
- package/link/http/serializeFetchParameter.d.ts.map +0 -1
- package/link/persisted-queries/index.d.ts.map +0 -1
- package/link/remove-typename/index.d.ts.map +0 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
- package/link/retry/delayFunction.d.ts.map +0 -1
- package/link/retry/index.d.ts.map +0 -1
- package/link/retry/retryFunction.d.ts.map +0 -1
- package/link/retry/retryLink.d.ts.map +0 -1
- package/link/schema/index.d.ts.map +0 -1
- package/link/subscriptions/index.d.ts.map +0 -1
- package/link/utils/createOperation.d.ts.map +0 -1
- package/link/utils/filterOperationVariables.d.ts.map +0 -1
- package/link/utils/fromError.d.ts.map +0 -1
- package/link/utils/fromPromise.d.ts.map +0 -1
- package/link/utils/index.d.ts.map +0 -1
- package/link/utils/throwServerError.d.ts.map +0 -1
- package/link/utils/toPromise.d.ts.map +0 -1
- package/link/utils/transformOperation.d.ts.map +0 -1
- package/link/utils/validateOperation.d.ts.map +0 -1
- package/link/ws/index.d.ts.map +0 -1
- package/react/cache/QueryReference.d.ts.map +0 -1
- package/react/cache/SuspenseCache.d.ts.map +0 -1
- package/react/cache/getSuspenseCache.d.ts.map +0 -1
- package/react/cache/index.d.ts.map +0 -1
- package/react/cache/types.d.ts.map +0 -1
- package/react/components/Mutation.d.ts.map +0 -1
- package/react/components/Query.d.ts.map +0 -1
- package/react/components/Subscription.d.ts.map +0 -1
- package/react/components/index.d.ts.map +0 -1
- package/react/components/types.d.ts.map +0 -1
- package/react/context/ApolloConsumer.d.ts.map +0 -1
- package/react/context/ApolloContext.d.ts.map +0 -1
- package/react/context/ApolloProvider.d.ts.map +0 -1
- package/react/context/index.d.ts.map +0 -1
- package/react/hoc/graphql.d.ts.map +0 -1
- package/react/hoc/hoc-utils.d.ts.map +0 -1
- package/react/hoc/index.d.ts.map +0 -1
- package/react/hoc/mutation-hoc.d.ts.map +0 -1
- package/react/hoc/query-hoc.d.ts.map +0 -1
- package/react/hoc/subscription-hoc.d.ts.map +0 -1
- package/react/hoc/types.d.ts.map +0 -1
- package/react/hoc/withApollo.d.ts.map +0 -1
- package/react/hooks/constants.d.ts.map +0 -1
- package/react/hooks/index.d.ts.map +0 -1
- package/react/hooks/internal/__use.d.ts.map +0 -1
- package/react/hooks/internal/index.d.ts.map +0 -1
- package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
- package/react/hooks/useApolloClient.d.ts.map +0 -1
- package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
- package/react/hooks/useFragment.d.ts.map +0 -1
- package/react/hooks/useLazyQuery.d.ts.map +0 -1
- package/react/hooks/useMutation.d.ts.map +0 -1
- package/react/hooks/useQuery.d.ts.map +0 -1
- package/react/hooks/useReactiveVar.d.ts.map +0 -1
- package/react/hooks/useReadQuery.d.ts.map +0 -1
- package/react/hooks/useSubscription.d.ts.map +0 -1
- package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
- package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
- package/react/index.d.ts.map +0 -1
- package/react/parser/index.d.ts.map +0 -1
- package/react/ssr/RenderPromises.d.ts.map +0 -1
- package/react/ssr/getDataFromTree.d.ts.map +0 -1
- package/react/ssr/index.d.ts.map +0 -1
- package/react/ssr/renderToStringWithData.d.ts.map +0 -1
- package/react/types/types.d.ts.map +0 -1
- package/testing/core/index.d.ts.map +0 -1
- package/testing/core/itAsync.d.ts.map +0 -1
- package/testing/core/mocking/mockClient.d.ts.map +0 -1
- package/testing/core/mocking/mockFetch.d.ts.map +0 -1
- package/testing/core/mocking/mockLink.d.ts.map +0 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
- package/testing/core/observableToPromise.d.ts.map +0 -1
- package/testing/core/subscribeAndCount.d.ts.map +0 -1
- package/testing/core/wait.d.ts.map +0 -1
- package/testing/core/withConsoleSpy.d.ts.map +0 -1
- package/testing/core/wrap.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/internal/ObservableStream.d.ts.map +0 -1
- package/testing/internal/disposables/index.d.ts.map +0 -1
- package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
- package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
- package/testing/internal/index.d.ts.map +0 -1
- package/testing/internal/profile/Render.d.ts.map +0 -1
- package/testing/internal/profile/index.d.ts.map +0 -1
- package/testing/internal/profile/profile.d.ts.map +0 -1
- package/testing/internal/profile/traces.d.ts.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
- package/testing/matchers/index.d.ts.map +0 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
- package/testing/matchers/toMatchDocument.d.ts.map +0 -1
- package/testing/react/MockedProvider.d.ts.map +0 -1
- package/utilities/common/arrays.d.ts.map +0 -1
- package/utilities/common/canUse.d.ts.map +0 -1
- package/utilities/common/canonicalStringify.d.ts.map +0 -1
- package/utilities/common/cloneDeep.d.ts.map +0 -1
- package/utilities/common/compact.d.ts.map +0 -1
- package/utilities/common/errorHandling.d.ts.map +0 -1
- package/utilities/common/filterInPlace.d.ts +0 -2
- package/utilities/common/filterInPlace.d.ts.map +0 -1
- package/utilities/common/filterInPlace.js +0 -11
- package/utilities/common/filterInPlace.js.map +0 -1
- package/utilities/common/incrementalResult.d.ts.map +0 -1
- package/utilities/common/makeUniqueId.d.ts.map +0 -1
- package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
- package/utilities/common/mergeDeep.d.ts.map +0 -1
- package/utilities/common/mergeOptions.d.ts.map +0 -1
- package/utilities/common/objects.d.ts.map +0 -1
- package/utilities/common/omitDeep.d.ts.map +0 -1
- package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
- package/utilities/common/stripTypename.d.ts.map +0 -1
- package/utilities/globals/global.d.ts.map +0 -1
- package/utilities/globals/index.d.ts.map +0 -1
- package/utilities/globals/invariantWrappers.d.ts.map +0 -1
- package/utilities/globals/maybe.d.ts.map +0 -1
- package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
- package/utilities/graphql/directives.d.ts.map +0 -1
- package/utilities/graphql/fragments.d.ts.map +0 -1
- package/utilities/graphql/getFromAST.d.ts.map +0 -1
- package/utilities/graphql/operations.d.ts.map +0 -1
- package/utilities/graphql/print.d.ts.map +0 -1
- package/utilities/graphql/storeUtils.d.ts.map +0 -1
- package/utilities/graphql/transform.d.ts.map +0 -1
- package/utilities/index.d.ts.map +0 -1
- package/utilities/observables/Concast.d.ts.map +0 -1
- package/utilities/observables/Observable.d.ts.map +0 -1
- package/utilities/observables/asyncMap.d.ts.map +0 -1
- package/utilities/observables/iteration.d.ts.map +0 -1
- package/utilities/observables/subclassing.d.ts.map +0 -1
- package/utilities/policies/pagination.d.ts.map +0 -1
- package/utilities/promises/decoration.d.ts.map +0 -1
- package/utilities/subscriptions/relay/index.d.ts.map +0 -1
- package/utilities/subscriptions/shared.d.ts.map +0 -1
- package/utilities/subscriptions/urql/index.d.ts.map +0 -1
- package/utilities/types/DeepOmit.d.ts.map +0 -1
- package/utilities/types/DeepPartial.d.ts.map +0 -1
- package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
- package/utilities/types/Primitive.d.ts.map +0 -1
- package/version.d.ts.map +0 -1
package/core/ObservableQuery.js
CHANGED
|
@@ -5,11 +5,13 @@ import { NetworkStatus, isNetworkRequestInFlight } from "./networkStatus.js";
|
|
|
5
5
|
import { cloneDeep, compact, getOperationDefinition, Observable, iterateObserversSafely, fixObservableSubclass, getQueryDefinition, } from "../utilities/index.js";
|
|
6
6
|
import { equalByQuery } from "./equalByQuery.js";
|
|
7
7
|
var assign = Object.assign, hasOwnProperty = Object.hasOwnProperty;
|
|
8
|
-
var ObservableQuery = (function (_super) {
|
|
8
|
+
var ObservableQuery = /** @class */ (function (_super) {
|
|
9
9
|
__extends(ObservableQuery, _super);
|
|
10
10
|
function ObservableQuery(_a) {
|
|
11
11
|
var queryManager = _a.queryManager, queryInfo = _a.queryInfo, options = _a.options;
|
|
12
12
|
var _this = _super.call(this, function (observer) {
|
|
13
|
+
// Zen Observable has its own error function, so in order to log correctly
|
|
14
|
+
// we need to provide a custom error callback.
|
|
13
15
|
try {
|
|
14
16
|
var subObserver = observer._subscription._observer;
|
|
15
17
|
if (subObserver && !subObserver.error) {
|
|
@@ -19,6 +21,7 @@ var ObservableQuery = (function (_super) {
|
|
|
19
21
|
catch (_a) { }
|
|
20
22
|
var first = !_this.observers.size;
|
|
21
23
|
_this.observers.add(observer);
|
|
24
|
+
// Deliver most recent error or result.
|
|
22
25
|
var last = _this.last;
|
|
23
26
|
if (last && last.error) {
|
|
24
27
|
observer.error && observer.error(last.error);
|
|
@@ -26,7 +29,13 @@ var ObservableQuery = (function (_super) {
|
|
|
26
29
|
else if (last && last.result) {
|
|
27
30
|
observer.next && observer.next(last.result);
|
|
28
31
|
}
|
|
32
|
+
// Initiate observation of this query if it hasn't been reported to
|
|
33
|
+
// the QueryManager yet.
|
|
29
34
|
if (first) {
|
|
35
|
+
// Blindly catching here prevents unhandled promise rejections,
|
|
36
|
+
// and is safe because the ObservableQuery handles this error with
|
|
37
|
+
// this.observer.error, so we're not just swallowing the error by
|
|
38
|
+
// ignoring it here.
|
|
30
39
|
_this.reobserve().catch(function () { });
|
|
31
40
|
}
|
|
32
41
|
return function () {
|
|
@@ -37,21 +46,36 @@ var ObservableQuery = (function (_super) {
|
|
|
37
46
|
}) || this;
|
|
38
47
|
_this.observers = new Set();
|
|
39
48
|
_this.subscriptions = new Set();
|
|
49
|
+
// related classes
|
|
40
50
|
_this.queryInfo = queryInfo;
|
|
41
51
|
_this.queryManager = queryManager;
|
|
52
|
+
// active state
|
|
42
53
|
_this.waitForOwnResult = skipCacheDataFor(options.fetchPolicy);
|
|
43
54
|
_this.isTornDown = false;
|
|
44
55
|
var _b = queryManager.defaultOptions.watchQuery, _c = _b === void 0 ? {} : _b, _d = _c.fetchPolicy, defaultFetchPolicy = _d === void 0 ? "cache-first" : _d;
|
|
45
|
-
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
var _e = options.fetchPolicy, fetchPolicy = _e === void 0 ? defaultFetchPolicy : _e,
|
|
57
|
+
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
58
|
+
_f = options.initialFetchPolicy,
|
|
59
|
+
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
60
|
+
initialFetchPolicy = _f === void 0 ? fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy) : _f;
|
|
61
|
+
_this.options = __assign(__assign({}, options), {
|
|
62
|
+
// Remember the initial options.fetchPolicy so we can revert back to this
|
|
63
|
+
// policy when variables change. This information can also be specified
|
|
64
|
+
// (or overridden) by providing options.initialFetchPolicy explicitly.
|
|
65
|
+
initialFetchPolicy: initialFetchPolicy,
|
|
66
|
+
// This ensures this.options.fetchPolicy always has a string value, in
|
|
67
|
+
// case options.fetchPolicy was not provided.
|
|
68
|
+
fetchPolicy: fetchPolicy });
|
|
49
69
|
_this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
50
70
|
var opDef = getOperationDefinition(_this.query);
|
|
51
71
|
_this.queryName = opDef && opDef.name && opDef.name.value;
|
|
52
72
|
return _this;
|
|
53
73
|
}
|
|
54
74
|
Object.defineProperty(ObservableQuery.prototype, "query", {
|
|
75
|
+
// The `query` computed property will always reflect the document transformed
|
|
76
|
+
// by the last run query. `this.options.query` will always reflect the raw
|
|
77
|
+
// untransformed query to ensure document transforms with runtime conditionals
|
|
78
|
+
// are run on the original document.
|
|
55
79
|
get: function () {
|
|
56
80
|
return this.lastQuery || this.options.query;
|
|
57
81
|
},
|
|
@@ -59,6 +83,8 @@ var ObservableQuery = (function (_super) {
|
|
|
59
83
|
configurable: true
|
|
60
84
|
});
|
|
61
85
|
Object.defineProperty(ObservableQuery.prototype, "variables", {
|
|
86
|
+
// Computed shorthand for this.options.variables, preserved for
|
|
87
|
+
// backwards compatibility.
|
|
62
88
|
get: function () {
|
|
63
89
|
return this.options.variables;
|
|
64
90
|
},
|
|
@@ -68,9 +94,22 @@ var ObservableQuery = (function (_super) {
|
|
|
68
94
|
ObservableQuery.prototype.result = function () {
|
|
69
95
|
var _this = this;
|
|
70
96
|
return new Promise(function (resolve, reject) {
|
|
97
|
+
// TODO: this code doesn’t actually make sense insofar as the observer
|
|
98
|
+
// will never exist in this.observers due how zen-observable wraps observables.
|
|
99
|
+
// https://github.com/zenparsing/zen-observable/blob/master/src/Observable.js#L169
|
|
71
100
|
var observer = {
|
|
72
101
|
next: function (result) {
|
|
73
102
|
resolve(result);
|
|
103
|
+
// Stop the query within the QueryManager if we can before
|
|
104
|
+
// this function returns.
|
|
105
|
+
//
|
|
106
|
+
// We do this in order to prevent observers piling up within
|
|
107
|
+
// the QueryManager. Notice that we only fully unsubscribe
|
|
108
|
+
// from the subscription in a setTimeout(..., 0) call. This call can
|
|
109
|
+
// actually be handled by the browser at a much later time. If queries
|
|
110
|
+
// are fired in the meantime, observers that should have been removed
|
|
111
|
+
// from the QueryManager will continue to fire, causing an unnecessary
|
|
112
|
+
// performance hit.
|
|
74
113
|
_this.observers.delete(observer);
|
|
75
114
|
if (!_this.observers.size) {
|
|
76
115
|
_this.queryManager.removeQuery(_this.queryId);
|
|
@@ -84,18 +123,34 @@ var ObservableQuery = (function (_super) {
|
|
|
84
123
|
var subscription = _this.subscribe(observer);
|
|
85
124
|
});
|
|
86
125
|
};
|
|
126
|
+
/** @internal */
|
|
127
|
+
ObservableQuery.prototype.resetDiff = function () {
|
|
128
|
+
this.queryInfo.resetDiff();
|
|
129
|
+
};
|
|
87
130
|
ObservableQuery.prototype.getCurrentResult = function (saveAsLastResult) {
|
|
88
131
|
if (saveAsLastResult === void 0) { saveAsLastResult = true; }
|
|
132
|
+
// Use the last result as long as the variables match this.variables.
|
|
89
133
|
var lastResult = this.getLastResult(true);
|
|
90
134
|
var networkStatus = this.queryInfo.networkStatus ||
|
|
91
135
|
(lastResult && lastResult.networkStatus) ||
|
|
92
136
|
NetworkStatus.ready;
|
|
93
137
|
var result = __assign(__assign({}, lastResult), { loading: isNetworkRequestInFlight(networkStatus), networkStatus: networkStatus });
|
|
94
138
|
var _a = this.options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a;
|
|
95
|
-
if (
|
|
139
|
+
if (
|
|
140
|
+
// These fetch policies should never deliver data from the cache, unless
|
|
141
|
+
// redelivering a previously delivered result.
|
|
142
|
+
skipCacheDataFor(fetchPolicy) ||
|
|
143
|
+
// If this.options.query has @client(always: true) fields, we cannot
|
|
144
|
+
// trust diff.result, since it was read from the cache without running
|
|
145
|
+
// local resolvers (and it's too late to run resolvers now, since we must
|
|
146
|
+
// return a result synchronously).
|
|
96
147
|
this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) {
|
|
148
|
+
// Fall through.
|
|
97
149
|
}
|
|
98
150
|
else if (this.waitForOwnResult) {
|
|
151
|
+
// This would usually be a part of `QueryInfo.getDiff()`.
|
|
152
|
+
// which we skip in the waitForOwnResult case since we are not
|
|
153
|
+
// interested in the diff.
|
|
99
154
|
this.queryInfo["updateWatch"]();
|
|
100
155
|
}
|
|
101
156
|
else {
|
|
@@ -107,7 +162,12 @@ var ObservableQuery = (function (_super) {
|
|
|
107
162
|
result.data = void 0;
|
|
108
163
|
}
|
|
109
164
|
if (diff.complete) {
|
|
165
|
+
// Similar to setting result.partial to false, but taking advantage of the
|
|
166
|
+
// falsiness of missing fields.
|
|
110
167
|
delete result.partial;
|
|
168
|
+
// If the diff is complete, and we're using a FetchPolicy that
|
|
169
|
+
// terminates after a complete cache read, we can assume the next result
|
|
170
|
+
// we receive will have NetworkStatus.ready and !loading.
|
|
111
171
|
if (diff.complete &&
|
|
112
172
|
result.networkStatus === NetworkStatus.loading &&
|
|
113
173
|
(fetchPolicy === "cache-first" || fetchPolicy === "cache-only")) {
|
|
@@ -132,13 +192,14 @@ var ObservableQuery = (function (_super) {
|
|
|
132
192
|
}
|
|
133
193
|
return result;
|
|
134
194
|
};
|
|
195
|
+
// Compares newResult to the snapshot we took of this.lastResult when it was
|
|
196
|
+
// first received.
|
|
135
197
|
ObservableQuery.prototype.isDifferentFromLastResult = function (newResult, variables) {
|
|
136
198
|
if (!this.last) {
|
|
137
199
|
return true;
|
|
138
200
|
}
|
|
139
|
-
var resultIsDifferent = this.queryManager.getDocumentInfo(this.query)
|
|
140
|
-
.
|
|
141
|
-
? !equalByQuery(this.query, this.last.result, newResult, this.variables)
|
|
201
|
+
var resultIsDifferent = this.queryManager.getDocumentInfo(this.query).hasNonreactiveDirective ?
|
|
202
|
+
!equalByQuery(this.query, this.last.result, newResult, this.variables)
|
|
142
203
|
: !equal(this.last.result, newResult);
|
|
143
204
|
return (resultIsDifferent || (variables && !equal(this.last.variables, variables)));
|
|
144
205
|
};
|
|
@@ -163,11 +224,22 @@ var ObservableQuery = (function (_super) {
|
|
|
163
224
|
ObservableQuery.prototype.resetQueryStoreErrors = function () {
|
|
164
225
|
this.queryManager.resetErrors(this.queryId);
|
|
165
226
|
};
|
|
227
|
+
/**
|
|
228
|
+
* Update the variables of this observable query, and fetch the new results.
|
|
229
|
+
* This method should be preferred over `setVariables` in most use cases.
|
|
230
|
+
*
|
|
231
|
+
* @param variables - The new set of variables. If there are missing variables,
|
|
232
|
+
* the previous values of those variables will be used.
|
|
233
|
+
*/
|
|
166
234
|
ObservableQuery.prototype.refetch = function (variables) {
|
|
167
235
|
var _a;
|
|
168
236
|
var reobserveOptions = {
|
|
237
|
+
// Always disable polling for refetches.
|
|
169
238
|
pollInterval: 0,
|
|
170
239
|
};
|
|
240
|
+
// Unless the provided fetchPolicy always consults the network
|
|
241
|
+
// (no-cache, network-only, or cache-and-network), override it with
|
|
242
|
+
// network-only to force the refetch for this fetchQuery call.
|
|
171
243
|
var fetchPolicy = this.options.fetchPolicy;
|
|
172
244
|
if (fetchPolicy === "cache-and-network") {
|
|
173
245
|
reobserveOptions.fetchPolicy = fetchPolicy;
|
|
@@ -190,6 +262,7 @@ var ObservableQuery = (function (_super) {
|
|
|
190
262
|
}
|
|
191
263
|
}
|
|
192
264
|
if (variables && !equal(this.options.variables, variables)) {
|
|
265
|
+
// Update the existing options with new variables
|
|
193
266
|
reobserveOptions.variables = this.options.variables = __assign(__assign({}, this.options.variables), variables);
|
|
194
267
|
}
|
|
195
268
|
this.queryInfo.resetLastWrite();
|
|
@@ -197,14 +270,26 @@ var ObservableQuery = (function (_super) {
|
|
|
197
270
|
};
|
|
198
271
|
ObservableQuery.prototype.fetchMore = function (fetchMoreOptions) {
|
|
199
272
|
var _this = this;
|
|
200
|
-
var combinedOptions = __assign(__assign({}, (fetchMoreOptions.query
|
|
201
|
-
|
|
202
|
-
|
|
273
|
+
var combinedOptions = __assign(__assign({}, (fetchMoreOptions.query ? fetchMoreOptions : (__assign(__assign(__assign(__assign({}, this.options), { query: this.options.query }), fetchMoreOptions), { variables: __assign(__assign({}, this.options.variables), fetchMoreOptions.variables) })))), {
|
|
274
|
+
// The fetchMore request goes immediately to the network and does
|
|
275
|
+
// not automatically write its result to the cache (hence no-cache
|
|
276
|
+
// instead of network-only), because we allow the caller of
|
|
277
|
+
// fetchMore to provide an updateQuery callback that determines how
|
|
278
|
+
// the data gets written to the cache.
|
|
279
|
+
fetchPolicy: "no-cache" });
|
|
203
280
|
combinedOptions.query = this.transformDocument(combinedOptions.query);
|
|
204
281
|
var qid = this.queryManager.generateQueryId();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
282
|
+
// If a temporary query is passed to `fetchMore`, we don't want to store
|
|
283
|
+
// it as the last query result since it may be an optimized query for
|
|
284
|
+
// pagination. We will however run the transforms on the original document
|
|
285
|
+
// as well as the document passed in `fetchMoreOptions` to ensure the cache
|
|
286
|
+
// uses the most up-to-date document which may rely on runtime conditionals.
|
|
287
|
+
this.lastQuery =
|
|
288
|
+
fetchMoreOptions.query ?
|
|
289
|
+
this.transformDocument(this.options.query)
|
|
290
|
+
: combinedOptions.query;
|
|
291
|
+
// Simulate a loading result for the original query with
|
|
292
|
+
// result.networkStatus === NetworkStatus.fetchMore.
|
|
208
293
|
var queryInfo = this.queryInfo;
|
|
209
294
|
var originalNetworkStatus = queryInfo.networkStatus;
|
|
210
295
|
queryInfo.networkStatus = NetworkStatus.fetchMore;
|
|
@@ -219,6 +304,11 @@ var ObservableQuery = (function (_super) {
|
|
|
219
304
|
if (queryInfo.networkStatus === NetworkStatus.fetchMore) {
|
|
220
305
|
queryInfo.networkStatus = originalNetworkStatus;
|
|
221
306
|
}
|
|
307
|
+
// Performing this cache update inside a cache.batch transaction ensures
|
|
308
|
+
// any affected cache.watch watchers are notified at most once about any
|
|
309
|
+
// updates. Most watchers will be using the QueryInfo class, which
|
|
310
|
+
// responds to notifications by calling reobserveCacheFirst to deliver
|
|
311
|
+
// fetchMore cache results back to this ObservableQuery.
|
|
222
312
|
_this.queryManager.cache.batch({
|
|
223
313
|
update: function (cache) {
|
|
224
314
|
var updateQuery = fetchMoreOptions.updateQuery;
|
|
@@ -236,6 +326,11 @@ var ObservableQuery = (function (_super) {
|
|
|
236
326
|
});
|
|
237
327
|
}
|
|
238
328
|
else {
|
|
329
|
+
// If we're using a field policy instead of updateQuery, the only
|
|
330
|
+
// thing we need to do is write the new data to the cache using
|
|
331
|
+
// combinedOptions.variables (instead of this.variables, which is
|
|
332
|
+
// what this.updateQuery uses, because it works by abusing the
|
|
333
|
+
// original field value, keyed by the original variables).
|
|
239
334
|
cache.writeQuery({
|
|
240
335
|
query: combinedOptions.query,
|
|
241
336
|
variables: combinedOptions.variables,
|
|
@@ -244,17 +339,27 @@ var ObservableQuery = (function (_super) {
|
|
|
244
339
|
}
|
|
245
340
|
},
|
|
246
341
|
onWatchUpdated: function (watch) {
|
|
342
|
+
// Record the DocumentNode associated with any watched query whose
|
|
343
|
+
// data were updated by the cache writes above.
|
|
247
344
|
updatedQuerySet.add(watch.query);
|
|
248
345
|
},
|
|
249
346
|
});
|
|
250
347
|
return fetchMoreResult;
|
|
251
348
|
})
|
|
252
349
|
.finally(function () {
|
|
350
|
+
// In case the cache writes above did not generate a broadcast
|
|
351
|
+
// notification (which would have been intercepted by onWatchUpdated),
|
|
352
|
+
// likely because the written data were the same as what was already in
|
|
353
|
+
// the cache, we still want fetchMore to deliver its final loading:false
|
|
354
|
+
// result with the unchanged data.
|
|
253
355
|
if (!updatedQuerySet.has(_this.query)) {
|
|
254
356
|
reobserveCacheFirst(_this);
|
|
255
357
|
}
|
|
256
358
|
});
|
|
257
359
|
};
|
|
360
|
+
// XXX the subscription variables are separate from the query variables.
|
|
361
|
+
// if you want to update subscription variables, right now you have to do that separately,
|
|
362
|
+
// and you can only do it by stopping the subscription and then subscribing again with new variables.
|
|
258
363
|
ObservableQuery.prototype.subscribeToMore = function (options) {
|
|
259
364
|
var _this = this;
|
|
260
365
|
var subscription = this.queryManager
|
|
@@ -298,15 +403,38 @@ var ObservableQuery = (function (_super) {
|
|
|
298
403
|
var mergedOptions = compact(this.options, newOptions || {});
|
|
299
404
|
assign(this.options, mergedOptions);
|
|
300
405
|
};
|
|
406
|
+
/**
|
|
407
|
+
* Update the variables of this observable query, and fetch the new results
|
|
408
|
+
* if they've changed. Most users should prefer `refetch` instead of
|
|
409
|
+
* `setVariables` in order to to be properly notified of results even when
|
|
410
|
+
* they come from the cache.
|
|
411
|
+
*
|
|
412
|
+
* Note: the `next` callback will *not* fire if the variables have not changed
|
|
413
|
+
* or if the result is coming from cache.
|
|
414
|
+
*
|
|
415
|
+
* Note: the promise will return the old results immediately if the variables
|
|
416
|
+
* have not changed.
|
|
417
|
+
*
|
|
418
|
+
* Note: the promise will return null immediately if the query is not active
|
|
419
|
+
* (there are no subscribers).
|
|
420
|
+
*
|
|
421
|
+
* @param variables - The new set of variables. If there are missing variables,
|
|
422
|
+
* the previous values of those variables will be used.
|
|
423
|
+
*/
|
|
301
424
|
ObservableQuery.prototype.setVariables = function (variables) {
|
|
302
425
|
if (equal(this.variables, variables)) {
|
|
426
|
+
// If we have no observers, then we don't actually want to make a network
|
|
427
|
+
// request. As soon as someone observes the query, the request will kick
|
|
428
|
+
// off. For now, we just store any changes. (See #1077)
|
|
303
429
|
return this.observers.size ? this.result() : Promise.resolve();
|
|
304
430
|
}
|
|
305
431
|
this.options.variables = variables;
|
|
432
|
+
// See comment above
|
|
306
433
|
if (!this.observers.size) {
|
|
307
434
|
return Promise.resolve();
|
|
308
435
|
}
|
|
309
436
|
return this.reobserve({
|
|
437
|
+
// Reset options.fetchPolicy to its original value.
|
|
310
438
|
fetchPolicy: this.options.initialFetchPolicy,
|
|
311
439
|
variables: variables,
|
|
312
440
|
}, NetworkStatus.setVariables);
|
|
@@ -339,12 +467,29 @@ var ObservableQuery = (function (_super) {
|
|
|
339
467
|
this.options.pollInterval = 0;
|
|
340
468
|
this.updatePolling();
|
|
341
469
|
};
|
|
342
|
-
|
|
470
|
+
// Update options.fetchPolicy according to options.nextFetchPolicy.
|
|
471
|
+
ObservableQuery.prototype.applyNextFetchPolicy = function (reason,
|
|
472
|
+
// It's possible to use this method to apply options.nextFetchPolicy to
|
|
473
|
+
// options.fetchPolicy even if options !== this.options, though that happens
|
|
474
|
+
// most often when the options are temporary, used for only one request and
|
|
475
|
+
// then thrown away, so nextFetchPolicy may not end up mattering.
|
|
476
|
+
options) {
|
|
343
477
|
if (options.nextFetchPolicy) {
|
|
344
478
|
var _a = options.fetchPolicy, fetchPolicy = _a === void 0 ? "cache-first" : _a, _b = options.initialFetchPolicy, initialFetchPolicy = _b === void 0 ? fetchPolicy : _b;
|
|
345
479
|
if (fetchPolicy === "standby") {
|
|
480
|
+
// Do nothing, leaving options.fetchPolicy unchanged.
|
|
346
481
|
}
|
|
347
482
|
else if (typeof options.nextFetchPolicy === "function") {
|
|
483
|
+
// When someone chooses "cache-and-network" or "network-only" as their
|
|
484
|
+
// initial FetchPolicy, they often do not want future cache updates to
|
|
485
|
+
// trigger unconditional network requests, which is what repeatedly
|
|
486
|
+
// applying the "cache-and-network" or "network-only" policies would
|
|
487
|
+
// seem to imply. Instead, when the cache reports an update after the
|
|
488
|
+
// initial network request, it may be desirable for subsequent network
|
|
489
|
+
// requests to be triggered only if the cache result is incomplete. To
|
|
490
|
+
// that end, the options.nextFetchPolicy option provides an easy way to
|
|
491
|
+
// update options.fetchPolicy after the initial network request, without
|
|
492
|
+
// having to call observableQuery.setOptions.
|
|
348
493
|
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
|
|
349
494
|
reason: reason,
|
|
350
495
|
options: options,
|
|
@@ -362,11 +507,15 @@ var ObservableQuery = (function (_super) {
|
|
|
362
507
|
return options.fetchPolicy;
|
|
363
508
|
};
|
|
364
509
|
ObservableQuery.prototype.fetch = function (options, newNetworkStatus, query) {
|
|
510
|
+
// TODO Make sure we update the networkStatus (and infer fetchVariables)
|
|
511
|
+
// before actually committing to the fetch.
|
|
365
512
|
this.queryManager.setObservableQuery(this);
|
|
366
513
|
return this.queryManager["fetchConcastWithInfo"](this.queryId, options, newNetworkStatus, query);
|
|
367
514
|
};
|
|
515
|
+
// Turns polling on or off based on this.options.pollInterval.
|
|
368
516
|
ObservableQuery.prototype.updatePolling = function () {
|
|
369
517
|
var _this = this;
|
|
518
|
+
// Avoid polling in SSR mode
|
|
370
519
|
if (this.queryManager.ssrMode) {
|
|
371
520
|
return;
|
|
372
521
|
}
|
|
@@ -385,11 +534,17 @@ var ObservableQuery = (function (_super) {
|
|
|
385
534
|
var info = pollingInfo || (this.pollingInfo = {});
|
|
386
535
|
info.interval = pollInterval;
|
|
387
536
|
var maybeFetch = function () {
|
|
537
|
+
var _a, _b;
|
|
388
538
|
if (_this.pollingInfo) {
|
|
389
|
-
if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus)
|
|
539
|
+
if (!isNetworkRequestInFlight(_this.queryInfo.networkStatus) &&
|
|
540
|
+
!((_b = (_a = _this.options).skipPollAttempt) === null || _b === void 0 ? void 0 : _b.call(_a))) {
|
|
390
541
|
_this.reobserve({
|
|
391
|
-
fetchPolicy
|
|
392
|
-
|
|
542
|
+
// Most fetchPolicy options don't make sense to use in a polling context, as
|
|
543
|
+
// users wouldn't want to be polling the cache directly. However, network-only and
|
|
544
|
+
// no-cache are both useful for when the user wants to control whether or not the
|
|
545
|
+
// polled results are written to the cache.
|
|
546
|
+
fetchPolicy: _this.options.initialFetchPolicy === "no-cache" ?
|
|
547
|
+
"no-cache"
|
|
393
548
|
: "network-only",
|
|
394
549
|
}, NetworkStatus.poll).then(poll, poll);
|
|
395
550
|
}
|
|
@@ -410,34 +565,55 @@ var ObservableQuery = (function (_super) {
|
|
|
410
565
|
ObservableQuery.prototype.updateLastResult = function (newResult, variables) {
|
|
411
566
|
if (variables === void 0) { variables = this.variables; }
|
|
412
567
|
var error = this.getLastError();
|
|
568
|
+
// Preserve this.last.error unless the variables have changed.
|
|
413
569
|
if (error && this.last && !equal(variables, this.last.variables)) {
|
|
414
570
|
error = void 0;
|
|
415
571
|
}
|
|
416
|
-
return (this.last = __assign({ result: this.queryManager.assumeImmutableResults
|
|
417
|
-
|
|
572
|
+
return (this.last = __assign({ result: this.queryManager.assumeImmutableResults ?
|
|
573
|
+
newResult
|
|
418
574
|
: cloneDeep(newResult), variables: variables }, (error ? { error: error } : null)));
|
|
419
575
|
};
|
|
420
576
|
ObservableQuery.prototype.reobserveAsConcast = function (newOptions, newNetworkStatus) {
|
|
421
577
|
var _this = this;
|
|
422
578
|
this.isTornDown = false;
|
|
423
|
-
var useDisposableConcast =
|
|
579
|
+
var useDisposableConcast =
|
|
580
|
+
// Refetching uses a disposable Concast to allow refetches using different
|
|
581
|
+
// options/variables, without permanently altering the options of the
|
|
582
|
+
// original ObservableQuery.
|
|
583
|
+
newNetworkStatus === NetworkStatus.refetch ||
|
|
584
|
+
// The fetchMore method does not actually call the reobserve method, but,
|
|
585
|
+
// if it did, it would definitely use a disposable Concast.
|
|
424
586
|
newNetworkStatus === NetworkStatus.fetchMore ||
|
|
587
|
+
// Polling uses a disposable Concast so the polling options (which force
|
|
588
|
+
// fetchPolicy to be "network-only" or "no-cache") won't override the original options.
|
|
425
589
|
newNetworkStatus === NetworkStatus.poll;
|
|
590
|
+
// Save the old variables, since Object.assign may modify them below.
|
|
426
591
|
var oldVariables = this.options.variables;
|
|
427
592
|
var oldFetchPolicy = this.options.fetchPolicy;
|
|
428
593
|
var mergedOptions = compact(this.options, newOptions || {});
|
|
429
|
-
var options = useDisposableConcast
|
|
430
|
-
|
|
431
|
-
|
|
594
|
+
var options = useDisposableConcast ?
|
|
595
|
+
// Disposable Concast fetches receive a shallow copy of this.options
|
|
596
|
+
// (merged with newOptions), leaving this.options unmodified.
|
|
597
|
+
mergedOptions
|
|
432
598
|
: assign(this.options, mergedOptions);
|
|
599
|
+
// Don't update options.query with the transformed query to avoid
|
|
600
|
+
// overwriting this.options.query when we aren't using a disposable concast.
|
|
601
|
+
// We want to ensure we can re-run the custom document transforms the next
|
|
602
|
+
// time a request is made against the original query.
|
|
433
603
|
var query = this.transformDocument(options.query);
|
|
434
604
|
this.lastQuery = query;
|
|
435
605
|
if (!useDisposableConcast) {
|
|
606
|
+
// We can skip calling updatePolling if we're not changing this.options.
|
|
436
607
|
this.updatePolling();
|
|
608
|
+
// Reset options.fetchPolicy to its original value when variables change,
|
|
609
|
+
// unless a new fetchPolicy was provided by newOptions.
|
|
437
610
|
if (newOptions &&
|
|
438
611
|
newOptions.variables &&
|
|
439
612
|
!equal(newOptions.variables, oldVariables) &&
|
|
613
|
+
// Don't mess with the fetchPolicy if it's currently "standby".
|
|
440
614
|
options.fetchPolicy !== "standby" &&
|
|
615
|
+
// If we're changing the fetchPolicy anyway, don't try to change it here
|
|
616
|
+
// using applyNextFetchPolicy. The explicit options.fetchPolicy wins.
|
|
441
617
|
options.fetchPolicy === oldFetchPolicy) {
|
|
442
618
|
this.applyNextFetchPolicy("variables-changed", options);
|
|
443
619
|
if (newNetworkStatus === void 0) {
|
|
@@ -464,6 +640,8 @@ var ObservableQuery = (function (_super) {
|
|
|
464
640
|
},
|
|
465
641
|
};
|
|
466
642
|
if (!useDisposableConcast && (fromLink || !this.concast)) {
|
|
643
|
+
// We use the {add,remove}Observer methods directly to avoid wrapping
|
|
644
|
+
// observer with an unnecessary SubscriptionObserver object.
|
|
467
645
|
if (this.concast && this.observer) {
|
|
468
646
|
this.concast.removeObserver(this.observer);
|
|
469
647
|
}
|
|
@@ -474,25 +652,43 @@ var ObservableQuery = (function (_super) {
|
|
|
474
652
|
return concast;
|
|
475
653
|
};
|
|
476
654
|
ObservableQuery.prototype.reobserve = function (newOptions, newNetworkStatus) {
|
|
477
|
-
return this.reobserveAsConcast(newOptions, newNetworkStatus)
|
|
655
|
+
return this.reobserveAsConcast(newOptions, newNetworkStatus)
|
|
656
|
+
.promise;
|
|
478
657
|
};
|
|
479
658
|
ObservableQuery.prototype.resubscribeAfterError = function () {
|
|
480
659
|
var args = [];
|
|
481
660
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
482
661
|
args[_i] = arguments[_i];
|
|
483
662
|
}
|
|
663
|
+
// If `lastError` is set in the current when the subscription is re-created,
|
|
664
|
+
// the subscription will immediately receive the error, which will
|
|
665
|
+
// cause it to terminate again. To avoid this, we first clear
|
|
666
|
+
// the last error/result from the `observableQuery` before re-starting
|
|
667
|
+
// the subscription, and restore the last value afterwards so that the
|
|
668
|
+
// subscription has a chance to stay open.
|
|
484
669
|
var last = this.last;
|
|
485
670
|
this.resetLastResults();
|
|
486
671
|
var subscription = this.subscribe.apply(this, args);
|
|
487
672
|
this.last = last;
|
|
488
673
|
return subscription;
|
|
489
674
|
};
|
|
675
|
+
// (Re)deliver the current result to this.observers without applying fetch
|
|
676
|
+
// policies or making network requests.
|
|
490
677
|
ObservableQuery.prototype.observe = function () {
|
|
491
|
-
this.reportResult(
|
|
678
|
+
this.reportResult(
|
|
679
|
+
// Passing false is important so that this.getCurrentResult doesn't
|
|
680
|
+
// save the fetchMore result as this.lastResult, causing it to be
|
|
681
|
+
// ignored due to the this.isDifferentFromLastResult check in
|
|
682
|
+
// this.reportResult.
|
|
683
|
+
this.getCurrentResult(false), this.variables);
|
|
492
684
|
};
|
|
493
685
|
ObservableQuery.prototype.reportResult = function (result, variables) {
|
|
494
686
|
var lastError = this.getLastError();
|
|
495
687
|
var isDifferent = this.isDifferentFromLastResult(result, variables);
|
|
688
|
+
// Update the last result even when isDifferentFromLastResult returns false,
|
|
689
|
+
// because the query may be using the @nonreactive directive, and we want to
|
|
690
|
+
// save the the latest version of any nonreactive subtrees (in case
|
|
691
|
+
// getCurrentResult is called), even though we skip broadcasting changes.
|
|
496
692
|
if (lastError || !result.partial || this.options.returnPartialData) {
|
|
497
693
|
this.updateLastResult(result, variables);
|
|
498
694
|
}
|
|
@@ -501,6 +697,8 @@ var ObservableQuery = (function (_super) {
|
|
|
501
697
|
}
|
|
502
698
|
};
|
|
503
699
|
ObservableQuery.prototype.reportError = function (error, variables) {
|
|
700
|
+
// Since we don't get the current result on errors, only the error, we
|
|
701
|
+
// must mirror the updates that occur in QueryStore.markQueryError here
|
|
504
702
|
var errorResult = __assign(__assign({}, this.getLastResult()), { error: error, errors: error.graphQLErrors, networkStatus: NetworkStatus.error, loading: false });
|
|
505
703
|
this.updateLastResult(errorResult, variables);
|
|
506
704
|
iterateObserversSafely(this.observers, "error", (this.last.error = error));
|
|
@@ -517,6 +715,7 @@ var ObservableQuery = (function (_super) {
|
|
|
517
715
|
delete this.observer;
|
|
518
716
|
}
|
|
519
717
|
this.stopPolling();
|
|
718
|
+
// stop all active GraphQL subscriptions
|
|
520
719
|
this.subscriptions.forEach(function (sub) { return sub.unsubscribe(); });
|
|
521
720
|
this.subscriptions.clear();
|
|
522
721
|
this.queryManager.stopQuery(this.queryId);
|
|
@@ -529,17 +728,33 @@ var ObservableQuery = (function (_super) {
|
|
|
529
728
|
return ObservableQuery;
|
|
530
729
|
}(Observable));
|
|
531
730
|
export { ObservableQuery };
|
|
731
|
+
// Necessary because the ObservableQuery constructor has a different
|
|
732
|
+
// signature than the Observable constructor.
|
|
532
733
|
fixObservableSubclass(ObservableQuery);
|
|
734
|
+
// Reobserve with fetchPolicy effectively set to "cache-first", triggering
|
|
735
|
+
// delivery of any new data from the cache, possibly falling back to the network
|
|
736
|
+
// if any cache data are missing. This allows _complete_ cache results to be
|
|
737
|
+
// delivered without also kicking off unnecessary network requests when
|
|
738
|
+
// this.options.fetchPolicy is "cache-and-network" or "network-only". When
|
|
739
|
+
// this.options.fetchPolicy is any other policy ("cache-first", "cache-only",
|
|
740
|
+
// "standby", or "no-cache"), we call this.reobserve() as usual.
|
|
533
741
|
export function reobserveCacheFirst(obsQuery) {
|
|
534
742
|
var _a = obsQuery.options, fetchPolicy = _a.fetchPolicy, nextFetchPolicy = _a.nextFetchPolicy;
|
|
535
743
|
if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
|
|
536
744
|
return obsQuery.reobserve({
|
|
537
745
|
fetchPolicy: "cache-first",
|
|
538
|
-
nextFetchPolicy
|
|
746
|
+
// Use a temporary nextFetchPolicy function that replaces itself with the
|
|
747
|
+
// previous nextFetchPolicy value and returns the original fetchPolicy.
|
|
748
|
+
nextFetchPolicy: function (currentFetchPolicy, context) {
|
|
749
|
+
// Replace this nextFetchPolicy function in the options object with the
|
|
750
|
+
// original this.options.nextFetchPolicy value.
|
|
539
751
|
this.nextFetchPolicy = nextFetchPolicy;
|
|
540
|
-
|
|
541
|
-
|
|
752
|
+
// If the original nextFetchPolicy value was a function, give it a
|
|
753
|
+
// chance to decide what happens here.
|
|
754
|
+
if (typeof this.nextFetchPolicy === "function") {
|
|
755
|
+
return this.nextFetchPolicy(currentFetchPolicy, context);
|
|
542
756
|
}
|
|
757
|
+
// Otherwise go back to the original this.options.fetchPolicy.
|
|
543
758
|
return fetchPolicy;
|
|
544
759
|
},
|
|
545
760
|
});
|
|
@@ -554,7 +769,7 @@ export function logMissingFieldErrors(missing) {
|
|
|
554
769
|
globalThis.__DEV__ !== false && invariant.debug(24, missing);
|
|
555
770
|
}
|
|
556
771
|
}
|
|
557
|
-
function skipCacheDataFor(fetchPolicy) {
|
|
772
|
+
function skipCacheDataFor(fetchPolicy /* `undefined` would mean `"cache-first"` */) {
|
|
558
773
|
return (fetchPolicy === "network-only" ||
|
|
559
774
|
fetchPolicy === "no-cache" ||
|
|
560
775
|
fetchPolicy === "standby");
|