@apollo/client 3.9.0-alpha.3 → 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 +484 -401
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +136 -153
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +136 -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 +166 -9
- 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 +51 -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/components/Mutation.d.ts +2 -2
- package/react/components/Mutation.js.map +1 -1
- package/react/components/Query.d.ts +2 -2
- package/react/components/Query.js.map +1 -1
- package/react/components/Subscription.d.ts +2 -2
- package/react/components/Subscription.js.map +1 -1
- package/react/components/types.d.ts +4 -4
- package/react/components/types.js.map +1 -1
- package/react/context/ApolloConsumer.d.ts +3 -3
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloConsumer.js.map +1 -1
- package/react/context/ApolloContext.d.ts +7 -2
- package/react/context/ApolloContext.js +11 -4
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/ApolloProvider.d.ts +3 -3
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/ApolloProvider.js.map +1 -1
- package/react/context/context.cjs +2 -4
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +2 -4
- package/react/hoc/graphql.d.ts +2 -2
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.d.ts +2 -1
- package/react/hoc/hoc-utils.js +4 -2
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs +10 -18
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +10 -18
- package/react/hoc/mutation-hoc.d.ts +2 -2
- package/react/hoc/mutation-hoc.js +10 -5
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.d.ts +2 -2
- package/react/hoc/query-hoc.js +11 -5
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.d.ts +2 -2
- package/react/hoc/subscription-hoc.js +11 -5
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.d.ts +2 -2
- package/react/hoc/withApollo.js +4 -5
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +139 -67
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +139 -67
- 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 +6 -1
- 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 +1 -1
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts +2 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +7 -4
- 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/useApolloClient.js +1 -1
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useBackgroundQuery.js +15 -12
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +5 -4
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +14 -5
- 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 +9 -4
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +11 -0
- package/react/hooks/useQuery.js +139 -7
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReactiveVar.js +6 -1
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +19 -0
- package/react/hooks/useReadQuery.js +5 -11
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +6 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +23 -23
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +54 -2
- 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.d.ts +3 -3
- package/react/ssr/RenderPromises.js +21 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/getDataFromTree.d.ts +4 -4
- package/react/ssr/getDataFromTree.js +19 -4
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/renderToStringWithData.d.ts +2 -2
- package/react/ssr/renderToStringWithData.js.map +1 -1
- package/react/ssr/ssr.cjs +7 -5
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/ssr/ssr.cjs.native.js +7 -5
- package/react/types/types.d.ts +125 -3
- 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.d.ts +4 -2
- package/utilities/graphql/print.js +11 -7
- 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 +68 -55
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +68 -55
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readFromStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/readFromStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,aAAa,EACb,OAAO,EACP,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAgDhD,SAAS,uBAAuB,CAC9B,OAAgC;IAEhC,OAAO;QACL,OAAO,CAAC,YAAY;QACpB,OAAO,CAAC,iBAAiB;QACzB,OAAO,CAAC,OAAO;QAGf,OAAO,CAAC,OAAO,CAAC,eAAe;KAChC,CAAC;AACJ,CAAC;AAED;IAiCE,qBAAY,MAAyB;QAArC,iBA8EC;QAxFO,iBAAY,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,EAGvD,CAAC;QAQF,IAAI,CAAC,MAAM,G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ACnB,yEAAyE,EACzE,0BAA0B,CAAC,KAAK,EAAE,KAAK,CAAC,EACxC,KAAK,CAAC,IAAI,CAAC,KAAK,CACjB,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAO,CAAC,GAAG,EAAE,SAAO,CAAC,CAAC;aACpD;QACH,CAAC,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../../utilities/globals/index.js\";\n\nimport type { DocumentNode, FieldNode, SelectionSetNode } from \"graphql\";\nimport { Kind } from \"graphql\";\nimport type { OptimisticWrapperFunction } from \"optimism\";\nimport { wrap } from \"optimism\";\n\nimport type {\n Reference,\n StoreObject,\n FragmentMap,\n FragmentMapFunction,\n} from \"../../utilities/index.js\";\nimport {\n isField,\n resultKeyNameFromField,\n isReference,\n makeReference,\n shouldInclude,\n addTypenameToDocument,\n getDefaultValues,\n getMainDefinition,\n getQueryDefinition,\n getFragmentFromSelection,\n maybeDeepFreeze,\n mergeDeepArray,\n DeepMerger,\n isNonNullObject,\n canUseWeakMap,\n compact,\n canonicalStringify,\n} from \"../../utilities/index.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n DiffQueryAgainstStoreOptions,\n InMemoryCacheConfig,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n maybeDependOnExistenceOfEntity,\n supportsResultCaching,\n} from \"./entityStore.js\";\nimport {\n isArray,\n extractFragmentContext,\n getTypenameFromStoreObject,\n shouldCanonizeResults,\n} from \"./helpers.js\";\nimport type { Policies } from \"./policies.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type { MissingTree } from \"../core/types/common.js\";\nimport { MissingFieldError } from \"../core/types/common.js\";\nimport { ObjectCanon } from \"./object-canon.js\";\n\nexport type VariableMap = { [name: string]: any };\n\ninterface ReadContext extends ReadMergeModifyContext {\n query: DocumentNode;\n policies: Policies;\n canonizeResults: boolean;\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n}\n\nexport type ExecResult<R = any> = {\n result: R;\n missing?: MissingTree;\n};\n\ntype ExecSelectionSetOptions = {\n selectionSet: SelectionSetNode;\n objectOrReference: StoreObject | Reference;\n enclosingRef: Reference;\n context: ReadContext;\n};\n\ntype ExecSubSelectedArrayOptions = {\n field: FieldNode;\n array: readonly any[];\n enclosingRef: Reference;\n context: ReadContext;\n};\n\nexport interface StoreReaderConfig {\n cache: InMemoryCache;\n addTypename?: boolean;\n resultCacheMaxSize?: number;\n canonizeResults?: boolean;\n canon?: ObjectCanon;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n}\n\n// Arguments type after keyArgs translation.\ntype ExecSelectionSetKeyArgs = [\n SelectionSetNode,\n StoreObject | Reference,\n ReadMergeModifyContext,\n boolean,\n];\n\nfunction execSelectionSetKeyArgs(\n options: ExecSelectionSetOptions\n): ExecSelectionSetKeyArgs {\n return [\n options.selectionSet,\n options.objectOrReference,\n options.context,\n // We split out this property so we can pass different values\n // independently without modifying options.context itself.\n options.context.canonizeResults,\n ];\n}\n\nexport class StoreReader {\n // cached version of executeSelectionSet\n private executeSelectionSet: OptimisticWrapperFunction<\n [ExecSelectionSetOptions], // Actual arguments tuple type.\n ExecResult, // Actual return type.\n ExecSelectionSetKeyArgs\n >;\n\n // cached version of executeSubSelectedArray\n private executeSubSelectedArray: OptimisticWrapperFunction<\n [ExecSubSelectedArrayOptions],\n ExecResult<any>,\n [ExecSubSelectedArrayOptions]\n >;\n\n private config: {\n cache: InMemoryCache;\n addTypename: boolean;\n resultCacheMaxSize?: number;\n canonizeResults: boolean;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n };\n\n private knownResults = new (canUseWeakMap ? WeakMap : Map)<\n Record<string, any>,\n SelectionSetNode\n >();\n\n public canon: ObjectCanon;\n public resetCanon() {\n this.canon = new ObjectCanon();\n }\n\n constructor(config: StoreReaderConfig) {\n this.config = compact(config, {\n addTypename: config.addTypename !== false,\n canonizeResults: shouldCanonizeResults(config),\n });\n\n this.canon = config.canon || new ObjectCanon();\n\n this.executeSelectionSet = wrap(\n (options) => {\n const { canonizeResults } = options.context;\n\n const peekArgs = execSelectionSetKeyArgs(options);\n\n // Negate this boolean option so we can find out if we've already read\n // this result using the other boolean value.\n peekArgs[3] = !canonizeResults;\n\n const other = this.executeSelectionSet.peek(...peekArgs);\n\n if (other) {\n if (canonizeResults) {\n return {\n ...other,\n // If we previously read this result without canonizing it, we can\n // reuse that result simply by canonizing it now.\n result: this.canon.admit(other.result),\n };\n }\n // If we previously read this result with canonization enabled, we can\n // return that canonized result as-is.\n return other;\n }\n\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n\n // Finally, if we didn't find any useful previous results, run the real\n // execSelectionSetImpl method with the given options.\n return this.execSelectionSetImpl(options);\n },\n {\n max: this.config.resultCacheMaxSize,\n keyArgs: execSelectionSetKeyArgs,\n // Note that the parameters of makeCacheKey are determined by the\n // array returned by keyArgs.\n makeCacheKey(selectionSet, parent, context, canonizeResults) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(\n selectionSet,\n isReference(parent) ? parent.__ref : parent,\n context.varString,\n canonizeResults\n );\n }\n },\n }\n );\n\n this.executeSubSelectedArray = wrap(\n (options: ExecSubSelectedArrayOptions) => {\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n return this.execSubSelectedArrayImpl(options);\n },\n {\n max: this.config.resultCacheMaxSize,\n makeCacheKey({ field, array, context }) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(field, array, context.varString);\n }\n },\n }\n );\n }\n\n /**\n * Given a store and a query, return as much of the result as possible and\n * identify if any data was missing from the store.\n * @param {DocumentNode} query A parsed GraphQL query document\n * @param {Store} store The Apollo Client store object\n * @return {result: Object, complete: [boolean]}\n */\n public diffQueryAgainstStore<T>({\n store,\n query,\n rootId = \"ROOT_QUERY\",\n variables,\n returnPartialData = true,\n canonizeResults = this.config.canonizeResults,\n }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> {\n const policies = this.config.cache.policies;\n\n variables = {\n ...getDefaultValues(getQueryDefinition(query)),\n ...variables!,\n };\n\n const rootRef = makeReference(rootId);\n const execResult = this.executeSelectionSet({\n selectionSet: getMainDefinition(query).selectionSet,\n objectOrReference: rootRef,\n enclosingRef: rootRef,\n context: {\n store,\n query,\n policies,\n variables,\n varString: canonicalStringify(variables),\n canonizeResults,\n ...extractFragmentContext(query, this.config.fragments),\n },\n });\n\n let missing: MissingFieldError[] | undefined;\n if (execResult.missing) {\n // For backwards compatibility we still report an array of\n // MissingFieldError objects, even though there will only ever be at most\n // one of them, now that all missing field error messages are grouped\n // together in the execResult.missing tree.\n missing = [\n new MissingFieldError(\n firstMissing(execResult.missing)!,\n execResult.missing,\n query,\n variables\n ),\n ];\n if (!returnPartialData) {\n throw missing[0];\n }\n }\n\n return {\n result: execResult.result,\n complete: !missing,\n missing,\n };\n }\n\n public isFresh(\n result: Record<string, any>,\n parent: StoreObject | Reference,\n selectionSet: SelectionSetNode,\n context: ReadMergeModifyContext\n ): boolean {\n if (\n supportsResultCaching(context.store) &&\n this.knownResults.get(result) === selectionSet\n ) {\n const latest = this.executeSelectionSet.peek(\n selectionSet,\n parent,\n context,\n // If result is canonical, then it could only have been previously\n // cached by the canonizing version of executeSelectionSet, so we can\n // avoid checking both possibilities here.\n this.canon.isKnown(result)\n );\n if (latest && result === latest.result) {\n return true;\n }\n }\n return false;\n }\n\n // Uncached version of executeSelectionSet.\n private execSelectionSetImpl({\n selectionSet,\n objectOrReference,\n enclosingRef,\n context,\n }: ExecSelectionSetOptions): ExecResult {\n if (\n isReference(objectOrReference) &&\n !context.policies.rootTypenamesById[objectOrReference.__ref] &&\n !context.store.has(objectOrReference.__ref)\n ) {\n return {\n result: this.canon.empty,\n missing: `Dangling reference to missing ${objectOrReference.__ref} object`,\n };\n }\n\n const { variables, policies, store } = context;\n const typename = store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n\n const objectsToMerge: Record<string, any>[] = [];\n let missing: MissingTree | undefined;\n const missingMerger = new DeepMerger();\n\n if (\n this.config.addTypename &&\n typeof typename === \"string\" &&\n !policies.rootIdsByTypename[typename]\n ) {\n // Ensure we always include a default value for the __typename\n // field, if we have one, and this.config.addTypename is true. Note\n // that this field can be overridden by other merged objects.\n objectsToMerge.push({ __typename: typename });\n }\n\n function handleMissing<T>(result: ExecResult<T>, resultName: string): T {\n if (result.missing) {\n missing = missingMerger.merge(missing, {\n [resultName]: result.missing,\n });\n }\n return result.result;\n }\n\n const workSet = new Set(selectionSet.selections);\n\n workSet.forEach((selection) => {\n // Omit fields with directives @skip(if: <truthy value>) or\n // @include(if: <falsy value>).\n if (!shouldInclude(selection, variables)) return;\n\n if (isField(selection)) {\n let fieldValue = policies.readField(\n {\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n from: objectOrReference,\n },\n context\n );\n\n const resultName = resultKeyNameFromField(selection);\n\n if (fieldValue === void 0) {\n if (!addTypenameToDocument.added(selection)) {\n missing = missingMerger.merge(missing, {\n [resultName]: `Can't find field '${selection.name.value}' on ${\n isReference(objectOrReference)\n ? objectOrReference.__ref + \" object\"\n : \"object \" + JSON.stringify(objectOrReference, null, 2)\n }`,\n });\n }\n } else if (isArray(fieldValue)) {\n fieldValue = handleMissing(\n this.executeSubSelectedArray({\n field: selection,\n array: fieldValue,\n enclosingRef,\n context,\n }),\n resultName\n );\n } else if (!selection.selectionSet) {\n // If the field does not have a selection set, then we handle it\n // as a scalar value. To keep this.canon from canonicalizing\n // this value, we use this.canon.pass to wrap fieldValue in a\n // Pass object that this.canon.admit will later unwrap as-is.\n if (context.canonizeResults) {\n fieldValue = this.canon.pass(fieldValue);\n }\n } else if (fieldValue != null) {\n // In this case, because we know the field has a selection set,\n // it must be trying to query a GraphQLObjectType, which is why\n // fieldValue must be != null.\n fieldValue = handleMissing(\n this.executeSelectionSet({\n selectionSet: selection.selectionSet,\n objectOrReference: fieldValue as StoreObject | Reference,\n enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,\n context,\n }),\n resultName\n );\n }\n\n if (fieldValue !== void 0) {\n objectsToMerge.push({ [resultName]: fieldValue });\n }\n } else {\n const fragment = getFragmentFromSelection(\n selection,\n context.lookupFragment\n );\n\n if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {\n throw newInvariantError(`No fragment named %s`, selection.name.value);\n }\n\n if (fragment && policies.fragmentMatches(fragment, typename)) {\n fragment.selectionSet.selections.forEach(workSet.add, workSet);\n }\n }\n });\n\n const result = mergeDeepArray(objectsToMerge);\n const finalResult: ExecResult = { result, missing };\n const frozen = context.canonizeResults\n ? this.canon.admit(finalResult)\n : // Since this.canon is normally responsible for freezing results (only in\n // development), freeze them manually if canonization is disabled.\n maybeDeepFreeze(finalResult);\n\n // Store this result with its selection set so that we can quickly\n // recognize it again in the StoreReader#isFresh method.\n if (frozen.result) {\n this.knownResults.set(frozen.result, selectionSet);\n }\n\n return frozen;\n }\n\n // Uncached version of executeSubSelectedArray.\n private execSubSelectedArrayImpl({\n field,\n array,\n enclosingRef,\n context,\n }: ExecSubSelectedArrayOptions): ExecResult {\n let missing: MissingTree | undefined;\n let missingMerger = new DeepMerger<MissingTree[]>();\n\n function handleMissing<T>(childResult: ExecResult<T>, i: number): T {\n if (childResult.missing) {\n missing = missingMerger.merge(missing, { [i]: childResult.missing });\n }\n return childResult.result;\n }\n\n if (field.selectionSet) {\n array = array.filter(context.store.canRead);\n }\n\n array = array.map((item, i) => {\n // null value in array\n if (item === null) {\n return null;\n }\n\n // This is a nested array, recurse\n if (isArray(item)) {\n return handleMissing(\n this.executeSubSelectedArray({\n field,\n array: item,\n enclosingRef,\n context,\n }),\n i\n );\n }\n\n // This is an object, run the selection set on it\n if (field.selectionSet) {\n return handleMissing(\n this.executeSelectionSet({\n selectionSet: field.selectionSet,\n objectOrReference: item,\n enclosingRef: isReference(item) ? item : enclosingRef,\n context,\n }),\n i\n );\n }\n\n if (__DEV__) {\n assertSelectionSetForIdValue(context.store, field, item);\n }\n\n return item;\n });\n\n return {\n result: context.canonizeResults ? this.canon.admit(array) : array,\n missing,\n };\n }\n}\n\nfunction firstMissing(tree: MissingTree): string | undefined {\n try {\n JSON.stringify(tree, (_, value) => {\n if (typeof value === \"string\") throw value;\n return value;\n });\n } catch (result) {\n return result;\n }\n}\n\nfunction assertSelectionSetForIdValue(\n store: NormalizedCache,\n field: FieldNode,\n fieldValue: any\n) {\n if (!field.selectionSet) {\n const workSet = new Set([fieldValue]);\n workSet.forEach((value) => {\n if (isNonNullObject(value)) {\n invariant(\n !isReference(value),\n `Missing selection set for object of type %s returned for query field %s`,\n getTypenameFromStoreObject(store, value),\n field.name.value\n );\n Object.values(value).forEach(workSet.add, workSet);\n }\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"readFromStore.js","sourceRoot":"","sources":["../../../src/cache/inmemory/readFromStore.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAGhF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAQhC,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,WAAW,EACX,aAAa,EACb,aAAa,EACb,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,aAAa,EACb,OAAO,EACP,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAQlC,OAAO,EACL,8BAA8B,EAC9B,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,OAAO,EACP,sBAAsB,EACtB,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,cAAc,CAAC;AAItB,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;A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AC,YAAY,EAAE,CAAC;QACxB,IAAM,SAAO,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC;QACtC,SAAO,CAAC,OAAO,CAAC,UAAC,KAAK;YACpB,IAAI,eAAe,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,SAAS,CACP,CAAC,WAAW,CAAC,KAAK,CAAC,EACnB,yEAAyE,EACzE,0BAA0B,CAAC,KAAK,EAAE,KAAK,CAAC,EACxC,KAAK,CAAC,IAAI,CAAC,KAAK,CACjB,CAAC;gBACF,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,SAAO,CAAC,GAAG,EAAE,SAAO,CAAC,CAAC;YACrD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { invariant, newInvariantError } from \"../../utilities/globals/index.js\";\n\nimport type { DocumentNode, FieldNode, SelectionSetNode } from \"graphql\";\nimport { Kind } from \"graphql\";\nimport type { OptimisticWrapperFunction } from \"optimism\";\nimport { wrap } from \"optimism\";\n\nimport type {\n Reference,\n StoreObject,\n FragmentMap,\n FragmentMapFunction,\n} from \"../../utilities/index.js\";\nimport {\n isField,\n resultKeyNameFromField,\n isReference,\n makeReference,\n shouldInclude,\n addTypenameToDocument,\n getDefaultValues,\n getMainDefinition,\n getQueryDefinition,\n getFragmentFromSelection,\n maybeDeepFreeze,\n mergeDeepArray,\n DeepMerger,\n isNonNullObject,\n canUseWeakMap,\n compact,\n canonicalStringify,\n} from \"../../utilities/index.js\";\nimport type { Cache } from \"../core/types/Cache.js\";\nimport type {\n DiffQueryAgainstStoreOptions,\n InMemoryCacheConfig,\n NormalizedCache,\n ReadMergeModifyContext,\n} from \"./types.js\";\nimport {\n maybeDependOnExistenceOfEntity,\n supportsResultCaching,\n} from \"./entityStore.js\";\nimport {\n isArray,\n extractFragmentContext,\n getTypenameFromStoreObject,\n shouldCanonizeResults,\n} from \"./helpers.js\";\nimport type { Policies } from \"./policies.js\";\nimport type { InMemoryCache } from \"./inMemoryCache.js\";\nimport type { MissingTree } from \"../core/types/common.js\";\nimport { MissingFieldError } from \"../core/types/common.js\";\nimport { ObjectCanon } from \"./object-canon.js\";\n\nexport type VariableMap = { [name: string]: any };\n\ninterface ReadContext extends ReadMergeModifyContext {\n query: DocumentNode;\n policies: Policies;\n canonizeResults: boolean;\n fragmentMap: FragmentMap;\n lookupFragment: FragmentMapFunction;\n}\n\nexport type ExecResult<R = any> = {\n result: R;\n missing?: MissingTree;\n};\n\ntype ExecSelectionSetOptions = {\n selectionSet: SelectionSetNode;\n objectOrReference: StoreObject | Reference;\n enclosingRef: Reference;\n context: ReadContext;\n};\n\ntype ExecSubSelectedArrayOptions = {\n field: FieldNode;\n array: readonly any[];\n enclosingRef: Reference;\n context: ReadContext;\n};\n\nexport interface StoreReaderConfig {\n cache: InMemoryCache;\n addTypename?: boolean;\n resultCacheMaxSize?: number;\n canonizeResults?: boolean;\n canon?: ObjectCanon;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n}\n\n// Arguments type after keyArgs translation.\ntype ExecSelectionSetKeyArgs = [\n SelectionSetNode,\n StoreObject | Reference,\n ReadMergeModifyContext,\n boolean,\n];\n\nfunction execSelectionSetKeyArgs(\n options: ExecSelectionSetOptions\n): ExecSelectionSetKeyArgs {\n return [\n options.selectionSet,\n options.objectOrReference,\n options.context,\n // We split out this property so we can pass different values\n // independently without modifying options.context itself.\n options.context.canonizeResults,\n ];\n}\n\nexport class StoreReader {\n // cached version of executeSelectionSet\n private executeSelectionSet: OptimisticWrapperFunction<\n [ExecSelectionSetOptions], // Actual arguments tuple type.\n ExecResult, // Actual return type.\n ExecSelectionSetKeyArgs\n >;\n\n // cached version of executeSubSelectedArray\n private executeSubSelectedArray: OptimisticWrapperFunction<\n [ExecSubSelectedArrayOptions],\n ExecResult<any>,\n [ExecSubSelectedArrayOptions]\n >;\n\n private config: {\n cache: InMemoryCache;\n addTypename: boolean;\n resultCacheMaxSize?: number;\n canonizeResults: boolean;\n fragments?: InMemoryCacheConfig[\"fragments\"];\n };\n\n private knownResults = new (canUseWeakMap ? WeakMap : Map)<\n Record<string, any>,\n SelectionSetNode\n >();\n\n public canon: ObjectCanon;\n public resetCanon() {\n this.canon = new ObjectCanon();\n }\n\n constructor(config: StoreReaderConfig) {\n this.config = compact(config, {\n addTypename: config.addTypename !== false,\n canonizeResults: shouldCanonizeResults(config),\n });\n\n this.canon = config.canon || new ObjectCanon();\n\n // memoized functions in this class will be \"garbage-collected\"\n // by recreating the whole `StoreReader` in\n // `InMemoryCache.resetResultsCache`\n // (triggered from `InMemoryCache.gc` with `resetResultCache: true`)\n this.executeSelectionSet = wrap(\n (options) => {\n const { canonizeResults } = options.context;\n\n const peekArgs = execSelectionSetKeyArgs(options);\n\n // Negate this boolean option so we can find out if we've already read\n // this result using the other boolean value.\n peekArgs[3] = !canonizeResults;\n\n const other = this.executeSelectionSet.peek(...peekArgs);\n\n if (other) {\n if (canonizeResults) {\n return {\n ...other,\n // If we previously read this result without canonizing it, we can\n // reuse that result simply by canonizing it now.\n result: this.canon.admit(other.result),\n };\n }\n // If we previously read this result with canonization enabled, we can\n // return that canonized result as-is.\n return other;\n }\n\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n\n // Finally, if we didn't find any useful previous results, run the real\n // execSelectionSetImpl method with the given options.\n return this.execSelectionSetImpl(options);\n },\n {\n max: this.config.resultCacheMaxSize,\n keyArgs: execSelectionSetKeyArgs,\n // Note that the parameters of makeCacheKey are determined by the\n // array returned by keyArgs.\n makeCacheKey(selectionSet, parent, context, canonizeResults) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(\n selectionSet,\n isReference(parent) ? parent.__ref : parent,\n context.varString,\n canonizeResults\n );\n }\n },\n }\n );\n\n this.executeSubSelectedArray = wrap(\n (options: ExecSubSelectedArrayOptions) => {\n maybeDependOnExistenceOfEntity(\n options.context.store,\n options.enclosingRef.__ref\n );\n return this.execSubSelectedArrayImpl(options);\n },\n {\n max: this.config.resultCacheMaxSize,\n makeCacheKey({ field, array, context }) {\n if (supportsResultCaching(context.store)) {\n return context.store.makeCacheKey(field, array, context.varString);\n }\n },\n }\n );\n }\n\n /**\n * Given a store and a query, return as much of the result as possible and\n * identify if any data was missing from the store.\n */\n public diffQueryAgainstStore<T>({\n store,\n query,\n rootId = \"ROOT_QUERY\",\n variables,\n returnPartialData = true,\n canonizeResults = this.config.canonizeResults,\n }: DiffQueryAgainstStoreOptions): Cache.DiffResult<T> {\n const policies = this.config.cache.policies;\n\n variables = {\n ...getDefaultValues(getQueryDefinition(query)),\n ...variables!,\n };\n\n const rootRef = makeReference(rootId);\n const execResult = this.executeSelectionSet({\n selectionSet: getMainDefinition(query).selectionSet,\n objectOrReference: rootRef,\n enclosingRef: rootRef,\n context: {\n store,\n query,\n policies,\n variables,\n varString: canonicalStringify(variables),\n canonizeResults,\n ...extractFragmentContext(query, this.config.fragments),\n },\n });\n\n let missing: MissingFieldError[] | undefined;\n if (execResult.missing) {\n // For backwards compatibility we still report an array of\n // MissingFieldError objects, even though there will only ever be at most\n // one of them, now that all missing field error messages are grouped\n // together in the execResult.missing tree.\n missing = [\n new MissingFieldError(\n firstMissing(execResult.missing)!,\n execResult.missing,\n query,\n variables\n ),\n ];\n if (!returnPartialData) {\n throw missing[0];\n }\n }\n\n return {\n result: execResult.result,\n complete: !missing,\n missing,\n };\n }\n\n public isFresh(\n result: Record<string, any>,\n parent: StoreObject | Reference,\n selectionSet: SelectionSetNode,\n context: ReadMergeModifyContext\n ): boolean {\n if (\n supportsResultCaching(context.store) &&\n this.knownResults.get(result) === selectionSet\n ) {\n const latest = this.executeSelectionSet.peek(\n selectionSet,\n parent,\n context,\n // If result is canonical, then it could only have been previously\n // cached by the canonizing version of executeSelectionSet, so we can\n // avoid checking both possibilities here.\n this.canon.isKnown(result)\n );\n if (latest && result === latest.result) {\n return true;\n }\n }\n return false;\n }\n\n // Uncached version of executeSelectionSet.\n private execSelectionSetImpl({\n selectionSet,\n objectOrReference,\n enclosingRef,\n context,\n }: ExecSelectionSetOptions): ExecResult {\n if (\n isReference(objectOrReference) &&\n !context.policies.rootTypenamesById[objectOrReference.__ref] &&\n !context.store.has(objectOrReference.__ref)\n ) {\n return {\n result: this.canon.empty,\n missing: `Dangling reference to missing ${objectOrReference.__ref} object`,\n };\n }\n\n const { variables, policies, store } = context;\n const typename = store.getFieldValue<string>(\n objectOrReference,\n \"__typename\"\n );\n\n const objectsToMerge: Record<string, any>[] = [];\n let missing: MissingTree | undefined;\n const missingMerger = new DeepMerger();\n\n if (\n this.config.addTypename &&\n typeof typename === \"string\" &&\n !policies.rootIdsByTypename[typename]\n ) {\n // Ensure we always include a default value for the __typename\n // field, if we have one, and this.config.addTypename is true. Note\n // that this field can be overridden by other merged objects.\n objectsToMerge.push({ __typename: typename });\n }\n\n function handleMissing<T>(result: ExecResult<T>, resultName: string): T {\n if (result.missing) {\n missing = missingMerger.merge(missing, {\n [resultName]: result.missing,\n });\n }\n return result.result;\n }\n\n const workSet = new Set(selectionSet.selections);\n\n workSet.forEach((selection) => {\n // Omit fields with directives @skip(if: <truthy value>) or\n // @include(if: <falsy value>).\n if (!shouldInclude(selection, variables)) return;\n\n if (isField(selection)) {\n let fieldValue = policies.readField(\n {\n fieldName: selection.name.value,\n field: selection,\n variables: context.variables,\n from: objectOrReference,\n },\n context\n );\n\n const resultName = resultKeyNameFromField(selection);\n\n if (fieldValue === void 0) {\n if (!addTypenameToDocument.added(selection)) {\n missing = missingMerger.merge(missing, {\n [resultName]: `Can't find field '${selection.name.value}' on ${\n isReference(objectOrReference) ?\n objectOrReference.__ref + \" object\"\n : \"object \" + JSON.stringify(objectOrReference, null, 2)\n }`,\n });\n }\n } else if (isArray(fieldValue)) {\n fieldValue = handleMissing(\n this.executeSubSelectedArray({\n field: selection,\n array: fieldValue,\n enclosingRef,\n context,\n }),\n resultName\n );\n } else if (!selection.selectionSet) {\n // If the field does not have a selection set, then we handle it\n // as a scalar value. To keep this.canon from canonicalizing\n // this value, we use this.canon.pass to wrap fieldValue in a\n // Pass object that this.canon.admit will later unwrap as-is.\n if (context.canonizeResults) {\n fieldValue = this.canon.pass(fieldValue);\n }\n } else if (fieldValue != null) {\n // In this case, because we know the field has a selection set,\n // it must be trying to query a GraphQLObjectType, which is why\n // fieldValue must be != null.\n fieldValue = handleMissing(\n this.executeSelectionSet({\n selectionSet: selection.selectionSet,\n objectOrReference: fieldValue as StoreObject | Reference,\n enclosingRef: isReference(fieldValue) ? fieldValue : enclosingRef,\n context,\n }),\n resultName\n );\n }\n\n if (fieldValue !== void 0) {\n objectsToMerge.push({ [resultName]: fieldValue });\n }\n } else {\n const fragment = getFragmentFromSelection(\n selection,\n context.lookupFragment\n );\n\n if (!fragment && selection.kind === Kind.FRAGMENT_SPREAD) {\n throw newInvariantError(`No fragment named %s`, selection.name.value);\n }\n\n if (fragment && policies.fragmentMatches(fragment, typename)) {\n fragment.selectionSet.selections.forEach(workSet.add, workSet);\n }\n }\n });\n\n const result = mergeDeepArray(objectsToMerge);\n const finalResult: ExecResult = { result, missing };\n const frozen =\n context.canonizeResults ?\n this.canon.admit(finalResult)\n // Since this.canon is normally responsible for freezing results (only in\n // development), freeze them manually if canonization is disabled.\n : maybeDeepFreeze(finalResult);\n\n // Store this result with its selection set so that we can quickly\n // recognize it again in the StoreReader#isFresh method.\n if (frozen.result) {\n this.knownResults.set(frozen.result, selectionSet);\n }\n\n return frozen;\n }\n\n // Uncached version of executeSubSelectedArray.\n private execSubSelectedArrayImpl({\n field,\n array,\n enclosingRef,\n context,\n }: ExecSubSelectedArrayOptions): ExecResult {\n let missing: MissingTree | undefined;\n let missingMerger = new DeepMerger<MissingTree[]>();\n\n function handleMissing<T>(childResult: ExecResult<T>, i: number): T {\n if (childResult.missing) {\n missing = missingMerger.merge(missing, { [i]: childResult.missing });\n }\n return childResult.result;\n }\n\n if (field.selectionSet) {\n array = array.filter(context.store.canRead);\n }\n\n array = array.map((item, i) => {\n // null value in array\n if (item === null) {\n return null;\n }\n\n // This is a nested array, recurse\n if (isArray(item)) {\n return handleMissing(\n this.executeSubSelectedArray({\n field,\n array: item,\n enclosingRef,\n context,\n }),\n i\n );\n }\n\n // This is an object, run the selection set on it\n if (field.selectionSet) {\n return handleMissing(\n this.executeSelectionSet({\n selectionSet: field.selectionSet,\n objectOrReference: item,\n enclosingRef: isReference(item) ? item : enclosingRef,\n context,\n }),\n i\n );\n }\n\n if (__DEV__) {\n assertSelectionSetForIdValue(context.store, field, item);\n }\n\n return item;\n });\n\n return {\n result: context.canonizeResults ? this.canon.admit(array) : array,\n missing,\n };\n }\n}\n\nfunction firstMissing(tree: MissingTree): string | undefined {\n try {\n JSON.stringify(tree, (_, value) => {\n if (typeof value === \"string\") throw value;\n return value;\n });\n } catch (result) {\n return result as string;\n }\n}\n\nfunction assertSelectionSetForIdValue(\n store: NormalizedCache,\n field: FieldNode,\n fieldValue: any\n) {\n if (!field.selectionSet) {\n const workSet = new Set([fieldValue]);\n workSet.forEach((value) => {\n if (isNonNullObject(value)) {\n invariant(\n !isReference(value),\n `Missing selection set for object of type %s returned for query field %s`,\n getTypenameFromStoreObject(store, value),\n field.name.value\n );\n Object.values(value).forEach(workSet.add, workSet);\n }\n });\n }\n}\n"]}
|
|
@@ -12,6 +12,10 @@ export interface IdGetterObj extends Object {
|
|
|
12
12
|
_id?: string;
|
|
13
13
|
}
|
|
14
14
|
export declare type IdGetter = (value: IdGetterObj) => string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* This is an interface used to access, set and remove
|
|
17
|
+
* StoreObjects from the cache
|
|
18
|
+
*/
|
|
15
19
|
export interface NormalizedCache {
|
|
16
20
|
has(dataId: string): boolean;
|
|
17
21
|
get(dataId: string, fieldName: string): StoreValue;
|
|
@@ -20,8 +24,22 @@ export interface NormalizedCache {
|
|
|
20
24
|
modify<Entity extends Record<string, any>>(dataId: string, fields: Modifiers<Entity> | AllFieldsModifier<Entity>): boolean;
|
|
21
25
|
delete(dataId: string, fieldName?: string): boolean;
|
|
22
26
|
clear(): void;
|
|
27
|
+
/**
|
|
28
|
+
* returns an Object with key-value pairs matching the contents of the store
|
|
29
|
+
*/
|
|
23
30
|
toObject(): NormalizedCacheObject;
|
|
31
|
+
/**
|
|
32
|
+
* replace the state of the store
|
|
33
|
+
*/
|
|
24
34
|
replace(newData: NormalizedCacheObject): void;
|
|
35
|
+
/**
|
|
36
|
+
* Retain (or release) a given root ID to protect (or expose) it and its
|
|
37
|
+
* transitive child entities from (or to) garbage collection. The current
|
|
38
|
+
* retainment count is returned by both methods. Note that releasing a root
|
|
39
|
+
* ID does not cause that entity to be garbage collected, but merely removes
|
|
40
|
+
* it from the set of root IDs that will be considered during the next
|
|
41
|
+
* mark-and-sweep collection.
|
|
42
|
+
*/
|
|
25
43
|
retain(rootId: string): number;
|
|
26
44
|
release(rootId: string): number;
|
|
27
45
|
getFieldValue: FieldValueGetter;
|
|
@@ -29,6 +47,10 @@ export interface NormalizedCache {
|
|
|
29
47
|
canRead: CanReadFunction;
|
|
30
48
|
getStorage(idOrObj: string | StoreObject, ...storeFieldNames: (string | number)[]): StorageType;
|
|
31
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* This is a normalized representation of the Apollo query result cache. It consists of
|
|
52
|
+
* a flattened representation of query result trees.
|
|
53
|
+
*/
|
|
32
54
|
export interface NormalizedCacheObject {
|
|
33
55
|
__META?: {
|
|
34
56
|
extraRootIds: string[];
|
|
@@ -41,7 +63,13 @@ export type OptimisticStoreItem = {
|
|
|
41
63
|
transaction: Transaction<NormalizedCacheObject>;
|
|
42
64
|
};
|
|
43
65
|
export type ReadQueryOptions = {
|
|
66
|
+
/**
|
|
67
|
+
* The Apollo Client store object.
|
|
68
|
+
*/
|
|
44
69
|
store: NormalizedCache;
|
|
70
|
+
/**
|
|
71
|
+
* A parsed GraphQL query document.
|
|
72
|
+
*/
|
|
45
73
|
query: DocumentNode;
|
|
46
74
|
variables?: Object;
|
|
47
75
|
previousResult?: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { Transaction } from \"../core/cache.js\";\nimport type {\n StoreObject,\n StoreValue,\n Reference,\n} from \"../../utilities/index.js\";\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type {\n TypePolicies,\n PossibleTypesMap,\n KeyFieldsFunction,\n StorageType,\n FieldMergeFunction,\n} from \"./policies.js\";\nimport type {\n Modifiers,\n ToReferenceFunction,\n CanReadFunction,\n AllFieldsModifier,\n} from \"../core/types/common.js\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\n\nexport type { StoreObject, StoreValue, Reference };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction<NormalizedCacheObject>;\n};\n\nexport type ReadQueryOptions = {\n store: NormalizedCache;\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n canonizeResults?: boolean;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n addTypename?: boolean;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n resultCacheMaxSize?: number;\n canonizeResults?: boolean;\n fragments?: FragmentRegistryAPI;\n}\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n variables?: Record<string, any>;\n // A JSON.stringify-serialized version of context.variables.\n varString?: string;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/cache/inmemory/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { DocumentNode, FieldNode } from \"graphql\";\n\nimport type { Transaction } from \"../core/cache.js\";\nimport type {\n StoreObject,\n StoreValue,\n Reference,\n} from \"../../utilities/index.js\";\nimport type { FieldValueGetter } from \"./entityStore.js\";\nimport type {\n TypePolicies,\n PossibleTypesMap,\n KeyFieldsFunction,\n StorageType,\n FieldMergeFunction,\n} from \"./policies.js\";\nimport type {\n Modifiers,\n ToReferenceFunction,\n CanReadFunction,\n AllFieldsModifier,\n} from \"../core/types/common.js\";\n\nimport type { FragmentRegistryAPI } from \"./fragmentRegistry.js\";\n\nexport type { StoreObject, StoreValue, Reference };\n\nexport interface IdGetterObj extends Object {\n __typename?: string;\n id?: string;\n _id?: string;\n}\n\nexport declare type IdGetter = (value: IdGetterObj) => string | undefined;\n\n/**\n * This is an interface used to access, set and remove\n * StoreObjects from the cache\n */\nexport interface NormalizedCache {\n has(dataId: string): boolean;\n get(dataId: string, fieldName: string): StoreValue;\n\n // The store.merge method allows either argument to be a string ID, but\n // the other argument has to be a StoreObject. Either way, newer fields\n // always take precedence over older fields.\n merge(olderId: string, newerObject: StoreObject): void;\n merge(olderObject: StoreObject, newerId: string): void;\n\n modify<Entity extends Record<string, any>>(\n dataId: string,\n fields: Modifiers<Entity> | AllFieldsModifier<Entity>\n ): boolean;\n delete(dataId: string, fieldName?: string): boolean;\n clear(): void;\n\n // non-Map elements:\n /**\n * returns an Object with key-value pairs matching the contents of the store\n */\n toObject(): NormalizedCacheObject;\n /**\n * replace the state of the store\n */\n replace(newData: NormalizedCacheObject): void;\n\n /**\n * Retain (or release) a given root ID to protect (or expose) it and its\n * transitive child entities from (or to) garbage collection. The current\n * retainment count is returned by both methods. Note that releasing a root\n * ID does not cause that entity to be garbage collected, but merely removes\n * it from the set of root IDs that will be considered during the next\n * mark-and-sweep collection.\n */\n retain(rootId: string): number;\n release(rootId: string): number;\n\n getFieldValue: FieldValueGetter;\n toReference: ToReferenceFunction;\n canRead: CanReadFunction;\n\n getStorage(\n idOrObj: string | StoreObject,\n ...storeFieldNames: (string | number)[]\n ): StorageType;\n}\n\n/**\n * This is a normalized representation of the Apollo query result cache. It consists of\n * a flattened representation of query result trees.\n */\nexport interface NormalizedCacheObject {\n __META?: {\n // Well-known singleton IDs like ROOT_QUERY and ROOT_MUTATION are\n // always considered to be root IDs during cache.gc garbage\n // collection, but other IDs can become roots if they are written\n // directly with cache.writeFragment or retained explicitly with\n // cache.retain. When such IDs exist, we include them in the __META\n // section so that they can survive cache.{extract,restore}.\n extraRootIds: string[];\n };\n [dataId: string]: StoreObject | undefined;\n}\n\nexport type OptimisticStoreItem = {\n id: string;\n data: NormalizedCacheObject;\n transaction: Transaction<NormalizedCacheObject>;\n};\n\nexport type ReadQueryOptions = {\n /**\n * The Apollo Client store object.\n */\n store: NormalizedCache;\n /**\n * A parsed GraphQL query document.\n */\n query: DocumentNode;\n variables?: Object;\n previousResult?: any;\n canonizeResults?: boolean;\n rootId?: string;\n config?: ApolloReducerConfig;\n};\n\nexport type DiffQueryAgainstStoreOptions = ReadQueryOptions & {\n returnPartialData?: boolean;\n};\n\nexport type ApolloReducerConfig = {\n dataIdFromObject?: KeyFieldsFunction;\n addTypename?: boolean;\n};\n\nexport interface InMemoryCacheConfig extends ApolloReducerConfig {\n resultCaching?: boolean;\n possibleTypes?: PossibleTypesMap;\n typePolicies?: TypePolicies;\n resultCacheMaxSize?: number;\n canonizeResults?: boolean;\n fragments?: FragmentRegistryAPI;\n}\n\nexport interface MergeInfo {\n field: FieldNode;\n typename: string | undefined;\n merge: FieldMergeFunction;\n}\n\nexport interface MergeTree {\n info?: MergeInfo;\n map: Map<string | number, MergeTree>;\n}\n\nexport interface ReadMergeModifyContext {\n store: NormalizedCache;\n variables?: Record<string, any>;\n // A JSON.stringify-serialized version of context.variables.\n varString?: string;\n}\n"]}
|
|
@@ -6,18 +6,23 @@ import { Kind } from "graphql";
|
|
|
6
6
|
import { getFragmentFromSelection, getDefaultValues, getOperationDefinition, getTypenameFromResult, makeReference, isField, resultKeyNameFromField, isReference, shouldInclude, cloneDeep, addTypenameToDocument, isNonEmptyArray, argumentsObjectFromField, canonicalStringify, } from "../../utilities/index.js";
|
|
7
7
|
import { isArray, makeProcessedFieldsMerger, fieldNameFromStoreName, storeValueIsStoreObject, extractFragmentContext, } from "./helpers.js";
|
|
8
8
|
import { normalizeReadFieldOptions } from "./policies.js";
|
|
9
|
+
// Since there are only four possible combinations of context.clientOnly and
|
|
10
|
+
// context.deferred values, we should need at most four "flavors" of any given
|
|
11
|
+
// WriteContext. To avoid creating multiple copies of the same context, we cache
|
|
12
|
+
// the contexts in the context.flavors Map (shared by all flavors) according to
|
|
13
|
+
// their clientOnly and deferred values (always in that order).
|
|
9
14
|
function getContextFlavor(context, clientOnly, deferred) {
|
|
10
15
|
var key = "".concat(clientOnly).concat(deferred);
|
|
11
16
|
var flavored = context.flavors.get(key);
|
|
12
17
|
if (!flavored) {
|
|
13
18
|
context.flavors.set(key, (flavored =
|
|
14
|
-
context.clientOnly === clientOnly && context.deferred === deferred
|
|
15
|
-
|
|
19
|
+
context.clientOnly === clientOnly && context.deferred === deferred ?
|
|
20
|
+
context
|
|
16
21
|
: __assign(__assign({}, context), { clientOnly: clientOnly, deferred: deferred })));
|
|
17
22
|
}
|
|
18
23
|
return flavored;
|
|
19
24
|
}
|
|
20
|
-
var StoreWriter = (function () {
|
|
25
|
+
var StoreWriter = /** @class */ (function () {
|
|
21
26
|
function StoreWriter(cache, reader, fragments) {
|
|
22
27
|
this.cache = cache;
|
|
23
28
|
this.reader = reader;
|
|
@@ -42,14 +47,21 @@ var StoreWriter = (function () {
|
|
|
42
47
|
if (!isReference(ref)) {
|
|
43
48
|
throw newInvariantError(11, result);
|
|
44
49
|
}
|
|
50
|
+
// So far, the store has not been modified, so now it's time to process
|
|
51
|
+
// context.incomingById and merge those incoming fields into context.store.
|
|
45
52
|
context.incomingById.forEach(function (_a, dataId) {
|
|
46
53
|
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
47
54
|
var entityRef = makeReference(dataId);
|
|
48
55
|
if (mergeTree && mergeTree.map.size) {
|
|
49
56
|
var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
|
|
50
57
|
if (isReference(applied)) {
|
|
58
|
+
// Assume References returned by applyMerges have already been merged
|
|
59
|
+
// into the store. See makeMergeObjectsFunction in policies.ts for an
|
|
60
|
+
// example of how this can happen.
|
|
51
61
|
return;
|
|
52
62
|
}
|
|
63
|
+
// Otherwise, applyMerges returned a StoreObject, whose fields we should
|
|
64
|
+
// merge into the store (see store.merge statement below).
|
|
53
65
|
storeObject = applied;
|
|
54
66
|
}
|
|
55
67
|
if (globalThis.__DEV__ !== false && !context.overwrite) {
|
|
@@ -68,6 +80,10 @@ var StoreWriter = (function () {
|
|
|
68
80
|
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
69
81
|
};
|
|
70
82
|
Object.keys(storeObject).forEach(function (storeFieldName) {
|
|
83
|
+
// If a merge function was defined for this field, trust that it
|
|
84
|
+
// did the right thing about (not) clobbering data. If the field
|
|
85
|
+
// has no selection set, it's a scalar field, so it doesn't need
|
|
86
|
+
// a merge function (even if it's an object, like JSON data).
|
|
71
87
|
if (hasSelectionSet_1(storeFieldName) &&
|
|
72
88
|
!hasMergeFunction_1(storeFieldName)) {
|
|
73
89
|
warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
|
|
@@ -76,20 +92,41 @@ var StoreWriter = (function () {
|
|
|
76
92
|
}
|
|
77
93
|
store.merge(dataId, storeObject);
|
|
78
94
|
});
|
|
95
|
+
// Any IDs written explicitly to the cache will be retained as
|
|
96
|
+
// reachable root IDs for garbage collection purposes. Although this
|
|
97
|
+
// logic includes root IDs like ROOT_QUERY and ROOT_MUTATION, their
|
|
98
|
+
// retainment counts are effectively ignored because cache.gc() always
|
|
99
|
+
// includes them in its root ID set.
|
|
79
100
|
store.retain(ref.__ref);
|
|
80
101
|
return ref;
|
|
81
102
|
};
|
|
82
103
|
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
83
104
|
var _this = this;
|
|
84
|
-
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context,
|
|
105
|
+
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context,
|
|
106
|
+
// This object allows processSelectionSet to report useful information
|
|
107
|
+
// to its callers without explicitly returning that information.
|
|
108
|
+
mergeTree = _a.mergeTree;
|
|
85
109
|
var policies = this.cache.policies;
|
|
110
|
+
// This variable will be repeatedly updated using context.merge to
|
|
111
|
+
// accumulate all fields that need to be written into the store.
|
|
86
112
|
var incoming = Object.create(null);
|
|
113
|
+
// If typename was not passed in, infer it. Note that typename is
|
|
114
|
+
// always passed in for tricky-to-infer cases such as "Query" for
|
|
115
|
+
// ROOT_QUERY.
|
|
87
116
|
var typename = (dataId && policies.rootTypenamesById[dataId]) ||
|
|
88
117
|
getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
|
|
89
118
|
(dataId && context.store.get(dataId, "__typename"));
|
|
90
119
|
if ("string" === typeof typename) {
|
|
91
120
|
incoming.__typename = typename;
|
|
92
121
|
}
|
|
122
|
+
// This readField function will be passed as context.readField in the
|
|
123
|
+
// KeyFieldsContext object created within policies.identify (called below).
|
|
124
|
+
// In addition to reading from the existing context.store (thanks to the
|
|
125
|
+
// policies.readField(options, context) line at the very bottom), this
|
|
126
|
+
// version of readField can read from Reference objects that are currently
|
|
127
|
+
// pending in context.incomingById, which is important whenever keyFields
|
|
128
|
+
// need to be extracted from a child object that processSelectionSet has
|
|
129
|
+
// turned into a Reference.
|
|
93
130
|
var readField = function () {
|
|
94
131
|
var options = normalizeReadFieldOptions(arguments, incoming, context.variables);
|
|
95
132
|
if (isReference(options.from)) {
|
|
@@ -104,7 +141,11 @@ var StoreWriter = (function () {
|
|
|
104
141
|
return policies.readField(options, context);
|
|
105
142
|
};
|
|
106
143
|
var fieldNodeSet = new Set();
|
|
107
|
-
this.flattenFields(selectionSet, result,
|
|
144
|
+
this.flattenFields(selectionSet, result,
|
|
145
|
+
// This WriteContext will be the default context value for fields returned
|
|
146
|
+
// by the flattenFields method, but some fields may be assigned a modified
|
|
147
|
+
// context, depending on the presence of @client and other directives.
|
|
148
|
+
context, typename).forEach(function (context, field) {
|
|
108
149
|
var _a;
|
|
109
150
|
var resultFieldKey = resultKeyNameFromField(field);
|
|
110
151
|
var value = result[resultFieldKey];
|
|
@@ -117,10 +158,18 @@ var StoreWriter = (function () {
|
|
|
117
158
|
variables: context.variables,
|
|
118
159
|
});
|
|
119
160
|
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
120
|
-
var incomingValue = _this.processFieldValue(value, field,
|
|
121
|
-
|
|
161
|
+
var incomingValue = _this.processFieldValue(value, field,
|
|
162
|
+
// Reset context.clientOnly and context.deferred to their default
|
|
163
|
+
// values before processing nested selection sets.
|
|
164
|
+
field.selectionSet ?
|
|
165
|
+
getContextFlavor(context, false, false)
|
|
122
166
|
: context, childTree);
|
|
167
|
+
// To determine if this field holds a child object with a merge function
|
|
168
|
+
// defined in its type policy (see PR #7070), we need to figure out the
|
|
169
|
+
// child object's __typename.
|
|
123
170
|
var childTypename = void 0;
|
|
171
|
+
// The field's value can be an object that has a __typename only if the
|
|
172
|
+
// field has a selection set. Otherwise incomingValue is scalar.
|
|
124
173
|
if (field.selectionSet &&
|
|
125
174
|
(isReference(incomingValue) || storeValueIsStoreObject(incomingValue))) {
|
|
126
175
|
childTypename = readField("__typename", incomingValue);
|
|
@@ -128,6 +177,7 @@ var StoreWriter = (function () {
|
|
|
128
177
|
var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
|
|
129
178
|
if (merge) {
|
|
130
179
|
childTree.info = {
|
|
180
|
+
// TODO Check compatibility against any existing childTree.field?
|
|
131
181
|
field: field,
|
|
132
182
|
typename: typename,
|
|
133
183
|
merge: merge,
|
|
@@ -144,10 +194,15 @@ var StoreWriter = (function () {
|
|
|
144
194
|
!context.clientOnly &&
|
|
145
195
|
!context.deferred &&
|
|
146
196
|
!addTypenameToDocument.added(field) &&
|
|
197
|
+
// If the field has a read function, it may be a synthetic field or
|
|
198
|
+
// provide a default value, so its absence from the written data should
|
|
199
|
+
// not be cause for alarm.
|
|
147
200
|
!policies.getReadFunction(typename, field.name.value)) {
|
|
148
201
|
globalThis.__DEV__ !== false && invariant.error(12, resultKeyNameFromField(field), result);
|
|
149
202
|
}
|
|
150
203
|
});
|
|
204
|
+
// Identify the result object, even if dataId was already provided,
|
|
205
|
+
// since we always need keyObject below.
|
|
151
206
|
try {
|
|
152
207
|
var _b = policies.identify(result, {
|
|
153
208
|
typename: typename,
|
|
@@ -156,21 +211,37 @@ var StoreWriter = (function () {
|
|
|
156
211
|
storeObject: incoming,
|
|
157
212
|
readField: readField,
|
|
158
213
|
}), id = _b[0], keyObject = _b[1];
|
|
214
|
+
// If dataId was not provided, fall back to the id just generated by
|
|
215
|
+
// policies.identify.
|
|
159
216
|
dataId = dataId || id;
|
|
217
|
+
// Write any key fields that were used during identification, even if
|
|
218
|
+
// they were not mentioned in the original query.
|
|
160
219
|
if (keyObject) {
|
|
220
|
+
// TODO Reverse the order of the arguments?
|
|
161
221
|
incoming = context.merge(incoming, keyObject);
|
|
162
222
|
}
|
|
163
223
|
}
|
|
164
224
|
catch (e) {
|
|
225
|
+
// If dataId was provided, tolerate failure of policies.identify.
|
|
165
226
|
if (!dataId)
|
|
166
227
|
throw e;
|
|
167
228
|
}
|
|
168
229
|
if ("string" === typeof dataId) {
|
|
169
230
|
var dataRef = makeReference(dataId);
|
|
231
|
+
// Avoid processing the same entity object using the same selection
|
|
232
|
+
// set more than once. We use an array instead of a Set since most
|
|
233
|
+
// entity IDs will be written using only one selection set, so the
|
|
234
|
+
// size of this array is likely to be very small, meaning indexOf is
|
|
235
|
+
// likely to be faster than Set.prototype.has.
|
|
170
236
|
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
171
237
|
if (sets.indexOf(selectionSet) >= 0)
|
|
172
238
|
return dataRef;
|
|
173
239
|
sets.push(selectionSet);
|
|
240
|
+
// If we're about to write a result object into the store, but we
|
|
241
|
+
// happen to know that the exact same (===) result object would be
|
|
242
|
+
// returned if we were to reread the result with the same inputs,
|
|
243
|
+
// then we can skip the rest of the processSelectionSet work for
|
|
244
|
+
// this object, and immediately return a Reference to it.
|
|
174
245
|
if (this.reader &&
|
|
175
246
|
this.reader.isFresh(result, dataRef, selectionSet, context)) {
|
|
176
247
|
return dataRef;
|
|
@@ -184,6 +255,9 @@ var StoreWriter = (function () {
|
|
|
184
255
|
else {
|
|
185
256
|
context.incomingById.set(dataId, {
|
|
186
257
|
storeObject: incoming,
|
|
258
|
+
// Save a reference to mergeTree only if it is not empty, because
|
|
259
|
+
// empty MergeTrees may be recycled by maybeRecycleChildMergeTree and
|
|
260
|
+
// reused for entirely different parts of the result tree.
|
|
187
261
|
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
188
262
|
fieldNodeSet: fieldNodeSet,
|
|
189
263
|
});
|
|
@@ -195,6 +269,9 @@ var StoreWriter = (function () {
|
|
|
195
269
|
StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
|
|
196
270
|
var _this = this;
|
|
197
271
|
if (!field.selectionSet || value === null) {
|
|
272
|
+
// In development, we need to clone scalar values so that they can be
|
|
273
|
+
// safely frozen with maybeDeepFreeze in readFromStore.ts. In production,
|
|
274
|
+
// it's cheaper to store the scalar values directly in the cache.
|
|
198
275
|
return globalThis.__DEV__ !== false ? cloneDeep(value) : value;
|
|
199
276
|
}
|
|
200
277
|
if (isArray(value)) {
|
|
@@ -211,13 +288,20 @@ var StoreWriter = (function () {
|
|
|
211
288
|
mergeTree: mergeTree,
|
|
212
289
|
});
|
|
213
290
|
};
|
|
291
|
+
// Implements https://spec.graphql.org/draft/#sec-Field-Collection, but with
|
|
292
|
+
// some additions for tracking @client and @defer directives.
|
|
214
293
|
StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
|
|
215
294
|
if (typename === void 0) { typename = getTypenameFromResult(result, selectionSet, context.fragmentMap); }
|
|
216
295
|
var fieldMap = new Map();
|
|
217
296
|
var policies = this.cache.policies;
|
|
218
|
-
var limitingTrie = new Trie(false);
|
|
297
|
+
var limitingTrie = new Trie(false); // No need for WeakMap, since limitingTrie does not escape.
|
|
219
298
|
(function flatten(selectionSet, inheritedContext) {
|
|
220
|
-
var visitedNode = limitingTrie.lookup(selectionSet,
|
|
299
|
+
var visitedNode = limitingTrie.lookup(selectionSet,
|
|
300
|
+
// Because we take inheritedClientOnly and inheritedDeferred into
|
|
301
|
+
// consideration here (in addition to selectionSet), it's possible for
|
|
302
|
+
// the same selection set to be flattened more than once, if it appears
|
|
303
|
+
// in the query with different @client and/or @directive configurations.
|
|
304
|
+
inheritedContext.clientOnly, inheritedContext.deferred);
|
|
221
305
|
if (visitedNode.visited)
|
|
222
306
|
return;
|
|
223
307
|
visitedNode.visited = true;
|
|
@@ -225,7 +309,11 @@ var StoreWriter = (function () {
|
|
|
225
309
|
if (!shouldInclude(selection, context.variables))
|
|
226
310
|
return;
|
|
227
311
|
var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
|
|
228
|
-
if (
|
|
312
|
+
if (
|
|
313
|
+
// Since the presence of @client or @defer on this field can only
|
|
314
|
+
// cause clientOnly or deferred to become true, we can skip the
|
|
315
|
+
// forEach loop if both clientOnly and deferred are already true.
|
|
316
|
+
!(clientOnly && deferred) &&
|
|
229
317
|
isNonEmptyArray(selection.directives)) {
|
|
230
318
|
selection.directives.forEach(function (dir) {
|
|
231
319
|
var name = dir.name.value;
|
|
@@ -233,15 +321,24 @@ var StoreWriter = (function () {
|
|
|
233
321
|
clientOnly = true;
|
|
234
322
|
if (name === "defer") {
|
|
235
323
|
var args = argumentsObjectFromField(dir, context.variables);
|
|
324
|
+
// The @defer directive takes an optional args.if boolean
|
|
325
|
+
// argument, similar to @include(if: boolean). Note that
|
|
326
|
+
// @defer(if: false) does not make context.deferred false, but
|
|
327
|
+
// instead behaves as if there was no @defer directive.
|
|
236
328
|
if (!args || args.if !== false) {
|
|
237
329
|
deferred = true;
|
|
238
330
|
}
|
|
331
|
+
// TODO In the future, we may want to record args.label using
|
|
332
|
+
// context.deferred, if a label is specified.
|
|
239
333
|
}
|
|
240
334
|
});
|
|
241
335
|
}
|
|
242
336
|
if (isField(selection)) {
|
|
243
337
|
var existing = fieldMap.get(selection);
|
|
244
338
|
if (existing) {
|
|
339
|
+
// If this field has been visited along another recursive path
|
|
340
|
+
// before, the final context should have clientOnly or deferred set
|
|
341
|
+
// to true only if *all* paths have the directive (hence the &&).
|
|
245
342
|
clientOnly = clientOnly && existing.clientOnly;
|
|
246
343
|
deferred = deferred && existing.deferred;
|
|
247
344
|
}
|
|
@@ -265,25 +362,45 @@ var StoreWriter = (function () {
|
|
|
265
362
|
var _a;
|
|
266
363
|
var _this = this;
|
|
267
364
|
if (mergeTree.map.size && !isReference(incoming)) {
|
|
268
|
-
var e_1 =
|
|
269
|
-
|
|
270
|
-
|
|
365
|
+
var e_1 =
|
|
366
|
+
// Items in the same position in different arrays are not
|
|
367
|
+
// necessarily related to each other, so when incoming is an array
|
|
368
|
+
// we process its elements as if there was no existing data.
|
|
369
|
+
(!isArray(incoming) &&
|
|
370
|
+
// Likewise, existing must be either a Reference or a StoreObject
|
|
371
|
+
// in order for its fields to be safe to merge with the fields of
|
|
372
|
+
// the incoming object.
|
|
373
|
+
(isReference(existing) || storeValueIsStoreObject(existing))) ?
|
|
374
|
+
existing
|
|
271
375
|
: void 0;
|
|
376
|
+
// This narrowing is implied by mergeTree.map.size > 0 and
|
|
377
|
+
// !isReference(incoming), though TypeScript understandably cannot
|
|
378
|
+
// hope to infer this type.
|
|
272
379
|
var i_1 = incoming;
|
|
380
|
+
// The options.storage objects provided to read and merge functions
|
|
381
|
+
// are derived from the identity of the parent object plus a
|
|
382
|
+
// sequence of storeFieldName strings/numbers identifying the nested
|
|
383
|
+
// field name path of each field value to be merged.
|
|
273
384
|
if (e_1 && !getStorageArgs) {
|
|
274
385
|
getStorageArgs = [isReference(e_1) ? e_1.__ref : e_1];
|
|
275
386
|
}
|
|
387
|
+
// It's possible that applying merge functions to this subtree will
|
|
388
|
+
// not change the incoming data, so this variable tracks the fields
|
|
389
|
+
// that did change, so we can create a new incoming object when (and
|
|
390
|
+
// only when) at least one incoming field has changed. We use a Map
|
|
391
|
+
// to preserve the type of numeric keys.
|
|
276
392
|
var changedFields_1;
|
|
277
393
|
var getValue_1 = function (from, name) {
|
|
278
|
-
return isArray(from)
|
|
279
|
-
|
|
280
|
-
|
|
394
|
+
return (isArray(from) ?
|
|
395
|
+
typeof name === "number" ?
|
|
396
|
+
from[name]
|
|
281
397
|
: void 0
|
|
282
|
-
: context.store.getFieldValue(from, String(name));
|
|
398
|
+
: context.store.getFieldValue(from, String(name)));
|
|
283
399
|
};
|
|
284
400
|
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
285
401
|
var eVal = getValue_1(e_1, storeFieldName);
|
|
286
402
|
var iVal = getValue_1(i_1, storeFieldName);
|
|
403
|
+
// If we have no incoming data, leave any existing data untouched.
|
|
287
404
|
if (void 0 === iVal)
|
|
288
405
|
return;
|
|
289
406
|
if (getStorageArgs) {
|
|
@@ -299,6 +416,7 @@ var StoreWriter = (function () {
|
|
|
299
416
|
}
|
|
300
417
|
});
|
|
301
418
|
if (changedFields_1) {
|
|
419
|
+
// Shallow clone i so we can add changed fields to it.
|
|
302
420
|
incoming = (isArray(i_1) ? i_1.slice(0) : __assign({}, i_1));
|
|
303
421
|
changedFields_1.forEach(function (value, name) {
|
|
304
422
|
incoming[name] = value;
|
|
@@ -326,13 +444,10 @@ function mergeMergeTrees(left, right) {
|
|
|
326
444
|
return left;
|
|
327
445
|
if (!left || mergeTreeIsEmpty(left))
|
|
328
446
|
return right;
|
|
329
|
-
var info = left.info && right.info
|
|
330
|
-
? __assign(__assign({}, left.info), right.info) : left.info || right.info;
|
|
447
|
+
var info = left.info && right.info ? __assign(__assign({}, left.info), right.info) : left.info || right.info;
|
|
331
448
|
var needToMergeMaps = left.map.size && right.map.size;
|
|
332
|
-
var map = needToMergeMaps
|
|
333
|
-
?
|
|
334
|
-
: left.map.size
|
|
335
|
-
? left.map
|
|
449
|
+
var map = needToMergeMaps ? new Map()
|
|
450
|
+
: left.map.size ? left.map
|
|
336
451
|
: right.map;
|
|
337
452
|
var merged = { info: info, map: map };
|
|
338
453
|
if (needToMergeMaps) {
|
|
@@ -359,6 +474,8 @@ function maybeRecycleChildMergeTree(_a, name) {
|
|
|
359
474
|
}
|
|
360
475
|
}
|
|
361
476
|
var warnings = new Set();
|
|
477
|
+
// Note that this function is unused in production, and thus should be
|
|
478
|
+
// pruned by any well-configured minifier.
|
|
362
479
|
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
363
480
|
var getChild = function (objOrRef) {
|
|
364
481
|
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
@@ -370,10 +487,17 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
370
487
|
var incoming = getChild(incomingObj);
|
|
371
488
|
if (!incoming)
|
|
372
489
|
return;
|
|
490
|
+
// It's always safe to replace a reference, since it refers to data
|
|
491
|
+
// safely stored elsewhere.
|
|
373
492
|
if (isReference(existing))
|
|
374
493
|
return;
|
|
494
|
+
// If the values are structurally equivalent, we do not need to worry
|
|
495
|
+
// about incoming replacing existing.
|
|
375
496
|
if (equal(existing, incoming))
|
|
376
497
|
return;
|
|
498
|
+
// If we're replacing every key of the existing object, then the
|
|
499
|
+
// existing data would be overwritten even if the objects were
|
|
500
|
+
// normalized, so warning would not be helpful here.
|
|
377
501
|
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
378
502
|
return;
|
|
379
503
|
}
|
|
@@ -381,10 +505,13 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
381
505
|
store.getFieldValue(incomingObj, "__typename");
|
|
382
506
|
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
383
507
|
var typeDotName = "".concat(parentType, ".").concat(fieldName);
|
|
508
|
+
// Avoid warning more than once for the same type and field name.
|
|
384
509
|
if (warnings.has(typeDotName))
|
|
385
510
|
return;
|
|
386
511
|
warnings.add(typeDotName);
|
|
387
512
|
var childTypenames = [];
|
|
513
|
+
// Arrays do not have __typename fields, and always need a custom merge
|
|
514
|
+
// function, even if their elements are normalized entities.
|
|
388
515
|
if (!isArray(existing) && !isArray(incoming)) {
|
|
389
516
|
[existing, incoming].forEach(function (child) {
|
|
390
517
|
var typename = store.getFieldValue(child, "__typename");
|
|
@@ -393,8 +520,8 @@ function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
|
393
520
|
}
|
|
394
521
|
});
|
|
395
522
|
}
|
|
396
|
-
globalThis.__DEV__ !== false && invariant.warn(14, fieldName, parentType, childTypenames.length
|
|
397
|
-
|
|
523
|
+
globalThis.__DEV__ !== false && invariant.warn(14, fieldName, parentType, childTypenames.length ?
|
|
524
|
+
"either ensure all objects of type " +
|
|
398
525
|
childTypenames.join(" and ") +
|
|
399
526
|
" have an ID or a custom merge function, or "
|
|
400
527
|
: "", typeDotName, existing, incoming);
|