@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
|
@@ -5,25 +5,33 @@ import { hasOwn, fieldNameFromStoreName, storeValueIsStoreObject, selectionSetMa
|
|
|
5
5
|
import { cacheSlot } from "./reactiveVars.js";
|
|
6
6
|
import { keyArgsFnFromSpecifier, keyFieldsFnFromSpecifier, } from "./key-extractor.js";
|
|
7
7
|
function argsFromFieldSpecifier(spec) {
|
|
8
|
-
return spec.args !== void 0
|
|
9
|
-
? spec.
|
|
10
|
-
|
|
11
|
-
? argumentsObjectFromField(spec.field, spec.variables)
|
|
12
|
-
: null;
|
|
8
|
+
return (spec.args !== void 0 ? spec.args
|
|
9
|
+
: spec.field ? argumentsObjectFromField(spec.field, spec.variables)
|
|
10
|
+
: null);
|
|
13
11
|
}
|
|
14
12
|
var nullKeyFieldsFn = function () { return void 0; };
|
|
15
13
|
var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
|
|
14
|
+
// These merge functions can be selected by specifying merge:true or
|
|
15
|
+
// merge:false in a field policy.
|
|
16
16
|
var mergeTrueFn = function (existing, incoming, _a) {
|
|
17
17
|
var mergeObjects = _a.mergeObjects;
|
|
18
18
|
return mergeObjects(existing, incoming);
|
|
19
19
|
};
|
|
20
20
|
var mergeFalseFn = function (_, incoming) { return incoming; };
|
|
21
|
-
var Policies = (function () {
|
|
21
|
+
var Policies = /** @class */ (function () {
|
|
22
22
|
function Policies(config) {
|
|
23
23
|
this.config = config;
|
|
24
24
|
this.typePolicies = Object.create(null);
|
|
25
25
|
this.toBeAdded = Object.create(null);
|
|
26
|
+
// Map from subtype names to sets of supertype names. Note that this
|
|
27
|
+
// representation inverts the structure of possibleTypes (whose keys are
|
|
28
|
+
// supertypes and whose values are arrays of subtypes) because it tends
|
|
29
|
+
// to be much more efficient to search upwards than downwards.
|
|
26
30
|
this.supertypeMap = new Map();
|
|
31
|
+
// Any fuzzy subtypes specified by possibleTypes will be converted to
|
|
32
|
+
// RegExp objects and recorded here. Every key of this map can also be
|
|
33
|
+
// found in supertypeMap. In many cases this Map will be empty, which
|
|
34
|
+
// means no fuzzy subtype checking will happen in fragmentMatches.
|
|
27
35
|
this.fuzzySubtypes = new Map();
|
|
28
36
|
this.rootIdsByTypename = Object.create(null);
|
|
29
37
|
this.rootTypenamesById = Object.create(null);
|
|
@@ -46,9 +54,15 @@ var Policies = (function () {
|
|
|
46
54
|
var typename = (partialContext &&
|
|
47
55
|
(partialContext.typename || ((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename))) ||
|
|
48
56
|
object.__typename;
|
|
57
|
+
// It should be possible to write root Query fields with writeFragment,
|
|
58
|
+
// using { __typename: "Query", ... } as the data, but it does not make
|
|
59
|
+
// sense to allow the same identification behavior for the Mutation and
|
|
60
|
+
// Subscription types, since application code should never be writing
|
|
61
|
+
// directly to (or reading directly from) those root objects.
|
|
49
62
|
if (typename === this.rootTypenamesById.ROOT_QUERY) {
|
|
50
63
|
return ["ROOT_QUERY"];
|
|
51
64
|
}
|
|
65
|
+
// Default context.storeObject to object if not otherwise provided.
|
|
52
66
|
var storeObject = (partialContext && partialContext.storeObject) || object;
|
|
53
67
|
var context = __assign(__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: (partialContext && partialContext.readField) ||
|
|
54
68
|
function () {
|
|
@@ -78,6 +92,20 @@ var Policies = (function () {
|
|
|
78
92
|
var _this = this;
|
|
79
93
|
Object.keys(typePolicies).forEach(function (typename) {
|
|
80
94
|
var _a = typePolicies[typename], queryType = _a.queryType, mutationType = _a.mutationType, subscriptionType = _a.subscriptionType, incoming = __rest(_a, ["queryType", "mutationType", "subscriptionType"]);
|
|
95
|
+
// Though {query,mutation,subscription}Type configurations are rare,
|
|
96
|
+
// it's important to call setRootTypename as early as possible,
|
|
97
|
+
// since these configurations should apply consistently for the
|
|
98
|
+
// entire lifetime of the cache. Also, since only one __typename can
|
|
99
|
+
// qualify as one of these root types, these three properties cannot
|
|
100
|
+
// be inherited, unlike the rest of the incoming properties. That
|
|
101
|
+
// restriction is convenient, because the purpose of this.toBeAdded
|
|
102
|
+
// is to delay the processing of type/field policies until the first
|
|
103
|
+
// time they're used, allowing policies to be added in any order as
|
|
104
|
+
// long as all relevant policies (including policies for supertypes)
|
|
105
|
+
// have been added by the time a given policy is used for the first
|
|
106
|
+
// time. In other words, since inheritance doesn't matter for these
|
|
107
|
+
// properties, there's also no need to delay their processing using
|
|
108
|
+
// the this.toBeAdded queue.
|
|
81
109
|
if (queryType)
|
|
82
110
|
_this.setRootTypename("Query", typename);
|
|
83
111
|
if (mutationType)
|
|
@@ -98,28 +126,28 @@ var Policies = (function () {
|
|
|
98
126
|
var keyFields = incoming.keyFields, fields = incoming.fields;
|
|
99
127
|
function setMerge(existing, merge) {
|
|
100
128
|
existing.merge =
|
|
101
|
-
typeof merge === "function"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
: existing.merge;
|
|
129
|
+
typeof merge === "function" ? merge
|
|
130
|
+
// Pass merge:true as a shorthand for a merge implementation
|
|
131
|
+
// that returns options.mergeObjects(existing, incoming).
|
|
132
|
+
: merge === true ? mergeTrueFn
|
|
133
|
+
// Pass merge:false to make incoming always replace existing
|
|
134
|
+
// without any warnings about data clobbering.
|
|
135
|
+
: merge === false ? mergeFalseFn
|
|
136
|
+
: existing.merge;
|
|
110
137
|
}
|
|
138
|
+
// Type policies can define merge functions, as an alternative to
|
|
139
|
+
// using field policies to merge child objects.
|
|
111
140
|
setMerge(existing, incoming.merge);
|
|
112
141
|
existing.keyFn =
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
existing.keyFn;
|
|
142
|
+
// Pass false to disable normalization for this typename.
|
|
143
|
+
keyFields === false ? nullKeyFieldsFn
|
|
144
|
+
// Pass an array of strings to use those fields to compute a
|
|
145
|
+
// composite ID for objects of this typename.
|
|
146
|
+
: isArray(keyFields) ? keyFieldsFnFromSpecifier(keyFields)
|
|
147
|
+
// Pass a function to take full control over identification.
|
|
148
|
+
: typeof keyFields === "function" ? keyFields
|
|
149
|
+
// Leave existing.keyFn unchanged if above cases fail.
|
|
150
|
+
: existing.keyFn;
|
|
123
151
|
if (fields) {
|
|
124
152
|
Object.keys(fields).forEach(function (fieldName) {
|
|
125
153
|
var existing = _this.getFieldPolicy(typename, fieldName, true);
|
|
@@ -130,22 +158,27 @@ var Policies = (function () {
|
|
|
130
158
|
else {
|
|
131
159
|
var keyArgs = incoming.keyArgs, read = incoming.read, merge = incoming.merge;
|
|
132
160
|
existing.keyFn =
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
161
|
+
// Pass false to disable argument-based differentiation of
|
|
162
|
+
// field identities.
|
|
163
|
+
keyArgs === false ? simpleKeyArgsFn
|
|
164
|
+
// Pass an array of strings to use named arguments to
|
|
165
|
+
// compute a composite identity for the field.
|
|
166
|
+
: isArray(keyArgs) ? keyArgsFnFromSpecifier(keyArgs)
|
|
167
|
+
// Pass a function to take full control over field identity.
|
|
168
|
+
: typeof keyArgs === "function" ? keyArgs
|
|
169
|
+
// Leave existing.keyFn unchanged if above cases fail.
|
|
170
|
+
: existing.keyFn;
|
|
143
171
|
if (typeof read === "function") {
|
|
144
172
|
existing.read = read;
|
|
145
173
|
}
|
|
146
174
|
setMerge(existing, merge);
|
|
147
175
|
}
|
|
148
176
|
if (existing.read && existing.merge) {
|
|
177
|
+
// If we have both a read and a merge function, assume
|
|
178
|
+
// keyArgs:false, because read and merge together can take
|
|
179
|
+
// responsibility for interpreting arguments in and out. This
|
|
180
|
+
// default assumption can always be overridden by specifying
|
|
181
|
+
// keyArgs explicitly in the FieldPolicy.
|
|
149
182
|
existing.keyFn = existing.keyFn || simpleKeyArgsFn;
|
|
150
183
|
}
|
|
151
184
|
});
|
|
@@ -157,9 +190,13 @@ var Policies = (function () {
|
|
|
157
190
|
var old = this.rootTypenamesById[rootId];
|
|
158
191
|
if (typename !== old) {
|
|
159
192
|
invariant(!old || old === which, 5, which);
|
|
193
|
+
// First, delete any old __typename associated with this rootId from
|
|
194
|
+
// rootIdsByTypename.
|
|
160
195
|
if (old)
|
|
161
196
|
delete this.rootIdsByTypename[old];
|
|
197
|
+
// Now make this the only __typename that maps to this rootId.
|
|
162
198
|
this.rootIdsByTypename[typename] = rootId;
|
|
199
|
+
// Finally, update the __typename associated with this rootId.
|
|
163
200
|
this.rootTypenamesById[rootId] = typename;
|
|
164
201
|
}
|
|
165
202
|
};
|
|
@@ -167,11 +204,15 @@ var Policies = (function () {
|
|
|
167
204
|
var _this = this;
|
|
168
205
|
this.usingPossibleTypes = true;
|
|
169
206
|
Object.keys(possibleTypes).forEach(function (supertype) {
|
|
207
|
+
// Make sure all types have an entry in this.supertypeMap, even if
|
|
208
|
+
// their supertype set is empty, so we can return false immediately
|
|
209
|
+
// from policies.fragmentMatches for unknown supertypes.
|
|
170
210
|
_this.getSupertypeSet(supertype, true);
|
|
171
211
|
possibleTypes[supertype].forEach(function (subtype) {
|
|
172
212
|
_this.getSupertypeSet(subtype, true).add(supertype);
|
|
173
213
|
var match = subtype.match(TypeOrFieldNameRegExp);
|
|
174
214
|
if (!match || match[0] !== subtype) {
|
|
215
|
+
// TODO Don't interpret just any invalid typename as a RegExp.
|
|
175
216
|
_this.fuzzySubtypes.set(subtype, new RegExp(subtype));
|
|
176
217
|
}
|
|
177
218
|
});
|
|
@@ -182,11 +223,43 @@ var Policies = (function () {
|
|
|
182
223
|
if (!hasOwn.call(this.typePolicies, typename)) {
|
|
183
224
|
var policy_1 = (this.typePolicies[typename] = Object.create(null));
|
|
184
225
|
policy_1.fields = Object.create(null);
|
|
226
|
+
// When the TypePolicy for typename is first accessed, instead of
|
|
227
|
+
// starting with an empty policy object, inherit any properties or
|
|
228
|
+
// fields from the type policies of the supertypes of typename.
|
|
229
|
+
//
|
|
230
|
+
// Any properties or fields defined explicitly within the TypePolicy
|
|
231
|
+
// for typename will take precedence, and if there are multiple
|
|
232
|
+
// supertypes, the properties of policies whose types were added
|
|
233
|
+
// later via addPossibleTypes will take precedence over those of
|
|
234
|
+
// earlier supertypes. TODO Perhaps we should warn about these
|
|
235
|
+
// conflicts in development, and recommend defining the property
|
|
236
|
+
// explicitly in the subtype policy?
|
|
237
|
+
//
|
|
238
|
+
// Field policy inheritance is atomic/shallow: you can't inherit a
|
|
239
|
+
// field policy and then override just its read function, since read
|
|
240
|
+
// and merge functions often need to cooperate, so changing only one
|
|
241
|
+
// of them would be a recipe for inconsistency.
|
|
242
|
+
//
|
|
243
|
+
// Once the TypePolicy for typename has been accessed, its properties can
|
|
244
|
+
// still be updated directly using addTypePolicies, but future changes to
|
|
245
|
+
// inherited supertype policies will not be reflected in this subtype
|
|
246
|
+
// policy, because this code runs at most once per typename.
|
|
185
247
|
var supertypes_1 = this.supertypeMap.get(typename);
|
|
186
248
|
if (!supertypes_1 && this.fuzzySubtypes.size) {
|
|
249
|
+
// To make the inheritance logic work for unknown typename strings that
|
|
250
|
+
// may have fuzzy supertypes, we give this typename an empty supertype
|
|
251
|
+
// set and then populate it with any fuzzy supertypes that match.
|
|
187
252
|
supertypes_1 = this.getSupertypeSet(typename, true);
|
|
253
|
+
// This only works for typenames that are directly matched by a fuzzy
|
|
254
|
+
// supertype. What if there is an intermediate chain of supertypes?
|
|
255
|
+
// While possible, that situation can only be solved effectively by
|
|
256
|
+
// specifying the intermediate relationships via possibleTypes, manually
|
|
257
|
+
// and in a non-fuzzy way.
|
|
188
258
|
this.fuzzySubtypes.forEach(function (regExp, fuzzy) {
|
|
189
259
|
if (regExp.test(typename)) {
|
|
260
|
+
// The fuzzy parameter is just the original string version of regExp
|
|
261
|
+
// (not a valid __typename string), but we can look up the
|
|
262
|
+
// associated supertype(s) in this.supertypeMap.
|
|
190
263
|
var fuzzySupertypes = _this.supertypeMap.get(fuzzy);
|
|
191
264
|
if (fuzzySupertypes) {
|
|
192
265
|
fuzzySupertypes.forEach(function (supertype) {
|
|
@@ -206,6 +279,8 @@ var Policies = (function () {
|
|
|
206
279
|
}
|
|
207
280
|
var inbox = this.toBeAdded[typename];
|
|
208
281
|
if (inbox && inbox.length) {
|
|
282
|
+
// Merge the pending policies into this.typePolicies, in the order they
|
|
283
|
+
// were originally passed to addTypePolicy.
|
|
209
284
|
inbox.splice(0).forEach(function (policy) {
|
|
210
285
|
_this.updateTypePolicy(typename, policy);
|
|
211
286
|
});
|
|
@@ -230,9 +305,12 @@ var Policies = (function () {
|
|
|
230
305
|
var _this = this;
|
|
231
306
|
if (!fragment.typeCondition)
|
|
232
307
|
return true;
|
|
308
|
+
// If the fragment has a type condition but the object we're matching
|
|
309
|
+
// against does not have a __typename, the fragment cannot match.
|
|
233
310
|
if (!typename)
|
|
234
311
|
return false;
|
|
235
312
|
var supertype = fragment.typeCondition.name.value;
|
|
313
|
+
// Common case: fragment type condition and __typename are the same.
|
|
236
314
|
if (typename === supertype)
|
|
237
315
|
return true;
|
|
238
316
|
if (this.usingPossibleTypes && this.supertypeMap.has(supertype)) {
|
|
@@ -246,8 +324,16 @@ var Policies = (function () {
|
|
|
246
324
|
workQueue_1.push(supertypeSet);
|
|
247
325
|
}
|
|
248
326
|
};
|
|
327
|
+
// We need to check fuzzy subtypes only if we encountered fuzzy
|
|
328
|
+
// subtype strings in addPossibleTypes, and only while writing to
|
|
329
|
+
// the cache, since that's when selectionSetMatchesResult gives a
|
|
330
|
+
// strong signal of fragment matching. The StoreReader class calls
|
|
331
|
+
// policies.fragmentMatches without passing a result object, so
|
|
332
|
+
// needToCheckFuzzySubtypes is always false while reading.
|
|
249
333
|
var needToCheckFuzzySubtypes = !!(result && this.fuzzySubtypes.size);
|
|
250
334
|
var checkingFuzzySubtypes = false;
|
|
335
|
+
// It's important to keep evaluating workQueue.length each time through
|
|
336
|
+
// the loop, because the queue can grow while we're iterating over it.
|
|
251
337
|
for (var i = 0; i < workQueue_1.length; ++i) {
|
|
252
338
|
var supertypeSet = workQueue_1[i];
|
|
253
339
|
if (supertypeSet.has(supertype)) {
|
|
@@ -255,16 +341,33 @@ var Policies = (function () {
|
|
|
255
341
|
if (checkingFuzzySubtypes) {
|
|
256
342
|
globalThis.__DEV__ !== false && invariant.warn(6, typename, supertype);
|
|
257
343
|
}
|
|
344
|
+
// Record positive results for faster future lookup.
|
|
345
|
+
// Unfortunately, we cannot safely cache negative results,
|
|
346
|
+
// because new possibleTypes data could always be added to the
|
|
347
|
+
// Policies class.
|
|
258
348
|
typenameSupertypeSet.add(supertype);
|
|
259
349
|
}
|
|
260
350
|
return true;
|
|
261
351
|
}
|
|
262
352
|
supertypeSet.forEach(maybeEnqueue_1);
|
|
263
353
|
if (needToCheckFuzzySubtypes &&
|
|
354
|
+
// Start checking fuzzy subtypes only after exhausting all
|
|
355
|
+
// non-fuzzy subtypes (after the final iteration of the loop).
|
|
264
356
|
i === workQueue_1.length - 1 &&
|
|
357
|
+
// We could wait to compare fragment.selectionSet to result
|
|
358
|
+
// after we verify the supertype, but this check is often less
|
|
359
|
+
// expensive than that search, and we will have to do the
|
|
360
|
+
// comparison anyway whenever we find a potential match.
|
|
265
361
|
selectionSetMatchesResult(fragment.selectionSet, result, variables)) {
|
|
362
|
+
// We don't always need to check fuzzy subtypes (if no result
|
|
363
|
+
// was provided, or !this.fuzzySubtypes.size), but, when we do,
|
|
364
|
+
// we only want to check them once.
|
|
266
365
|
needToCheckFuzzySubtypes = false;
|
|
267
366
|
checkingFuzzySubtypes = true;
|
|
367
|
+
// If we find any fuzzy subtypes that match typename, extend the
|
|
368
|
+
// workQueue to search through the supertypes of those fuzzy
|
|
369
|
+
// subtypes. Otherwise the for-loop will terminate and we'll
|
|
370
|
+
// return false below.
|
|
268
371
|
this.fuzzySubtypes.forEach(function (regExp, fuzzyString) {
|
|
269
372
|
var match = typename.match(regExp);
|
|
270
373
|
if (match && match[0] === typename) {
|
|
@@ -299,21 +402,28 @@ var Policies = (function () {
|
|
|
299
402
|
keyFn = keyArgsFnFromSpecifier(specifierOrString);
|
|
300
403
|
}
|
|
301
404
|
else {
|
|
405
|
+
// If the custom keyFn returns a falsy value, fall back to
|
|
406
|
+
// fieldName instead.
|
|
302
407
|
storeFieldName = specifierOrString || fieldName;
|
|
303
408
|
break;
|
|
304
409
|
}
|
|
305
410
|
}
|
|
306
411
|
}
|
|
307
412
|
if (storeFieldName === void 0) {
|
|
308
|
-
storeFieldName =
|
|
309
|
-
|
|
310
|
-
|
|
413
|
+
storeFieldName =
|
|
414
|
+
fieldSpec.field ?
|
|
415
|
+
storeKeyNameFromField(fieldSpec.field, fieldSpec.variables)
|
|
416
|
+
: getStoreKeyName(fieldName, argsFromFieldSpecifier(fieldSpec));
|
|
311
417
|
}
|
|
418
|
+
// Returning false from a keyArgs function is like configuring
|
|
419
|
+
// keyArgs: false, but more dynamic.
|
|
312
420
|
if (storeFieldName === false) {
|
|
313
421
|
return fieldName;
|
|
314
422
|
}
|
|
315
|
-
|
|
316
|
-
|
|
423
|
+
// Make sure custom field names start with the actual field.name.value
|
|
424
|
+
// of the field, so we can always figure out which properties of a
|
|
425
|
+
// StoreObject correspond to which original field names.
|
|
426
|
+
return fieldName === fieldNameFromStoreName(storeFieldName) ? storeFieldName
|
|
317
427
|
: fieldName + ":" + storeFieldName;
|
|
318
428
|
};
|
|
319
429
|
Policies.prototype.readField = function (options, context) {
|
|
@@ -334,9 +444,10 @@ var Policies = (function () {
|
|
|
334
444
|
var policy = this.getFieldPolicy(options.typename, fieldName, false);
|
|
335
445
|
var read = policy && policy.read;
|
|
336
446
|
if (read) {
|
|
337
|
-
var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference)
|
|
338
|
-
|
|
447
|
+
var readOptions = makeFieldFunctionOptions(this, objectOrReference, options, context, context.store.getStorage(isReference(objectOrReference) ?
|
|
448
|
+
objectOrReference.__ref
|
|
339
449
|
: objectOrReference, storeFieldName));
|
|
450
|
+
// Call read(existing, readOptions) with cacheSlot holding this.cache.
|
|
340
451
|
return cacheSlot.withValue(this.cache, read, [
|
|
341
452
|
existing,
|
|
342
453
|
readOptions,
|
|
@@ -360,15 +471,35 @@ var Policies = (function () {
|
|
|
360
471
|
Policies.prototype.runMergeFunction = function (existing, incoming, _a, context, storage) {
|
|
361
472
|
var field = _a.field, typename = _a.typename, merge = _a.merge;
|
|
362
473
|
if (merge === mergeTrueFn) {
|
|
474
|
+
// Instead of going to the trouble of creating a full
|
|
475
|
+
// FieldFunctionOptions object and calling mergeTrueFn, we can
|
|
476
|
+
// simply call mergeObjects, as mergeTrueFn would.
|
|
363
477
|
return makeMergeObjectsFunction(context.store)(existing, incoming);
|
|
364
478
|
}
|
|
365
479
|
if (merge === mergeFalseFn) {
|
|
480
|
+
// Likewise for mergeFalseFn, whose implementation is even simpler.
|
|
366
481
|
return incoming;
|
|
367
482
|
}
|
|
483
|
+
// If cache.writeQuery or cache.writeFragment was called with
|
|
484
|
+
// options.overwrite set to true, we still call merge functions, but
|
|
485
|
+
// the existing data is always undefined, so the merge function will
|
|
486
|
+
// not attempt to combine the incoming data with the existing data.
|
|
368
487
|
if (context.overwrite) {
|
|
369
488
|
existing = void 0;
|
|
370
489
|
}
|
|
371
|
-
return merge(existing, incoming, makeFieldFunctionOptions(this,
|
|
490
|
+
return merge(existing, incoming, makeFieldFunctionOptions(this,
|
|
491
|
+
// Unlike options.readField for read functions, we do not fall
|
|
492
|
+
// back to the current object if no foreignObjOrRef is provided,
|
|
493
|
+
// because it's not clear what the current object should be for
|
|
494
|
+
// merge functions: the (possibly undefined) existing object, or
|
|
495
|
+
// the incoming object? If you think your merge function needs
|
|
496
|
+
// to read sibling fields in order to produce a new value for
|
|
497
|
+
// the current field, you might want to rethink your strategy,
|
|
498
|
+
// because that's a recipe for making merge behavior sensitive
|
|
499
|
+
// to the order in which fields are written into the cache.
|
|
500
|
+
// However, readField(name, ref) is useful for merge functions
|
|
501
|
+
// that need to deduplicate child objects and references.
|
|
502
|
+
void 0, {
|
|
372
503
|
typename: typename,
|
|
373
504
|
fieldName: field.name.value,
|
|
374
505
|
field: field,
|
|
@@ -406,11 +537,16 @@ export function normalizeReadFieldOptions(readFieldArgs, objectOrReference, vari
|
|
|
406
537
|
if (typeof fieldNameOrOptions === "string") {
|
|
407
538
|
options = {
|
|
408
539
|
fieldName: fieldNameOrOptions,
|
|
540
|
+
// Default to objectOrReference only when no second argument was
|
|
541
|
+
// passed for the from parameter, not when undefined is explicitly
|
|
542
|
+
// passed as the second argument.
|
|
409
543
|
from: argc > 1 ? from : objectOrReference,
|
|
410
544
|
};
|
|
411
545
|
}
|
|
412
546
|
else {
|
|
413
547
|
options = __assign({}, fieldNameOrOptions);
|
|
548
|
+
// Default to objectOrReference only when fieldNameOrOptions.from is
|
|
549
|
+
// actually omitted, rather than just undefined.
|
|
414
550
|
if (!hasOwn.call(options, "from")) {
|
|
415
551
|
options.from = objectOrReference;
|
|
416
552
|
}
|
|
@@ -428,6 +564,10 @@ function makeMergeObjectsFunction(store) {
|
|
|
428
564
|
if (isArray(existing) || isArray(incoming)) {
|
|
429
565
|
throw newInvariantError(8);
|
|
430
566
|
}
|
|
567
|
+
// These dynamic checks are necessary because the parameters of a
|
|
568
|
+
// custom merge function can easily have the any type, so the type
|
|
569
|
+
// system cannot always enforce the StoreObject | Reference parameter
|
|
570
|
+
// types of options.mergeObjects.
|
|
431
571
|
if (isNonNullObject(existing) && isNonNullObject(incoming)) {
|
|
432
572
|
var eType = store.getFieldValue(existing, "__typename");
|
|
433
573
|
var iType = store.getFieldValue(incoming, "__typename");
|
|
@@ -436,10 +576,17 @@ function makeMergeObjectsFunction(store) {
|
|
|
436
576
|
return incoming;
|
|
437
577
|
}
|
|
438
578
|
if (isReference(existing) && storeValueIsStoreObject(incoming)) {
|
|
579
|
+
// Update the normalized EntityStore for the entity identified by
|
|
580
|
+
// existing.__ref, preferring/overwriting any fields contributed by the
|
|
581
|
+
// newer incoming StoreObject.
|
|
439
582
|
store.merge(existing.__ref, incoming);
|
|
440
583
|
return existing;
|
|
441
584
|
}
|
|
442
585
|
if (storeValueIsStoreObject(existing) && isReference(incoming)) {
|
|
586
|
+
// Update the normalized EntityStore for the entity identified by
|
|
587
|
+
// incoming.__ref, taking fields from the older existing object only if
|
|
588
|
+
// those fields are not already present in the newer StoreObject
|
|
589
|
+
// identified by incoming.__ref.
|
|
443
590
|
store.merge(existing, incoming.__ref);
|
|
444
591
|
return incoming;
|
|
445
592
|
}
|