@apollo/client 3.9.0-alpha.4 → 3.9.0-alpha.5
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/forty-cups-shop.md +5 -0
- package/.changeset/friendly-clouds-laugh.md +7 -0
- package/.changeset/hot-ducks-burn.md +5 -0
- package/.changeset/polite-avocados-warn.md +5 -0
- package/.changeset/pre.json +29 -0
- package/.changeset/quick-hats-marry.md +5 -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/thick-mice-collect.md +5 -0
- package/.changeset/thirty-ties-arrive.md +26 -0
- package/.changeset/violet-lions-draw.md +5 -0
- package/.changeset/wild-dolphins-jog.md +5 -0
- package/.changeset/yellow-flies-repeat.md +5 -0
- package/CHANGELOG.md +3535 -0
- package/apollo-client.cjs +475 -398
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +135 -153
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +135 -153
- package/cache/core/cache.d.ts +10 -0
- package/cache/core/cache.js +17 -5
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +92 -0
- package/cache/core/types/common.d.ts +1 -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 +23 -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.js +164 -8
- 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 +58 -9
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +28 -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 +264 -3
- package/core/ApolloClient.js +235 -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 +25 -0
- package/core/ObservableQuery.js +239 -30
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +3 -3
- package/core/QueryInfo.js +118 -13
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +8 -1
- package/core/QueryManager.js +247 -46
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +127 -114
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +127 -114
- 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 +225 -1
- 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.js +12 -5
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +5 -5
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +5 -5
- 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.js +34 -4
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +4 -4
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
- package/link/remove-typename/remove-typename.cjs +12 -9
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +12 -9
- package/link/remove-typename/removeTypenameFromVariables.js +12 -9
- 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 +50 -38
- package/react/cache/QueryReference.d.ts +18 -10
- package/react/cache/QueryReference.js +52 -8
- 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 +138 -66
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +138 -66
- package/react/hooks/index.d.ts +2 -0
- package/react/hooks/index.js +1 -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.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/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 +4 -10
- 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/parser/index.d.ts +3 -0
- package/react/parser/index.js +13 -6
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +11 -5
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +11 -5
- 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 +123 -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/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/matchers/ProfiledComponent.js +29 -26
- package/testing/matchers/ProfiledComponent.js.map +1 -1
- package/testing/matchers/index.js +2 -0
- package/testing/matchers/index.js.map +1 -1
- 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/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/canUse.js +16 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/canonicalStringify.d.ts +17 -0
- package/utilities/common/canonicalStringify.js +41 -0
- 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 +6 -5
- package/utilities/graphql/DocumentTransform.js +48 -27
- 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 +4 -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 +2 -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 +61 -53
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +61 -53
- 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/QueryManager.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import { invariant, newInvariantError } from "../utilities/globals/index.js";
|
|
3
3
|
import { equal } from "@wry/equality";
|
|
4
|
+
import { WeakCache } from "@wry/caches";
|
|
4
5
|
import { execute } from "../link/core/index.js";
|
|
5
|
-
import {
|
|
6
|
+
import { hasDirectives, isExecutionPatchIncrementalResult, isExecutionPatchResult, removeDirectivesFromDocument, } from "../utilities/index.js";
|
|
6
7
|
import { canonicalStringify } from "../cache/index.js";
|
|
7
|
-
import { getDefaultValues, getOperationDefinition, getOperationName, hasClientExports, graphQLResultHasError, getGraphQLErrorsFromResult,
|
|
8
|
+
import { getDefaultValues, getOperationDefinition, getOperationName, hasClientExports, graphQLResultHasError, getGraphQLErrorsFromResult, Observable, asyncMap, isNonEmptyArray, Concast, makeUniqueId, isDocumentNode, isNonNullObject, DocumentTransform, } from "../utilities/index.js";
|
|
8
9
|
import { mergeIncrementalData } from "../utilities/common/incrementalResult.js";
|
|
9
10
|
import { ApolloError, isApolloError, graphQLResultHasProtocolErrors, } from "../errors/index.js";
|
|
10
11
|
import { ObservableQuery, logMissingFieldErrors } from "./ObservableQuery.js";
|
|
@@ -14,19 +15,30 @@ import { QueryInfo, shouldWriteResult, } from "./QueryInfo.js";
|
|
|
14
15
|
import { PROTOCOL_ERRORS_SYMBOL } from "../errors/index.js";
|
|
15
16
|
import { print } from "../utilities/index.js";
|
|
16
17
|
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
17
|
-
|
|
18
|
+
import { Trie } from "@wry/trie";
|
|
19
|
+
var QueryManager = /** @class */ (function () {
|
|
18
20
|
function QueryManager(_a) {
|
|
19
|
-
var _this = this;
|
|
20
21
|
var cache = _a.cache, link = _a.link, defaultOptions = _a.defaultOptions, documentTransform = _a.documentTransform, _b = _a.queryDeduplication, queryDeduplication = _b === void 0 ? false : _b, onBroadcast = _a.onBroadcast, _c = _a.ssrMode, ssrMode = _c === void 0 ? false : _c, _d = _a.clientAwareness, clientAwareness = _d === void 0 ? {} : _d, localState = _a.localState, _e = _a.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? !!cache.assumeImmutableResults : _e, defaultContext = _a.defaultContext;
|
|
22
|
+
var _this = this;
|
|
21
23
|
this.clientAwareness = {};
|
|
24
|
+
// All the queries that the QueryManager is currently managing (not
|
|
25
|
+
// including mutations and subscriptions).
|
|
22
26
|
this.queries = new Map();
|
|
27
|
+
// Maps from queryId strings to Promise rejection functions for
|
|
28
|
+
// currently active queries and fetches.
|
|
29
|
+
// Use protected instead of private field so
|
|
30
|
+
// @apollo/experimental-nextjs-app-support can access type info.
|
|
23
31
|
this.fetchCancelFns = new Map();
|
|
24
|
-
this.transformCache = new (
|
|
32
|
+
this.transformCache = new WeakCache( /** TODO: decide on a maximum size (will do all max sizes in a combined separate PR) */);
|
|
25
33
|
this.queryIdCounter = 1;
|
|
26
34
|
this.requestIdCounter = 1;
|
|
27
35
|
this.mutationIdCounter = 1;
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
// Use protected instead of private field so
|
|
37
|
+
// @apollo/experimental-nextjs-app-support can access type info.
|
|
38
|
+
this.inFlightLinkObservables = new Trie(false);
|
|
39
|
+
var defaultDocumentTransform = new DocumentTransform(function (document) { return _this.cache.transformDocument(document); },
|
|
40
|
+
// Allow the apollo cache to manage its own transform caches
|
|
41
|
+
{ cache: false });
|
|
30
42
|
this.cache = cache;
|
|
31
43
|
this.link = link;
|
|
32
44
|
this.defaultOptions = defaultOptions || Object.create(null);
|
|
@@ -35,16 +47,31 @@ var QueryManager = (function () {
|
|
|
35
47
|
this.localState = localState || new LocalState({ cache: cache });
|
|
36
48
|
this.ssrMode = ssrMode;
|
|
37
49
|
this.assumeImmutableResults = assumeImmutableResults;
|
|
38
|
-
this.documentTransform =
|
|
39
|
-
?
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
this.documentTransform =
|
|
51
|
+
documentTransform ?
|
|
52
|
+
defaultDocumentTransform
|
|
53
|
+
.concat(documentTransform)
|
|
54
|
+
// The custom document transform may add new fragment spreads or new
|
|
55
|
+
// field selections, so we want to give the cache a chance to run
|
|
56
|
+
// again. For example, the InMemoryCache adds __typename to field
|
|
57
|
+
// selections and fragments from the fragment registry.
|
|
58
|
+
.concat(defaultDocumentTransform)
|
|
59
|
+
: defaultDocumentTransform;
|
|
43
60
|
this.defaultContext = defaultContext || Object.create(null);
|
|
44
61
|
if ((this.onBroadcast = onBroadcast)) {
|
|
45
62
|
this.mutationStore = Object.create(null);
|
|
46
63
|
}
|
|
64
|
+
// TODO: remove before we release 3.9
|
|
65
|
+
Object.defineProperty(this.inFlightLinkObservables, "get", {
|
|
66
|
+
value: function () {
|
|
67
|
+
throw new Error("This version of Apollo Client requires at least @apollo/experimental-nextjs-app-support version 0.5.2.");
|
|
68
|
+
},
|
|
69
|
+
});
|
|
47
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Call this method to terminate any active query processes, making it safe
|
|
73
|
+
* to dispose of this QueryManager instance.
|
|
74
|
+
*/
|
|
48
75
|
QueryManager.prototype.stop = function () {
|
|
49
76
|
var _this = this;
|
|
50
77
|
this.queries.forEach(function (_info, queryId) {
|
|
@@ -70,8 +97,8 @@ var QueryManager = (function () {
|
|
|
70
97
|
mutation = this.cache.transformForLink(this.transform(mutation));
|
|
71
98
|
hasClientExports = this.getDocumentInfo(mutation).hasClientExports;
|
|
72
99
|
variables = this.getVariables(mutation, variables);
|
|
73
|
-
if (!hasClientExports) return [3
|
|
74
|
-
return [4
|
|
100
|
+
if (!hasClientExports) return [3 /*break*/, 2];
|
|
101
|
+
return [4 /*yield*/, this.localState.addExportedVariables(mutation, variables, context)];
|
|
75
102
|
case 1:
|
|
76
103
|
variables = (_h.sent());
|
|
77
104
|
_h.label = 2;
|
|
@@ -98,7 +125,7 @@ var QueryManager = (function () {
|
|
|
98
125
|
}
|
|
99
126
|
this.broadcastQueries();
|
|
100
127
|
self = this;
|
|
101
|
-
return [2
|
|
128
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
102
129
|
return asyncMap(self.getObservableFromLink(mutation, __assign(__assign({}, context), { optimisticResponse: optimisticResponse }), variables, false), function (result) {
|
|
103
130
|
if (graphQLResultHasError(result) && errorPolicy === "none") {
|
|
104
131
|
throw new ApolloError({
|
|
@@ -135,6 +162,11 @@ var QueryManager = (function () {
|
|
|
135
162
|
}).subscribe({
|
|
136
163
|
next: function (storeResult) {
|
|
137
164
|
self.broadcastQueries();
|
|
165
|
+
// Since mutations might receive multiple payloads from the
|
|
166
|
+
// ApolloLink chain (e.g. when used with @defer),
|
|
167
|
+
// we resolve with a SingleExecutionResult or after the final
|
|
168
|
+
// ExecutionPatchResult has arrived and we have assembled the
|
|
169
|
+
// multipart response into a single result.
|
|
138
170
|
if (!("hasNext" in storeResult) || storeResult.hasNext === false) {
|
|
139
171
|
resolve(storeResult);
|
|
140
172
|
}
|
|
@@ -148,11 +180,9 @@ var QueryManager = (function () {
|
|
|
148
180
|
self.cache.removeOptimistic(mutationId);
|
|
149
181
|
}
|
|
150
182
|
self.broadcastQueries();
|
|
151
|
-
reject(err instanceof ApolloError
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
networkError: err,
|
|
155
|
-
}));
|
|
183
|
+
reject(err instanceof ApolloError ? err : (new ApolloError({
|
|
184
|
+
networkError: err,
|
|
185
|
+
})));
|
|
156
186
|
},
|
|
157
187
|
});
|
|
158
188
|
})];
|
|
@@ -179,6 +209,9 @@ var QueryManager = (function () {
|
|
|
179
209
|
isNonEmptyArray(result.incremental)) {
|
|
180
210
|
var diff = cache.diff({
|
|
181
211
|
id: "ROOT_MUTATION",
|
|
212
|
+
// The cache complains if passed a mutation where it expects a
|
|
213
|
+
// query, so we transform mutations and subscriptions to queries
|
|
214
|
+
// (only once, thanks to this.transformCache).
|
|
182
215
|
query: this.getDocumentInfo(mutation.document).asQuery,
|
|
183
216
|
variables: mutation.variables,
|
|
184
217
|
optimistic: false,
|
|
@@ -189,6 +222,8 @@ var QueryManager = (function () {
|
|
|
189
222
|
mergedData = mergeIncrementalData(diff.result, result);
|
|
190
223
|
}
|
|
191
224
|
if (typeof mergedData !== "undefined") {
|
|
225
|
+
// cast the ExecutionPatchResult to FetchResult here since
|
|
226
|
+
// ExecutionPatchResult never has `data` when returned from the server
|
|
192
227
|
result.data = mergedData;
|
|
193
228
|
cacheWrites.push({
|
|
194
229
|
result: mergedData,
|
|
@@ -208,6 +243,7 @@ var QueryManager = (function () {
|
|
|
208
243
|
}
|
|
209
244
|
var updater = updateQueries_1[queryName];
|
|
210
245
|
var _b = _this.queries.get(queryId), document = _b.document, variables = _b.variables;
|
|
246
|
+
// Read the current query result from the store.
|
|
211
247
|
var _c = cache.diff({
|
|
212
248
|
query: document,
|
|
213
249
|
variables: variables,
|
|
@@ -215,11 +251,13 @@ var QueryManager = (function () {
|
|
|
215
251
|
optimistic: false,
|
|
216
252
|
}), currentQueryResult = _c.result, complete = _c.complete;
|
|
217
253
|
if (complete && currentQueryResult) {
|
|
254
|
+
// Run our reducer using the current query result and the mutation result.
|
|
218
255
|
var nextQueryResult = updater(currentQueryResult, {
|
|
219
256
|
mutationResult: result,
|
|
220
257
|
queryName: (document && getOperationName(document)) || void 0,
|
|
221
258
|
queryVariables: variables,
|
|
222
259
|
});
|
|
260
|
+
// Write the modified result back into the store if we got a new result.
|
|
223
261
|
if (nextQueryResult) {
|
|
224
262
|
cacheWrites.push({
|
|
225
263
|
result: nextQueryResult,
|
|
@@ -243,13 +281,25 @@ var QueryManager = (function () {
|
|
|
243
281
|
if (!skipCache) {
|
|
244
282
|
cacheWrites.forEach(function (write) { return cache.write(write); });
|
|
245
283
|
}
|
|
284
|
+
// If the mutation has some writes associated with it then we need to
|
|
285
|
+
// apply those writes to the store by running this reducer again with
|
|
286
|
+
// a write action.
|
|
246
287
|
var update = mutation.update;
|
|
288
|
+
// Determine whether result is a SingleExecutionResult,
|
|
289
|
+
// or the final ExecutionPatchResult.
|
|
247
290
|
var isFinalResult = !isExecutionPatchResult(result) ||
|
|
248
291
|
(isExecutionPatchIncrementalResult(result) && !result.hasNext);
|
|
249
292
|
if (update) {
|
|
250
293
|
if (!skipCache) {
|
|
294
|
+
// Re-read the ROOT_MUTATION data we just wrote into the cache
|
|
295
|
+
// (the first cache.write call in the cacheWrites.forEach loop
|
|
296
|
+
// above), so field read functions have a chance to run for
|
|
297
|
+
// fields within mutation result objects.
|
|
251
298
|
var diff = cache.diff({
|
|
252
299
|
id: "ROOT_MUTATION",
|
|
300
|
+
// The cache complains if passed a mutation where it expects a
|
|
301
|
+
// query, so we transform mutations and subscriptions to queries
|
|
302
|
+
// (only once, thanks to this.transformCache).
|
|
253
303
|
query: _this.getDocumentInfo(mutation.document).asQuery,
|
|
254
304
|
variables: mutation.variables,
|
|
255
305
|
optimistic: false,
|
|
@@ -265,6 +315,9 @@ var QueryManager = (function () {
|
|
|
265
315
|
}
|
|
266
316
|
}
|
|
267
317
|
}
|
|
318
|
+
// If we've received the whole response,
|
|
319
|
+
// either a SingleExecutionResult or the final ExecutionPatchResult,
|
|
320
|
+
// call the update function.
|
|
268
321
|
if (isFinalResult) {
|
|
269
322
|
update(cache, result, {
|
|
270
323
|
context: mutation.context,
|
|
@@ -272,6 +325,8 @@ var QueryManager = (function () {
|
|
|
272
325
|
});
|
|
273
326
|
}
|
|
274
327
|
}
|
|
328
|
+
// TODO Do this with cache.evict({ id: 'ROOT_MUTATION' }) but make it
|
|
329
|
+
// shallow to allow rolling back optimistic evictions.
|
|
275
330
|
if (!skipCache && !mutation.keepRootFields && isFinalResult) {
|
|
276
331
|
cache.modify({
|
|
277
332
|
id: "ROOT_MUTATION",
|
|
@@ -283,11 +338,21 @@ var QueryManager = (function () {
|
|
|
283
338
|
}
|
|
284
339
|
},
|
|
285
340
|
include: mutation.refetchQueries,
|
|
341
|
+
// Write the final mutation.result to the root layer of the cache.
|
|
286
342
|
optimistic: false,
|
|
343
|
+
// Remove the corresponding optimistic layer at the same time as we
|
|
344
|
+
// write the final non-optimistic result.
|
|
287
345
|
removeOptimistic: mutation.removeOptimistic,
|
|
346
|
+
// Let the caller of client.mutate optionally determine the refetching
|
|
347
|
+
// behavior for watched queries after the mutation.update function runs.
|
|
348
|
+
// If no onQueryUpdated function was provided for this mutation, pass
|
|
349
|
+
// null instead of undefined to disable the default refetching behavior.
|
|
288
350
|
onQueryUpdated: mutation.onQueryUpdated || null,
|
|
289
351
|
}).forEach(function (result) { return results_1.push(result); });
|
|
290
352
|
if (mutation.awaitRefetchQueries || mutation.onQueryUpdated) {
|
|
353
|
+
// Returning a promise here makes the mutation await that promise, so we
|
|
354
|
+
// include results in that promise's work if awaitRefetchQueries or an
|
|
355
|
+
// onQueryUpdated function was specified.
|
|
291
356
|
return Promise.all(results_1).then(function () { return result; });
|
|
292
357
|
}
|
|
293
358
|
}
|
|
@@ -295,8 +360,8 @@ var QueryManager = (function () {
|
|
|
295
360
|
};
|
|
296
361
|
QueryManager.prototype.markMutationOptimistic = function (optimisticResponse, mutation) {
|
|
297
362
|
var _this = this;
|
|
298
|
-
var data = typeof optimisticResponse === "function"
|
|
299
|
-
|
|
363
|
+
var data = typeof optimisticResponse === "function" ?
|
|
364
|
+
optimisticResponse(mutation.variables)
|
|
300
365
|
: optimisticResponse;
|
|
301
366
|
return this.cache.recordOptimisticTransaction(function (cache) {
|
|
302
367
|
try {
|
|
@@ -337,6 +402,11 @@ var QueryManager = (function () {
|
|
|
337
402
|
var transformCache = this.transformCache;
|
|
338
403
|
if (!transformCache.has(document)) {
|
|
339
404
|
var cacheEntry = {
|
|
405
|
+
// TODO These three calls (hasClientExports, shouldForceResolvers, and
|
|
406
|
+
// usesNonreactiveDirective) are performing independent full traversals
|
|
407
|
+
// of the transformed document. We should consider merging these
|
|
408
|
+
// traversals into a single pass in the future, though the work is
|
|
409
|
+
// cached after the first time.
|
|
340
410
|
hasClientExports: hasClientExports(document),
|
|
341
411
|
hasForcedResolvers: this.localState.shouldForceResolvers(document),
|
|
342
412
|
hasNonreactiveDirective: hasDirectives(["nonreactive"], document),
|
|
@@ -347,6 +417,8 @@ var QueryManager = (function () {
|
|
|
347
417
|
{ name: "nonreactive" },
|
|
348
418
|
], document),
|
|
349
419
|
defaultVars: getDefaultValues(getOperationDefinition(document)),
|
|
420
|
+
// Transform any mutation or subscription operations to query operations
|
|
421
|
+
// so we can read/write them from/to the cache.
|
|
350
422
|
asQuery: __assign(__assign({}, document), { definitions: document.definitions.map(function (def) {
|
|
351
423
|
if (def.kind === "OperationDefinition" &&
|
|
352
424
|
def.operation !== "query") {
|
|
@@ -364,6 +436,9 @@ var QueryManager = (function () {
|
|
|
364
436
|
};
|
|
365
437
|
QueryManager.prototype.watchQuery = function (options) {
|
|
366
438
|
var query = this.transform(options.query);
|
|
439
|
+
// assign variable default values if supplied
|
|
440
|
+
// NOTE: We don't modify options.query here with the transformed query to
|
|
441
|
+
// ensure observable.options.query is set to the raw untransformed query.
|
|
367
442
|
options = __assign(__assign({}, options), { variables: this.getVariables(query, options.variables) });
|
|
368
443
|
if (typeof options.notifyOnNetworkStatusChange === "undefined") {
|
|
369
444
|
options.notifyOnNetworkStatusChange = false;
|
|
@@ -376,6 +451,8 @@ var QueryManager = (function () {
|
|
|
376
451
|
});
|
|
377
452
|
observable["lastQuery"] = query;
|
|
378
453
|
this.queries.set(observable.queryId, queryInfo);
|
|
454
|
+
// We give queryInfo the transformed query to ensure the first cache diff
|
|
455
|
+
// uses the transformed query instead of the raw query
|
|
379
456
|
queryInfo.init({
|
|
380
457
|
document: query,
|
|
381
458
|
observableQuery: observable,
|
|
@@ -414,9 +491,16 @@ var QueryManager = (function () {
|
|
|
414
491
|
if (options === void 0) { options = {
|
|
415
492
|
discardWatches: true,
|
|
416
493
|
}; }
|
|
494
|
+
// Before we have sent the reset action to the store, we can no longer
|
|
495
|
+
// rely on the results returned by in-flight requests since these may
|
|
496
|
+
// depend on values that previously existed in the data portion of the
|
|
497
|
+
// store. So, we cancel the promises and observers that we have issued
|
|
498
|
+
// so far and not yet resolved (in the case of queries).
|
|
417
499
|
this.cancelPendingFetches(newInvariantError(32));
|
|
418
500
|
this.queries.forEach(function (queryInfo) {
|
|
419
501
|
if (queryInfo.observableQuery) {
|
|
502
|
+
// Set loading to true so listeners don't trigger unless they want
|
|
503
|
+
// results with partial data.
|
|
420
504
|
queryInfo.networkStatus = NetworkStatus.loading;
|
|
421
505
|
}
|
|
422
506
|
else {
|
|
@@ -426,6 +510,7 @@ var QueryManager = (function () {
|
|
|
426
510
|
if (this.mutationStore) {
|
|
427
511
|
this.mutationStore = Object.create(null);
|
|
428
512
|
}
|
|
513
|
+
// begin removing data from the store
|
|
429
514
|
return this.cache.reset(options);
|
|
430
515
|
};
|
|
431
516
|
QueryManager.prototype.getObservableQueries = function (include) {
|
|
@@ -472,6 +557,9 @@ var QueryManager = (function () {
|
|
|
472
557
|
});
|
|
473
558
|
if (legacyQueryOptions.size) {
|
|
474
559
|
legacyQueryOptions.forEach(function (options) {
|
|
560
|
+
// We will be issuing a fresh network request for this query, so we
|
|
561
|
+
// pre-allocate a new query ID here, using a special prefix to enable
|
|
562
|
+
// cleaning up these temporary queries later, after fetching.
|
|
475
563
|
var queryId = makeUniqueId("legacyOneTimeQuery");
|
|
476
564
|
var queryInfo = _this.getQuery(queryId).init({
|
|
477
565
|
document: options.query,
|
|
@@ -523,6 +611,8 @@ var QueryManager = (function () {
|
|
|
523
611
|
var makeObservable = function (variables) {
|
|
524
612
|
return _this.getObservableFromLink(query, context, variables).map(function (result) {
|
|
525
613
|
if (fetchPolicy !== "no-cache") {
|
|
614
|
+
// the subscription interface should handle not sending us results we no longer subscribe to.
|
|
615
|
+
// XXX I don't think we ever send in an object with errors, but we might in the future...
|
|
526
616
|
if (shouldWriteResult(result, errorPolicy)) {
|
|
527
617
|
_this.cache.write({
|
|
528
618
|
query: query,
|
|
@@ -543,6 +633,9 @@ var QueryManager = (function () {
|
|
|
543
633
|
if (hasProtocolErrors) {
|
|
544
634
|
errors.protocolErrors = result.extensions[PROTOCOL_ERRORS_SYMBOL];
|
|
545
635
|
}
|
|
636
|
+
// `errorPolicy` is a mechanism for handling GraphQL errors, according
|
|
637
|
+
// to our documentation, so we throw protocol errors regardless of the
|
|
638
|
+
// set error policy.
|
|
546
639
|
if (errorPolicy === "none" || hasProtocolErrors) {
|
|
547
640
|
throw new ApolloError(errors);
|
|
548
641
|
}
|
|
@@ -574,6 +667,11 @@ var QueryManager = (function () {
|
|
|
574
667
|
this.removeQuery(queryId);
|
|
575
668
|
};
|
|
576
669
|
QueryManager.prototype.removeQuery = function (queryId) {
|
|
670
|
+
// teardown all links
|
|
671
|
+
// Both `QueryManager.fetchRequest` and `QueryManager.query` create separate promises
|
|
672
|
+
// that each add their reject functions to fetchCancelFns.
|
|
673
|
+
// A query created with `QueryManager.query()` could trigger a `QueryManager.fetchRequest`.
|
|
674
|
+
// The same queryId could have two rejection fns for two promises
|
|
577
675
|
this.fetchCancelFns.delete(queryId);
|
|
578
676
|
if (this.queries.has(queryId)) {
|
|
579
677
|
this.getQuery(queryId).stop();
|
|
@@ -588,7 +686,9 @@ var QueryManager = (function () {
|
|
|
588
686
|
QueryManager.prototype.getLocalState = function () {
|
|
589
687
|
return this.localState;
|
|
590
688
|
};
|
|
591
|
-
QueryManager.prototype.getObservableFromLink = function (query, context, variables,
|
|
689
|
+
QueryManager.prototype.getObservableFromLink = function (query, context, variables,
|
|
690
|
+
// Prefer context.queryDeduplication if specified.
|
|
691
|
+
deduplication) {
|
|
592
692
|
var _this = this;
|
|
593
693
|
var _a;
|
|
594
694
|
if (deduplication === void 0) { deduplication = (_a = context === null || context === void 0 ? void 0 : context.queryDeduplication) !== null && _a !== void 0 ? _a : this.queryDeduplication; }
|
|
@@ -605,19 +705,16 @@ var QueryManager = (function () {
|
|
|
605
705
|
context = operation.context;
|
|
606
706
|
if (deduplication) {
|
|
607
707
|
var printedServerQuery_1 = print(serverQuery);
|
|
608
|
-
var byVariables_1 = inFlightLinkObservables_1.get(printedServerQuery_1) || new Map();
|
|
609
|
-
inFlightLinkObservables_1.set(printedServerQuery_1, byVariables_1);
|
|
610
708
|
var varJson_1 = canonicalStringify(variables);
|
|
611
|
-
|
|
709
|
+
var entry = inFlightLinkObservables_1.lookup(printedServerQuery_1, varJson_1);
|
|
710
|
+
observable = entry.observable;
|
|
612
711
|
if (!observable) {
|
|
613
712
|
var concast = new Concast([
|
|
614
713
|
execute(link, operation),
|
|
615
714
|
]);
|
|
616
|
-
|
|
715
|
+
observable = entry.observable = concast;
|
|
617
716
|
concast.beforeNext(function () {
|
|
618
|
-
|
|
619
|
-
inFlightLinkObservables_1.delete(printedServerQuery_1);
|
|
620
|
-
}
|
|
717
|
+
inFlightLinkObservables_1.remove(printedServerQuery_1, varJson_1);
|
|
621
718
|
});
|
|
622
719
|
}
|
|
623
720
|
}
|
|
@@ -645,16 +742,25 @@ var QueryManager = (function () {
|
|
|
645
742
|
};
|
|
646
743
|
QueryManager.prototype.getResultsFromLink = function (queryInfo, cacheWriteBehavior, options) {
|
|
647
744
|
var requestId = (queryInfo.lastRequestId = this.generateRequestId());
|
|
745
|
+
// Performing transformForLink here gives this.cache a chance to fill in
|
|
746
|
+
// missing fragment definitions (for example) before sending this document
|
|
747
|
+
// through the link chain.
|
|
648
748
|
var linkDocument = this.cache.transformForLink(options.query);
|
|
649
|
-
return asyncMap(this.getObservableFromLink(linkDocument,
|
|
749
|
+
return asyncMap(this.getObservableFromLink(linkDocument, options.context, options.variables), function (result) {
|
|
650
750
|
var graphQLErrors = getGraphQLErrorsFromResult(result);
|
|
651
751
|
var hasErrors = graphQLErrors.length > 0;
|
|
752
|
+
// If we interrupted this request by calling getResultsFromLink again
|
|
753
|
+
// with the same QueryInfo object, we ignore the old results.
|
|
652
754
|
if (requestId >= queryInfo.lastRequestId) {
|
|
653
755
|
if (hasErrors && options.errorPolicy === "none") {
|
|
756
|
+
// Throwing here effectively calls observer.error.
|
|
654
757
|
throw queryInfo.markError(new ApolloError({
|
|
655
758
|
graphQLErrors: graphQLErrors,
|
|
656
759
|
}));
|
|
657
760
|
}
|
|
761
|
+
// Use linkDocument rather than queryInfo.document so the
|
|
762
|
+
// operation/fragments used to write the result are the same as the
|
|
763
|
+
// ones used to obtain it from the link.
|
|
658
764
|
result = queryInfo.markResult(result, linkDocument, options, cacheWriteBehavior);
|
|
659
765
|
queryInfo.markReady();
|
|
660
766
|
}
|
|
@@ -669,16 +775,19 @@ var QueryManager = (function () {
|
|
|
669
775
|
}
|
|
670
776
|
return aqr;
|
|
671
777
|
}, function (networkError) {
|
|
672
|
-
var error = isApolloError(networkError)
|
|
673
|
-
|
|
674
|
-
: new ApolloError({ networkError: networkError });
|
|
778
|
+
var error = isApolloError(networkError) ? networkError : (new ApolloError({ networkError: networkError }));
|
|
779
|
+
// Avoid storing errors from older interrupted queries.
|
|
675
780
|
if (requestId >= queryInfo.lastRequestId) {
|
|
676
781
|
queryInfo.markError(error);
|
|
677
782
|
}
|
|
678
783
|
throw error;
|
|
679
784
|
});
|
|
680
785
|
};
|
|
681
|
-
QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
|
|
786
|
+
QueryManager.prototype.fetchConcastWithInfo = function (queryId, options,
|
|
787
|
+
// The initial networkStatus for this fetch, most often
|
|
788
|
+
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
|
|
789
|
+
// or setVariables.
|
|
790
|
+
networkStatus, query) {
|
|
682
791
|
var _this = this;
|
|
683
792
|
if (networkStatus === void 0) { networkStatus = NetworkStatus.loading; }
|
|
684
793
|
if (query === void 0) { query = options.query; }
|
|
@@ -696,26 +805,49 @@ var QueryManager = (function () {
|
|
|
696
805
|
context: context,
|
|
697
806
|
});
|
|
698
807
|
var fromVariables = function (variables) {
|
|
808
|
+
// Since normalized is always a fresh copy of options, it's safe to
|
|
809
|
+
// modify its properties here, rather than creating yet another new
|
|
810
|
+
// WatchQueryOptions object.
|
|
699
811
|
normalized.variables = variables;
|
|
700
812
|
var sourcesWithInfo = _this.fetchQueryByPolicy(queryInfo, normalized, networkStatus);
|
|
701
|
-
if (
|
|
813
|
+
if (
|
|
814
|
+
// If we're in standby, postpone advancing options.fetchPolicy using
|
|
815
|
+
// applyNextFetchPolicy.
|
|
816
|
+
normalized.fetchPolicy !== "standby" &&
|
|
817
|
+
// The "standby" policy currently returns [] from fetchQueryByPolicy, so
|
|
818
|
+
// this is another way to detect when nothing was done/fetched.
|
|
702
819
|
sourcesWithInfo.sources.length > 0 &&
|
|
703
820
|
queryInfo.observableQuery) {
|
|
704
821
|
queryInfo.observableQuery["applyNextFetchPolicy"]("after-fetch", options);
|
|
705
822
|
}
|
|
706
823
|
return sourcesWithInfo;
|
|
707
824
|
};
|
|
825
|
+
// This cancel function needs to be set before the concast is created,
|
|
826
|
+
// in case concast creation synchronously cancels the request.
|
|
708
827
|
var cleanupCancelFn = function () { return _this.fetchCancelFns.delete(queryId); };
|
|
709
828
|
this.fetchCancelFns.set(queryId, function (reason) {
|
|
710
829
|
cleanupCancelFn();
|
|
830
|
+
// This delay ensures the concast variable has been initialized.
|
|
711
831
|
setTimeout(function () { return concast.cancel(reason); });
|
|
712
832
|
});
|
|
713
833
|
var concast, containsDataFromLink;
|
|
834
|
+
// If the query has @export(as: ...) directives, then we need to
|
|
835
|
+
// process those directives asynchronously. When there are no
|
|
836
|
+
// @export directives (the common case), we deliberately avoid
|
|
837
|
+
// wrapping the result of this.fetchQueryByPolicy in a Promise,
|
|
838
|
+
// since the timing of result delivery is (unfortunately) important
|
|
839
|
+
// for backwards compatibility. TODO This code could be simpler if
|
|
840
|
+
// we deprecated and removed LocalState.
|
|
714
841
|
if (this.getDocumentInfo(normalized.query).hasClientExports) {
|
|
715
842
|
concast = new Concast(this.localState
|
|
716
843
|
.addExportedVariables(normalized.query, normalized.variables, normalized.context)
|
|
717
844
|
.then(fromVariables)
|
|
718
845
|
.then(function (sourcesWithInfo) { return sourcesWithInfo.sources; }));
|
|
846
|
+
// there is just no way we can synchronously get the *right* value here,
|
|
847
|
+
// so we will assume `true`, which is the behaviour before the bug fix in
|
|
848
|
+
// #10597. This means that bug is not fixed in that case, and is probably
|
|
849
|
+
// un-fixable with reasonable effort for the edge case of @export as
|
|
850
|
+
// directives.
|
|
719
851
|
containsDataFromLink = true;
|
|
720
852
|
}
|
|
721
853
|
else {
|
|
@@ -745,23 +877,71 @@ var QueryManager = (function () {
|
|
|
745
877
|
if (updateCache) {
|
|
746
878
|
this.cache.batch({
|
|
747
879
|
update: updateCache,
|
|
880
|
+
// Since you can perform any combination of cache reads and/or writes in
|
|
881
|
+
// the cache.batch update function, its optimistic option can be either
|
|
882
|
+
// a boolean or a string, representing three distinct modes of
|
|
883
|
+
// operation:
|
|
884
|
+
//
|
|
885
|
+
// * false: read/write only the root layer
|
|
886
|
+
// * true: read/write the topmost layer
|
|
887
|
+
// * string: read/write a fresh optimistic layer with that ID string
|
|
888
|
+
//
|
|
889
|
+
// When typeof optimistic === "string", a new optimistic layer will be
|
|
890
|
+
// temporarily created within cache.batch with that string as its ID. If
|
|
891
|
+
// we then pass that same string as the removeOptimistic option, we can
|
|
892
|
+
// make cache.batch immediately remove the optimistic layer after
|
|
893
|
+
// running the updateCache function, triggering only one broadcast.
|
|
894
|
+
//
|
|
895
|
+
// However, the refetchQueries method accepts only true or false for its
|
|
896
|
+
// optimistic option (not string). We interpret true to mean a temporary
|
|
897
|
+
// optimistic layer should be created, to allow efficiently rolling back
|
|
898
|
+
// the effect of the updateCache function, which involves passing a
|
|
899
|
+
// string instead of true as the optimistic option to cache.batch, when
|
|
900
|
+
// refetchQueries receives optimistic: true.
|
|
901
|
+
//
|
|
902
|
+
// In other words, we are deliberately not supporting the use case of
|
|
903
|
+
// writing to an *existing* optimistic layer (using the refetchQueries
|
|
904
|
+
// updateCache function), since that would potentially interfere with
|
|
905
|
+
// other optimistic updates in progress. Instead, you can read/write
|
|
906
|
+
// only the root layer by passing optimistic: false to refetchQueries,
|
|
907
|
+
// or you can read/write a brand new optimistic layer that will be
|
|
908
|
+
// automatically removed by passing optimistic: true.
|
|
748
909
|
optimistic: (optimistic && removeOptimistic) || false,
|
|
910
|
+
// The removeOptimistic option can also be provided by itself, even if
|
|
911
|
+
// optimistic === false, to remove some previously-added optimistic
|
|
912
|
+
// layer safely and efficiently, like we do in markMutationResult.
|
|
913
|
+
//
|
|
914
|
+
// If an explicit removeOptimistic string is provided with optimistic:
|
|
915
|
+
// true, the removeOptimistic string will determine the ID of the
|
|
916
|
+
// temporary optimistic layer, in case that ever matters.
|
|
749
917
|
removeOptimistic: removeOptimistic,
|
|
750
918
|
onWatchUpdated: function (watch, diff, lastDiff) {
|
|
751
919
|
var oq = watch.watcher instanceof QueryInfo && watch.watcher.observableQuery;
|
|
752
920
|
if (oq) {
|
|
753
921
|
if (onQueryUpdated) {
|
|
922
|
+
// Since we're about to handle this query now, remove it from
|
|
923
|
+
// includedQueriesById, in case it was added earlier because of
|
|
924
|
+
// options.include.
|
|
754
925
|
includedQueriesById.delete(oq.queryId);
|
|
755
926
|
var result = onQueryUpdated(oq, diff, lastDiff);
|
|
756
927
|
if (result === true) {
|
|
928
|
+
// The onQueryUpdated function requested the default refetching
|
|
929
|
+
// behavior by returning true.
|
|
757
930
|
result = oq.refetch();
|
|
758
931
|
}
|
|
932
|
+
// Record the result in the results Map, as long as onQueryUpdated
|
|
933
|
+
// did not return false to skip/ignore this result.
|
|
759
934
|
if (result !== false) {
|
|
760
935
|
results.set(oq, result);
|
|
761
936
|
}
|
|
937
|
+
// Allow the default cache broadcast to happen, except when
|
|
938
|
+
// onQueryUpdated returns false.
|
|
762
939
|
return result;
|
|
763
940
|
}
|
|
764
941
|
if (onQueryUpdated !== null) {
|
|
942
|
+
// If we don't have an onQueryUpdated function, and onQueryUpdated
|
|
943
|
+
// was not disabled by passing null, make sure this query is
|
|
944
|
+
// "included" like any other options.include-specified query.
|
|
765
945
|
includedQueriesById.set(oq.queryId, { oq: oq, lastDiff: lastDiff, diff: diff });
|
|
766
946
|
}
|
|
767
947
|
}
|
|
@@ -772,14 +952,17 @@ var QueryManager = (function () {
|
|
|
772
952
|
includedQueriesById.forEach(function (_a, queryId) {
|
|
773
953
|
var oq = _a.oq, lastDiff = _a.lastDiff, diff = _a.diff;
|
|
774
954
|
var result;
|
|
955
|
+
// If onQueryUpdated is provided, we want to use it for all included
|
|
956
|
+
// queries, even the QueryOptions ones.
|
|
775
957
|
if (onQueryUpdated) {
|
|
776
958
|
if (!diff) {
|
|
777
959
|
var info = oq["queryInfo"];
|
|
778
|
-
info.reset();
|
|
960
|
+
info.reset(); // Force info.getDiff() to read from cache.
|
|
779
961
|
diff = info.getDiff();
|
|
780
962
|
}
|
|
781
963
|
result = onQueryUpdated(oq, diff, lastDiff);
|
|
782
964
|
}
|
|
965
|
+
// Otherwise, we fall back to refetching.
|
|
783
966
|
if (!onQueryUpdated || result === true) {
|
|
784
967
|
result = oq.refetch();
|
|
785
968
|
}
|
|
@@ -792,11 +975,22 @@ var QueryManager = (function () {
|
|
|
792
975
|
});
|
|
793
976
|
}
|
|
794
977
|
if (removeOptimistic) {
|
|
978
|
+
// In case no updateCache callback was provided (so cache.batch was not
|
|
979
|
+
// called above, and thus did not already remove the optimistic layer),
|
|
980
|
+
// remove it here. Since this is a no-op when the layer has already been
|
|
981
|
+
// removed, we do it even if we called cache.batch above, since it's
|
|
982
|
+
// possible this.cache is an instance of some ApolloCache subclass other
|
|
983
|
+
// than InMemoryCache, and does not fully support the removeOptimistic
|
|
984
|
+
// option for cache.batch.
|
|
795
985
|
this.cache.removeOptimistic(removeOptimistic);
|
|
796
986
|
}
|
|
797
987
|
return results;
|
|
798
988
|
};
|
|
799
|
-
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,
|
|
989
|
+
QueryManager.prototype.fetchQueryByPolicy = function (queryInfo, _a,
|
|
990
|
+
// The initial networkStatus for this fetch, most often
|
|
991
|
+
// NetworkStatus.loading, but also possibly fetchMore, poll, refetch,
|
|
992
|
+
// or setVariables.
|
|
993
|
+
networkStatus) {
|
|
800
994
|
var _this = this;
|
|
801
995
|
var query = _a.query, variables = _a.variables, fetchPolicy = _a.fetchPolicy, refetchWritePolicy = _a.refetchWritePolicy, errorPolicy = _a.errorPolicy, returnPartialData = _a.returnPartialData, context = _a.context, notifyOnNetworkStatusChange = _a.notifyOnNetworkStatusChange;
|
|
802
996
|
var oldNetworkStatus = queryInfo.networkStatus;
|
|
@@ -826,6 +1020,10 @@ var QueryManager = (function () {
|
|
|
826
1020
|
})
|
|
827
1021
|
.then(function (resolved) { return fromData(resolved.data || void 0); });
|
|
828
1022
|
}
|
|
1023
|
+
// Resolves https://github.com/apollographql/apollo-client/issues/10317.
|
|
1024
|
+
// If errorPolicy is 'none' and notifyOnNetworkStatusChange is true,
|
|
1025
|
+
// data was incorrectly returned from the cache on refetch:
|
|
1026
|
+
// if diff.missing exists, we should not return cache data.
|
|
829
1027
|
if (errorPolicy === "none" &&
|
|
830
1028
|
networkStatus === NetworkStatus.refetch &&
|
|
831
1029
|
Array.isArray(diff.missing)) {
|
|
@@ -833,13 +1031,13 @@ var QueryManager = (function () {
|
|
|
833
1031
|
}
|
|
834
1032
|
return fromData(data);
|
|
835
1033
|
};
|
|
836
|
-
var cacheWriteBehavior = fetchPolicy === "no-cache"
|
|
837
|
-
|
|
838
|
-
:
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
1034
|
+
var cacheWriteBehavior = fetchPolicy === "no-cache" ? 0 /* CacheWriteBehavior.FORBID */
|
|
1035
|
+
// Watched queries must opt into overwriting existing data on refetch,
|
|
1036
|
+
// by passing refetchWritePolicy: "overwrite" in their WatchQueryOptions.
|
|
1037
|
+
: (networkStatus === NetworkStatus.refetch &&
|
|
1038
|
+
refetchWritePolicy !== "merge") ?
|
|
1039
|
+
1 /* CacheWriteBehavior.OVERWRITE */
|
|
1040
|
+
: 2 /* CacheWriteBehavior.MERGE */;
|
|
843
1041
|
var resultsFromLink = function () {
|
|
844
1042
|
return _this.getResultsFromLink(queryInfo, cacheWriteBehavior, {
|
|
845
1043
|
query: query,
|
|
@@ -898,6 +1096,9 @@ var QueryManager = (function () {
|
|
|
898
1096
|
if (shouldNotify) {
|
|
899
1097
|
return {
|
|
900
1098
|
fromLink: true,
|
|
1099
|
+
// Note that queryInfo.getDiff() for no-cache queries does not call
|
|
1100
|
+
// cache.diff, but instead returns a { complete: false } stub result
|
|
1101
|
+
// when there is no queryInfo.diff already defined.
|
|
901
1102
|
sources: [resultsFromCache(queryInfo.getDiff()), resultsFromLink()],
|
|
902
1103
|
};
|
|
903
1104
|
}
|
|
@@ -915,7 +1116,7 @@ var QueryManager = (function () {
|
|
|
915
1116
|
QueryManager.prototype.prepareContext = function (context) {
|
|
916
1117
|
if (context === void 0) { context = {}; }
|
|
917
1118
|
var newContext = this.localState.prepareContext(context);
|
|
918
|
-
return __assign(__assign({}, newContext), { clientAwareness: this.clientAwareness });
|
|
1119
|
+
return __assign(__assign(__assign({}, this.defaultContext), newContext), { clientAwareness: this.clientAwareness });
|
|
919
1120
|
};
|
|
920
1121
|
return QueryManager;
|
|
921
1122
|
}());
|