@apollo/client 3.4.17 → 3.5.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/{apollo-client.cjs.js → apollo-client.cjs} +1219 -1280
- package/apollo-client.cjs.map +1 -0
- package/apollo-client.min.cjs +1 -0
- package/cache/{cache.cjs.js → cache.cjs} +757 -601
- package/cache/cache.cjs.map +1 -0
- package/cache/core/cache.d.ts +6 -4
- package/cache/core/cache.d.ts.map +1 -1
- package/cache/core/cache.js +28 -1
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +12 -10
- package/cache/core/types/Cache.d.ts.map +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +4 -0
- package/cache/core/types/DataProxy.d.ts.map +1 -1
- package/cache/core/types/DataProxy.js.map +1 -1
- package/cache/core/types/common.d.ts +8 -5
- package/cache/core/types/common.d.ts.map +1 -1
- package/cache/core/types/common.js +6 -11
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/helpers.js +1 -1
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.d.ts +4 -4
- package/cache/inmemory/inMemoryCache.d.ts.map +1 -1
- package/cache/inmemory/inMemoryCache.js +12 -3
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.d.ts +9 -0
- package/cache/inmemory/key-extractor.d.ts.map +1 -0
- package/cache/inmemory/key-extractor.js +118 -0
- package/cache/inmemory/key-extractor.js.map +1 -0
- package/cache/inmemory/policies.d.ts +7 -3
- package/cache/inmemory/policies.d.ts.map +1 -1
- package/cache/inmemory/policies.js +47 -118
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +2 -2
- package/cache/inmemory/readFromStore.d.ts.map +1 -1
- package/cache/inmemory/readFromStore.js +54 -42
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.d.ts +8 -3
- package/cache/inmemory/writeToStore.d.ts.map +1 -1
- package/cache/inmemory/writeToStore.js +166 -95
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/cache/package.json +2 -1
- package/core/ApolloClient.d.ts +0 -1
- package/core/ApolloClient.d.ts.map +1 -1
- package/core/ApolloClient.js +3 -3
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.js +1 -1
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +2 -2
- package/core/ObservableQuery.d.ts.map +1 -1
- package/core/ObservableQuery.js +19 -14
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +2 -2
- package/core/QueryInfo.d.ts.map +1 -1
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +0 -1
- package/core/QueryManager.d.ts.map +1 -1
- package/core/QueryManager.js +10 -10
- package/core/QueryManager.js.map +1 -1
- package/core/{core.cjs.js → core.cjs} +38 -34
- package/core/core.cjs.map +1 -0
- package/core/package.json +2 -1
- package/errors/{errors.cjs.js → errors.cjs} +3 -3
- package/errors/errors.cjs.map +1 -0
- package/errors/index.d.ts +3 -1
- package/errors/index.d.ts.map +1 -1
- package/errors/index.js +2 -2
- package/errors/index.js.map +1 -1
- package/errors/package.json +2 -1
- package/invariantErrorCodes.js +84 -104
- package/link/batch/{batch.cjs.js → batch.cjs} +2 -2
- package/link/batch/batch.cjs.map +1 -0
- package/link/batch/batchLink.d.ts +0 -1
- package/link/batch/batchLink.d.ts.map +1 -1
- package/link/batch/batching.d.ts +0 -1
- package/link/batch/batching.d.ts.map +1 -1
- package/link/batch/batching.js +1 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch/package.json +2 -1
- package/link/batch-http/{batch-http.cjs.js → batch-http.cjs} +3 -3
- package/link/batch-http/batch-http.cjs.map +1 -0
- package/link/batch-http/batchHttpLink.d.ts +0 -1
- package/link/batch-http/batchHttpLink.d.ts.map +1 -1
- package/link/batch-http/batchHttpLink.js +3 -3
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/batch-http/package.json +2 -1
- package/link/context/{context.cjs.js → context.cjs} +1 -1
- package/link/context/context.cjs.map +1 -0
- package/link/context/index.js.map +1 -1
- package/link/context/package.json +2 -1
- package/link/core/ApolloLink.d.ts +2 -3
- package/link/core/ApolloLink.d.ts.map +1 -1
- package/link/core/ApolloLink.js +1 -1
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/{core.cjs.js → core.cjs} +2 -2
- package/link/core/core.cjs.map +1 -0
- package/link/core/package.json +2 -1
- package/link/core/types.d.ts +4 -7
- package/link/core/types.d.ts.map +1 -1
- package/link/core/types.js.map +1 -1
- package/link/error/{error.cjs.js → error.cjs} +2 -2
- package/link/error/error.cjs.map +1 -0
- package/link/error/index.d.ts +5 -7
- package/link/error/index.d.ts.map +1 -1
- package/link/error/index.js +1 -1
- package/link/error/index.js.map +1 -1
- package/link/error/package.json +2 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.d.ts.map +1 -1
- package/link/http/createHttpLink.js +3 -3
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/{http.cjs.js → http.cjs} +28 -15
- package/link/http/http.cjs.map +1 -0
- package/link/http/index.d.ts +1 -1
- package/link/http/index.d.ts.map +1 -1
- package/link/http/index.js +1 -1
- package/link/http/index.js.map +1 -1
- package/link/http/package.json +2 -1
- package/link/http/parseAndCheckHttpResponse.js +3 -3
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/rewriteURIForGET.js +1 -1
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +11 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
- package/link/http/selectHttpOptionsAndBody.js +20 -7
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.d.ts.map +1 -1
- package/link/persisted-queries/index.js +3 -3
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/package.json +2 -1
- package/link/persisted-queries/{persisted-queries.cjs.js → persisted-queries.cjs} +3 -3
- package/link/persisted-queries/persisted-queries.cjs.map +1 -0
- package/link/retry/package.json +2 -1
- package/link/retry/{retry.cjs.js → retry.cjs} +1 -1
- package/link/retry/retry.cjs.map +1 -0
- package/link/retry/retryLink.d.ts +0 -1
- package/link/retry/retryLink.d.ts.map +1 -1
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +0 -1
- package/link/schema/index.d.ts.map +1 -1
- package/link/schema/index.js +8 -1
- package/link/schema/index.js.map +1 -1
- package/link/schema/package.json +2 -1
- package/link/schema/{schema.cjs.js → schema.cjs} +9 -2
- package/link/schema/schema.cjs.map +1 -0
- package/link/utils/fromError.d.ts +0 -1
- package/link/utils/fromError.d.ts.map +1 -1
- package/link/utils/fromPromise.d.ts +0 -1
- package/link/utils/fromPromise.d.ts.map +1 -1
- package/link/utils/package.json +2 -1
- package/link/utils/toPromise.d.ts +0 -1
- package/link/utils/toPromise.d.ts.map +1 -1
- package/link/utils/{utils.cjs.js → utils.cjs} +2 -2
- package/link/utils/utils.cjs.map +1 -0
- package/link/utils/validateOperation.js +1 -1
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +0 -1
- package/link/ws/index.d.ts.map +1 -1
- package/link/ws/package.json +2 -1
- package/link/ws/{ws.cjs.js → ws.cjs} +1 -1
- package/link/ws/ws.cjs.map +1 -0
- package/{main.cjs.js → main.cjs} +5 -5
- package/main.cjs.map +1 -0
- package/package.json +20 -19
- package/react/components/Query.js.map +1 -1
- package/react/components/{components.cjs.js → components.cjs} +4 -4
- package/react/components/components.cjs.map +1 -0
- package/react/components/package.json +2 -1
- package/react/context/ApolloConsumer.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/context/{context.cjs.js → context.cjs} +6 -6
- package/react/context/context.cjs.map +1 -0
- package/react/context/index.d.ts +3 -3
- package/react/context/index.d.ts.map +1 -1
- package/react/context/index.js +3 -3
- package/react/context/index.js.map +1 -1
- package/react/context/package.json +2 -1
- package/react/hoc/hoc-utils.js +1 -1
- package/react/hoc/{hoc.cjs.js → hoc.cjs} +12 -12
- package/react/hoc/hoc.cjs.map +1 -0
- package/react/hoc/mutation-hoc.js +2 -2
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/package.json +2 -1
- package/react/hoc/query-hoc.js +1 -1
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +1 -1
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +2 -2
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +502 -0
- package/react/hooks/hooks.cjs.map +1 -0
- package/react/hooks/package.json +2 -1
- package/react/hooks/useApolloClient.d.ts +1 -1
- package/react/hooks/useApolloClient.d.ts.map +1 -1
- package/react/hooks/useApolloClient.js +7 -5
- package/react/hooks/useApolloClient.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts.map +1 -1
- package/react/hooks/useLazyQuery.js +56 -2
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +89 -21
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +2 -3
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +224 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -7
- package/react/hooks/useSubscription.d.ts.map +1 -1
- package/react/hooks/useSubscription.js +89 -32
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/package.json +2 -1
- package/react/parser/index.d.ts +1 -0
- package/react/parser/index.d.ts.map +1 -1
- package/react/parser/index.js +16 -9
- package/react/parser/index.js.map +1 -1
- package/react/parser/package.json +2 -1
- package/react/parser/{parser.cjs.js → parser.cjs} +18 -10
- package/react/parser/parser.cjs.map +1 -0
- package/react/{react.cjs.js → react.cjs} +3 -3
- package/react/react.cjs.map +1 -0
- package/react/ssr/RenderPromises.d.ts +7 -3
- package/react/ssr/RenderPromises.d.ts.map +1 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/package.json +2 -1
- package/react/ssr/{ssr.cjs.js → ssr.cjs} +4 -4
- package/react/ssr/ssr.cjs.map +1 -0
- package/react/types/types.d.ts +7 -18
- package/react/types/types.d.ts.map +1 -1
- package/react/types/types.js.map +1 -1
- package/testing/{testing.cjs.js → core/core.cjs} +10 -104
- package/testing/core/core.cjs.map +1 -0
- package/{utilities/testing → testing/core}/index.d.ts +0 -1
- package/testing/core/index.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/index.js +0 -1
- package/testing/core/index.js.map +1 -0
- package/{utilities/testing → testing/core}/itAsync.d.ts +0 -0
- package/testing/core/itAsync.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/itAsync.js +0 -0
- package/testing/core/itAsync.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockClient.d.ts +0 -0
- package/testing/core/mocking/mockClient.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockClient.js +0 -0
- package/testing/core/mocking/mockClient.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockFetch.d.ts +0 -0
- package/testing/core/mocking/mockFetch.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockFetch.js +1 -1
- package/testing/core/mocking/mockFetch.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockLink.d.ts +0 -1
- package/testing/core/mocking/mockLink.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockLink.js +5 -5
- package/testing/core/mocking/mockLink.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockQueryManager.d.ts +1 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockQueryManager.js +1 -1
- package/testing/core/mocking/mockQueryManager.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.d.ts +1 -4
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockSubscriptionLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockWatchQuery.d.ts +1 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/mocking/mockWatchQuery.js +0 -0
- package/testing/core/mocking/mockWatchQuery.js.map +1 -0
- package/{utilities/testing → testing/core}/observableToPromise.d.ts +2 -3
- package/testing/core/observableToPromise.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/observableToPromise.js +1 -1
- package/testing/core/observableToPromise.js.map +1 -0
- package/testing/core/package.json +8 -0
- package/testing/core/subscribeAndCount.d.ts +4 -0
- package/testing/core/subscribeAndCount.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/subscribeAndCount.js +1 -1
- package/testing/core/subscribeAndCount.js.map +1 -0
- package/{utilities/testing → testing/core}/withConsoleSpy.d.ts +0 -0
- package/testing/core/withConsoleSpy.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/withConsoleSpy.js +0 -0
- package/testing/core/withConsoleSpy.js.map +1 -0
- package/{utilities/testing → testing/core}/wrap.d.ts +0 -0
- package/testing/core/wrap.d.ts.map +1 -0
- package/{utilities/testing → testing/core}/wrap.js +0 -0
- package/testing/core/wrap.js.map +1 -0
- package/testing/index.d.ts +2 -1
- package/testing/index.d.ts.map +1 -1
- package/testing/index.js +2 -1
- package/testing/index.js.map +1 -1
- package/testing/package.json +2 -1
- package/{utilities/testing/mocking → testing/react}/MockedProvider.d.ts +5 -5
- package/testing/react/MockedProvider.d.ts.map +1 -0
- package/{utilities/testing/mocking → testing/react}/MockedProvider.js +4 -4
- package/testing/react/MockedProvider.js.map +1 -0
- package/testing/testing.cjs +58 -0
- package/testing/testing.cjs.map +1 -0
- package/utilities/common/errorHandling.d.ts +1 -1
- package/utilities/common/errorHandling.d.ts.map +1 -1
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/makeUniqueId.js +1 -1
- package/utilities/common/makeUniqueId.js.map +1 -1
- package/utilities/common/mergeDeep.d.ts.map +1 -1
- package/utilities/common/mergeDeep.js +6 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/globals/fix-graphql.js +1 -1
- package/utilities/globals/global.d.ts.map +1 -1
- package/utilities/globals/global.js +1 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/{globals.cjs.js → globals.cjs} +3 -3
- package/utilities/globals/globals.cjs.map +1 -0
- package/utilities/globals/index.js +1 -1
- package/utilities/globals/package.json +2 -1
- package/utilities/graphql/directives.js +5 -5
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts.map +1 -1
- package/utilities/graphql/fragments.js +4 -4
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.js +8 -8
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/storeUtils.js +6 -6
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.d.ts.map +1 -1
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/observables/Concast.d.ts +0 -1
- package/utilities/observables/Concast.d.ts.map +1 -1
- package/utilities/observables/asyncMap.d.ts +0 -1
- package/utilities/observables/asyncMap.d.ts.map +1 -1
- package/utilities/observables/subclassing.d.ts +0 -1
- package/utilities/observables/subclassing.d.ts.map +1 -1
- package/utilities/package.json +2 -1
- package/utilities/{utilities.cjs.js → utilities.cjs} +31 -26
- package/utilities/utilities.cjs.map +1 -0
- package/version.js +1 -1
- package/apollo-client.cjs.js.map +0 -1
- package/apollo-client.cjs.min.js +0 -1
- package/cache/cache.cjs.js.map +0 -1
- package/core/core.cjs.js.map +0 -1
- package/errors/errors.cjs.js.map +0 -1
- package/link/batch/batch.cjs.js.map +0 -1
- package/link/batch-http/batch-http.cjs.js.map +0 -1
- package/link/context/context.cjs.js.map +0 -1
- package/link/core/core.cjs.js.map +0 -1
- package/link/error/error.cjs.js.map +0 -1
- package/link/http/http.cjs.js.map +0 -1
- package/link/persisted-queries/persisted-queries.cjs.js.map +0 -1
- package/link/retry/retry.cjs.js.map +0 -1
- package/link/schema/schema.cjs.js.map +0 -1
- package/link/utils/utils.cjs.js.map +0 -1
- package/link/ws/ws.cjs.js.map +0 -1
- package/main.cjs.js.map +0 -1
- package/react/components/components.cjs.js.map +0 -1
- package/react/context/context.cjs.js.map +0 -1
- package/react/data/MutationData.d.ts +0 -29
- package/react/data/MutationData.d.ts.map +0 -1
- package/react/data/MutationData.js +0 -115
- package/react/data/MutationData.js.map +0 -1
- package/react/data/OperationData.d.ts +0 -24
- package/react/data/OperationData.d.ts.map +0 -1
- package/react/data/OperationData.js +0 -53
- package/react/data/OperationData.js.map +0 -1
- package/react/data/QueryData.d.ts +0 -44
- package/react/data/QueryData.d.ts.map +0 -1
- package/react/data/QueryData.js +0 -298
- package/react/data/QueryData.js.map +0 -1
- package/react/data/SubscriptionData.d.ts +0 -28
- package/react/data/SubscriptionData.d.ts.map +0 -1
- package/react/data/SubscriptionData.js +0 -122
- package/react/data/SubscriptionData.js.map +0 -1
- package/react/data/data.cjs.js +0 -581
- package/react/data/data.cjs.js.map +0 -1
- package/react/data/index.d.ts +0 -6
- package/react/data/index.d.ts.map +0 -1
- package/react/data/index.js +0 -6
- package/react/data/index.js.map +0 -1
- package/react/data/package.json +0 -7
- package/react/hoc/hoc.cjs.js.map +0 -1
- package/react/hooks/hooks.cjs.js +0 -195
- package/react/hooks/hooks.cjs.js.map +0 -1
- package/react/hooks/utils/useAfterFastRefresh.d.ts +0 -3
- package/react/hooks/utils/useAfterFastRefresh.d.ts.map +0 -1
- package/react/hooks/utils/useAfterFastRefresh.js +0 -19
- package/react/hooks/utils/useAfterFastRefresh.js.map +0 -1
- package/react/hooks/utils/useBaseQuery.d.ts +0 -7
- package/react/hooks/utils/useBaseQuery.d.ts.map +0 -1
- package/react/hooks/utils/useBaseQuery.js +0 -55
- package/react/hooks/utils/useBaseQuery.js.map +0 -1
- package/react/hooks/utils/useDeepMemo.d.ts +0 -2
- package/react/hooks/utils/useDeepMemo.d.ts.map +0 -1
- package/react/hooks/utils/useDeepMemo.js +0 -10
- package/react/hooks/utils/useDeepMemo.js.map +0 -1
- package/react/parser/parser.cjs.js.map +0 -1
- package/react/react.cjs.js.map +0 -1
- package/react/ssr/ssr.cjs.js.map +0 -1
- package/testing/testing.cjs.js.map +0 -1
- package/utilities/globals/globals.cjs.js.map +0 -1
- package/utilities/testing/index.d.ts.map +0 -1
- package/utilities/testing/index.js.map +0 -1
- package/utilities/testing/itAsync.d.ts.map +0 -1
- package/utilities/testing/itAsync.js.map +0 -1
- package/utilities/testing/mocking/MockedProvider.d.ts.map +0 -1
- package/utilities/testing/mocking/MockedProvider.js.map +0 -1
- package/utilities/testing/mocking/mockClient.d.ts.map +0 -1
- package/utilities/testing/mocking/mockClient.js.map +0 -1
- package/utilities/testing/mocking/mockFetch.d.ts.map +0 -1
- package/utilities/testing/mocking/mockFetch.js.map +0 -1
- package/utilities/testing/mocking/mockLink.d.ts.map +0 -1
- package/utilities/testing/mocking/mockLink.js.map +0 -1
- package/utilities/testing/mocking/mockQueryManager.d.ts.map +0 -1
- package/utilities/testing/mocking/mockQueryManager.js.map +0 -1
- package/utilities/testing/mocking/mockSubscriptionLink.d.ts.map +0 -1
- package/utilities/testing/mocking/mockSubscriptionLink.js.map +0 -1
- package/utilities/testing/mocking/mockWatchQuery.d.ts.map +0 -1
- package/utilities/testing/mocking/mockWatchQuery.js.map +0 -1
- package/utilities/testing/observableToPromise.d.ts.map +0 -1
- package/utilities/testing/observableToPromise.js.map +0 -1
- package/utilities/testing/subscribeAndCount.d.ts +0 -5
- package/utilities/testing/subscribeAndCount.d.ts.map +0 -1
- package/utilities/testing/subscribeAndCount.js.map +0 -1
- package/utilities/testing/withConsoleSpy.d.ts.map +0 -1
- package/utilities/testing/withConsoleSpy.js.map +0 -1
- package/utilities/testing/wrap.d.ts.map +0 -1
- package/utilities/testing/wrap.js.map +0 -1
- package/utilities/utilities.cjs.js.map +0 -1
|
@@ -15,9 +15,12 @@ var ApolloCache = (function () {
|
|
|
15
15
|
this.getFragmentDoc = optimism.wrap(utilities.getFragmentQueryDocument);
|
|
16
16
|
}
|
|
17
17
|
ApolloCache.prototype.batch = function (options) {
|
|
18
|
+
var _this = this;
|
|
18
19
|
var optimisticId = typeof options.optimistic === "string" ? options.optimistic :
|
|
19
20
|
options.optimistic === false ? null : void 0;
|
|
20
|
-
|
|
21
|
+
var updateResult;
|
|
22
|
+
this.performTransaction(function () { return updateResult = options.update(_this); }, optimisticId);
|
|
23
|
+
return updateResult;
|
|
21
24
|
};
|
|
22
25
|
ApolloCache.prototype.recordOptimisticTransaction = function (transaction, optimisticId) {
|
|
23
26
|
this.performTransaction(transaction, optimisticId);
|
|
@@ -60,6 +63,30 @@ var ApolloCache = (function () {
|
|
|
60
63
|
result: data,
|
|
61
64
|
}));
|
|
62
65
|
};
|
|
66
|
+
ApolloCache.prototype.updateQuery = function (options, update) {
|
|
67
|
+
return this.batch({
|
|
68
|
+
update: function (cache) {
|
|
69
|
+
var value = cache.readQuery(options);
|
|
70
|
+
var data = update(value);
|
|
71
|
+
if (data === void 0 || data === null)
|
|
72
|
+
return value;
|
|
73
|
+
cache.writeQuery(tslib.__assign(tslib.__assign({}, options), { data: data }));
|
|
74
|
+
return data;
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
ApolloCache.prototype.updateFragment = function (options, update) {
|
|
79
|
+
return this.batch({
|
|
80
|
+
update: function (cache) {
|
|
81
|
+
var value = cache.readFragment(options);
|
|
82
|
+
var data = update(value);
|
|
83
|
+
if (data === void 0 || data === null)
|
|
84
|
+
return value;
|
|
85
|
+
cache.writeFragment(tslib.__assign(tslib.__assign({}, options), { data: data }));
|
|
86
|
+
return data;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
};
|
|
63
90
|
return ApolloCache;
|
|
64
91
|
}());
|
|
65
92
|
|
|
@@ -67,19 +94,15 @@ exports.Cache = void 0;
|
|
|
67
94
|
(function (Cache) {
|
|
68
95
|
})(exports.Cache || (exports.Cache = {}));
|
|
69
96
|
|
|
70
|
-
var MissingFieldError = (function (
|
|
71
|
-
tslib.__extends(MissingFieldError, _super);
|
|
97
|
+
var MissingFieldError = (function () {
|
|
72
98
|
function MissingFieldError(message, path, query, variables) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
_this.variables = variables;
|
|
78
|
-
_this.__proto__ = MissingFieldError.prototype;
|
|
79
|
-
return _this;
|
|
99
|
+
this.message = message;
|
|
100
|
+
this.path = path;
|
|
101
|
+
this.query = query;
|
|
102
|
+
this.variables = variables;
|
|
80
103
|
}
|
|
81
104
|
return MissingFieldError;
|
|
82
|
-
}(
|
|
105
|
+
}());
|
|
83
106
|
|
|
84
107
|
var hasOwn = Object.prototype.hasOwnProperty;
|
|
85
108
|
function defaultDataIdFromObject(_a, context) {
|
|
@@ -94,7 +117,7 @@ function defaultDataIdFromObject(_a, context) {
|
|
|
94
117
|
if (id === void 0)
|
|
95
118
|
id = _id;
|
|
96
119
|
if (id !== void 0) {
|
|
97
|
-
return __typename
|
|
120
|
+
return "".concat(__typename, ":").concat((typeof id === "number" ||
|
|
98
121
|
typeof id === "string") ? id : JSON.stringify(id));
|
|
99
122
|
}
|
|
100
123
|
}
|
|
@@ -720,9 +743,6 @@ function resetCanonicalStringify() {
|
|
|
720
743
|
stringifyCache = new (utilities.canUseWeakMap ? WeakMap : Map)();
|
|
721
744
|
}
|
|
722
745
|
|
|
723
|
-
function missingFromInvariant(err, context) {
|
|
724
|
-
return new MissingFieldError(err.message, context.path.slice(), context.query, context.variables);
|
|
725
|
-
}
|
|
726
746
|
function execSelectionSetKeyArgs(options) {
|
|
727
747
|
return [
|
|
728
748
|
options.selectionSet,
|
|
@@ -784,6 +804,7 @@ var StoreReader = (function () {
|
|
|
784
804
|
var policies = this.config.cache.policies;
|
|
785
805
|
variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(utilities.getQueryDefinition(query))), variables);
|
|
786
806
|
var rootRef = utilities.makeReference(rootId);
|
|
807
|
+
var merger = new utilities.DeepMerger;
|
|
787
808
|
var execResult = this.executeSelectionSet({
|
|
788
809
|
selectionSet: utilities.getMainDefinition(query).selectionSet,
|
|
789
810
|
objectOrReference: rootRef,
|
|
@@ -796,17 +817,22 @@ var StoreReader = (function () {
|
|
|
796
817
|
varString: canonicalStringify(variables),
|
|
797
818
|
canonizeResults: canonizeResults,
|
|
798
819
|
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
|
|
799
|
-
|
|
820
|
+
merge: function (a, b) {
|
|
821
|
+
return merger.merge(a, b);
|
|
822
|
+
},
|
|
800
823
|
},
|
|
801
824
|
});
|
|
802
|
-
var
|
|
803
|
-
if (
|
|
804
|
-
|
|
825
|
+
var missing;
|
|
826
|
+
if (execResult.missing) {
|
|
827
|
+
missing = [new MissingFieldError(firstMissing(execResult.missing), execResult.missing, query, variables)];
|
|
828
|
+
if (!returnPartialData) {
|
|
829
|
+
throw missing[0];
|
|
830
|
+
}
|
|
805
831
|
}
|
|
806
832
|
return {
|
|
807
833
|
result: execResult.result,
|
|
808
|
-
|
|
809
|
-
|
|
834
|
+
complete: !missing,
|
|
835
|
+
missing: missing,
|
|
810
836
|
};
|
|
811
837
|
};
|
|
812
838
|
StoreReader.prototype.isFresh = function (result, parent, selectionSet, context) {
|
|
@@ -827,30 +853,28 @@ var StoreReader = (function () {
|
|
|
827
853
|
!context.store.has(objectOrReference.__ref)) {
|
|
828
854
|
return {
|
|
829
855
|
result: this.canon.empty,
|
|
830
|
-
missing:
|
|
856
|
+
missing: "Dangling reference to missing ".concat(objectOrReference.__ref, " object"),
|
|
831
857
|
};
|
|
832
858
|
}
|
|
833
859
|
var variables = context.variables, policies = context.policies, store = context.store;
|
|
834
|
-
var objectsToMerge = [];
|
|
835
|
-
var finalResult = { result: null };
|
|
836
860
|
var typename = store.getFieldValue(objectOrReference, "__typename");
|
|
861
|
+
var result = {};
|
|
862
|
+
var missing;
|
|
837
863
|
if (this.config.addTypename &&
|
|
838
864
|
typeof typename === "string" &&
|
|
839
865
|
!policies.rootIdsByTypename[typename]) {
|
|
840
|
-
|
|
866
|
+
result = { __typename: typename };
|
|
841
867
|
}
|
|
842
|
-
function
|
|
843
|
-
return finalResult.missing || (finalResult.missing = []);
|
|
844
|
-
}
|
|
845
|
-
function handleMissing(result) {
|
|
868
|
+
function handleMissing(result, resultName) {
|
|
846
869
|
var _a;
|
|
847
|
-
if (result.missing)
|
|
848
|
-
|
|
870
|
+
if (result.missing) {
|
|
871
|
+
missing = context.merge(missing, (_a = {}, _a[resultName] = result.missing, _a));
|
|
872
|
+
}
|
|
849
873
|
return result.result;
|
|
850
874
|
}
|
|
851
875
|
var workSet = new Set(selectionSet.selections);
|
|
852
876
|
workSet.forEach(function (selection) {
|
|
853
|
-
var _a;
|
|
877
|
+
var _a, _b;
|
|
854
878
|
if (!utilities.shouldInclude(selection, variables))
|
|
855
879
|
return;
|
|
856
880
|
if (utilities.isField(selection)) {
|
|
@@ -861,12 +885,13 @@ var StoreReader = (function () {
|
|
|
861
885
|
from: objectOrReference,
|
|
862
886
|
}, context);
|
|
863
887
|
var resultName = utilities.resultKeyNameFromField(selection);
|
|
864
|
-
context.path.push(resultName);
|
|
865
888
|
if (fieldValue === void 0) {
|
|
866
889
|
if (!utilities.addTypenameToDocument.added(selection)) {
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
890
|
+
missing = context.merge(missing, (_a = {},
|
|
891
|
+
_a[resultName] = "Can't find field '".concat(selection.name.value, "' on ").concat(utilities.isReference(objectOrReference)
|
|
892
|
+
? objectOrReference.__ref + " object"
|
|
893
|
+
: "object " + JSON.stringify(objectOrReference, null, 2)),
|
|
894
|
+
_a));
|
|
870
895
|
}
|
|
871
896
|
}
|
|
872
897
|
else if (Array.isArray(fieldValue)) {
|
|
@@ -875,7 +900,7 @@ var StoreReader = (function () {
|
|
|
875
900
|
array: fieldValue,
|
|
876
901
|
enclosingRef: enclosingRef,
|
|
877
902
|
context: context,
|
|
878
|
-
}));
|
|
903
|
+
}), resultName);
|
|
879
904
|
}
|
|
880
905
|
else if (!selection.selectionSet) {
|
|
881
906
|
if (context.canonizeResults) {
|
|
@@ -888,12 +913,11 @@ var StoreReader = (function () {
|
|
|
888
913
|
objectOrReference: fieldValue,
|
|
889
914
|
enclosingRef: utilities.isReference(fieldValue) ? fieldValue : enclosingRef,
|
|
890
915
|
context: context,
|
|
891
|
-
}));
|
|
916
|
+
}), resultName);
|
|
892
917
|
}
|
|
893
918
|
if (fieldValue !== void 0) {
|
|
894
|
-
|
|
919
|
+
result = context.merge(result, (_b = {}, _b[resultName] = fieldValue, _b));
|
|
895
920
|
}
|
|
896
|
-
globals.invariant(context.path.pop() === resultName);
|
|
897
921
|
}
|
|
898
922
|
else {
|
|
899
923
|
var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
|
|
@@ -902,23 +926,24 @@ var StoreReader = (function () {
|
|
|
902
926
|
}
|
|
903
927
|
}
|
|
904
928
|
});
|
|
905
|
-
var
|
|
906
|
-
|
|
907
|
-
? this.canon.admit(
|
|
908
|
-
: utilities.maybeDeepFreeze(
|
|
909
|
-
|
|
910
|
-
|
|
929
|
+
var finalResult = { result: result, missing: missing };
|
|
930
|
+
var frozen = context.canonizeResults
|
|
931
|
+
? this.canon.admit(finalResult)
|
|
932
|
+
: utilities.maybeDeepFreeze(finalResult);
|
|
933
|
+
if (frozen.result) {
|
|
934
|
+
this.knownResults.set(frozen.result, selectionSet);
|
|
935
|
+
}
|
|
936
|
+
return frozen;
|
|
911
937
|
};
|
|
912
938
|
StoreReader.prototype.execSubSelectedArrayImpl = function (_a) {
|
|
913
939
|
var _this = this;
|
|
914
940
|
var field = _a.field, array = _a.array, enclosingRef = _a.enclosingRef, context = _a.context;
|
|
915
941
|
var missing;
|
|
916
942
|
function handleMissing(childResult, i) {
|
|
943
|
+
var _a;
|
|
917
944
|
if (childResult.missing) {
|
|
918
|
-
missing = missing
|
|
919
|
-
missing.push.apply(missing, childResult.missing);
|
|
945
|
+
missing = context.merge(missing, (_a = {}, _a[i] = childResult.missing, _a));
|
|
920
946
|
}
|
|
921
|
-
globals.invariant(context.path.pop() === i);
|
|
922
947
|
return childResult.result;
|
|
923
948
|
}
|
|
924
949
|
if (field.selectionSet) {
|
|
@@ -928,7 +953,6 @@ var StoreReader = (function () {
|
|
|
928
953
|
if (item === null) {
|
|
929
954
|
return null;
|
|
930
955
|
}
|
|
931
|
-
context.path.push(i);
|
|
932
956
|
if (Array.isArray(item)) {
|
|
933
957
|
return handleMissing(_this.executeSubSelectedArray({
|
|
934
958
|
field: field,
|
|
@@ -948,7 +972,6 @@ var StoreReader = (function () {
|
|
|
948
972
|
if (__DEV__) {
|
|
949
973
|
assertSelectionSetForIdValue(context.store, field, item);
|
|
950
974
|
}
|
|
951
|
-
globals.invariant(context.path.pop() === i);
|
|
952
975
|
return item;
|
|
953
976
|
});
|
|
954
977
|
return {
|
|
@@ -958,466 +981,275 @@ var StoreReader = (function () {
|
|
|
958
981
|
};
|
|
959
982
|
return StoreReader;
|
|
960
983
|
}());
|
|
984
|
+
function firstMissing(tree) {
|
|
985
|
+
try {
|
|
986
|
+
JSON.stringify(tree, function (_, value) {
|
|
987
|
+
if (typeof value === "string")
|
|
988
|
+
throw value;
|
|
989
|
+
return value;
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
catch (result) {
|
|
993
|
+
return result;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
961
996
|
function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
962
997
|
if (!field.selectionSet) {
|
|
963
998
|
var workSet_1 = new Set([fieldValue]);
|
|
964
999
|
workSet_1.forEach(function (value) {
|
|
965
1000
|
if (utilities.isNonNullObject(value)) {
|
|
966
|
-
__DEV__ ? globals.invariant(!utilities.isReference(value), "Missing selection set for object of type "
|
|
1001
|
+
__DEV__ ? globals.invariant(!utilities.isReference(value), "Missing selection set for object of type ".concat(getTypenameFromStoreObject(store, value), " returned for query field ").concat(field.name.value)) : globals.invariant(!utilities.isReference(value), 5);
|
|
967
1002
|
Object.values(value).forEach(workSet_1.add, workSet_1);
|
|
968
1003
|
}
|
|
969
1004
|
});
|
|
970
1005
|
}
|
|
971
1006
|
}
|
|
972
1007
|
|
|
973
|
-
var
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
1008
|
+
var cacheSlot = new context.Slot();
|
|
1009
|
+
var cacheInfoMap = new WeakMap();
|
|
1010
|
+
function getCacheInfo(cache) {
|
|
1011
|
+
var info = cacheInfoMap.get(cache);
|
|
1012
|
+
if (!info) {
|
|
1013
|
+
cacheInfoMap.set(cache, info = {
|
|
1014
|
+
vars: new Set,
|
|
1015
|
+
dep: optimism.dep(),
|
|
1016
|
+
});
|
|
977
1017
|
}
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1018
|
+
return info;
|
|
1019
|
+
}
|
|
1020
|
+
function forgetCache(cache) {
|
|
1021
|
+
getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
|
|
1022
|
+
}
|
|
1023
|
+
function recallCache(cache) {
|
|
1024
|
+
getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
|
|
1025
|
+
}
|
|
1026
|
+
function makeVar(value) {
|
|
1027
|
+
var caches = new Set();
|
|
1028
|
+
var listeners = new Set();
|
|
1029
|
+
var rv = function (newValue) {
|
|
1030
|
+
if (arguments.length > 0) {
|
|
1031
|
+
if (value !== newValue) {
|
|
1032
|
+
value = newValue;
|
|
1033
|
+
caches.forEach(function (cache) {
|
|
1034
|
+
getCacheInfo(cache).dep.dirty(rv);
|
|
1035
|
+
broadcast(cache);
|
|
1036
|
+
});
|
|
1037
|
+
var oldListeners = Array.from(listeners);
|
|
1038
|
+
listeners.clear();
|
|
1039
|
+
oldListeners.forEach(function (listener) { return listener(value); });
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else {
|
|
1043
|
+
var cache = cacheSlot.getValue();
|
|
1044
|
+
if (cache) {
|
|
1045
|
+
attach(cache);
|
|
1046
|
+
getCacheInfo(cache).dep(rv);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
return value;
|
|
1050
|
+
};
|
|
1051
|
+
rv.onNextChange = function (listener) {
|
|
1052
|
+
listeners.add(listener);
|
|
1053
|
+
return function () {
|
|
1054
|
+
listeners.delete(listener);
|
|
996
1055
|
};
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1056
|
+
};
|
|
1057
|
+
var attach = rv.attachCache = function (cache) {
|
|
1058
|
+
caches.add(cache);
|
|
1059
|
+
getCacheInfo(cache).vars.add(rv);
|
|
1060
|
+
return rv;
|
|
1061
|
+
};
|
|
1062
|
+
rv.forgetCache = function (cache) { return caches.delete(cache); };
|
|
1063
|
+
return rv;
|
|
1064
|
+
}
|
|
1065
|
+
function broadcast(cache) {
|
|
1066
|
+
if (cache.broadcastWatches) {
|
|
1067
|
+
cache.broadcastWatches();
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
var specifierInfoCache = Object.create(null);
|
|
1072
|
+
function lookupSpecifierInfo(spec) {
|
|
1073
|
+
var cacheKey = JSON.stringify(spec);
|
|
1074
|
+
return specifierInfoCache[cacheKey] ||
|
|
1075
|
+
(specifierInfoCache[cacheKey] = Object.create(null));
|
|
1076
|
+
}
|
|
1077
|
+
function keyFieldsFnFromSpecifier(specifier) {
|
|
1078
|
+
var info = lookupSpecifierInfo(specifier);
|
|
1079
|
+
return info.keyFieldsFn || (info.keyFieldsFn = function (object, context) {
|
|
1080
|
+
var extract = function (from, key) { return context.readField(key, from); };
|
|
1081
|
+
var keyObject = context.keyObject = collectSpecifierPaths(specifier, function (schemaKeyPath) {
|
|
1082
|
+
var extracted = extractKeyPath(context.storeObject, schemaKeyPath, extract);
|
|
1083
|
+
if (extracted === void 0 &&
|
|
1084
|
+
object !== context.storeObject &&
|
|
1085
|
+
hasOwn.call(object, schemaKeyPath[0])) {
|
|
1086
|
+
extracted = extractKeyPath(object, schemaKeyPath, extractKey);
|
|
1087
|
+
}
|
|
1088
|
+
__DEV__ ? globals.invariant(extracted !== void 0, "Missing field '".concat(schemaKeyPath.join('.'), "' while extracting keyFields from ").concat(JSON.stringify(object))) : globals.invariant(extracted !== void 0, 2);
|
|
1089
|
+
return extracted;
|
|
1003
1090
|
});
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1091
|
+
return "".concat(context.typename, ":").concat(JSON.stringify(keyObject));
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
function keyArgsFnFromSpecifier(specifier) {
|
|
1095
|
+
var info = lookupSpecifierInfo(specifier);
|
|
1096
|
+
return info.keyArgsFn || (info.keyArgsFn = function (args, _a) {
|
|
1097
|
+
var field = _a.field, variables = _a.variables, fieldName = _a.fieldName;
|
|
1098
|
+
var collected = collectSpecifierPaths(specifier, function (keyPath) {
|
|
1099
|
+
var firstKey = keyPath[0];
|
|
1100
|
+
var firstChar = firstKey.charAt(0);
|
|
1101
|
+
if (firstChar === "@") {
|
|
1102
|
+
if (field && utilities.isNonEmptyArray(field.directives)) {
|
|
1103
|
+
var directiveName_1 = firstKey.slice(1);
|
|
1104
|
+
var d = field.directives.find(function (d) { return d.name.value === directiveName_1; });
|
|
1105
|
+
var directiveArgs = d && utilities.argumentsObjectFromField(d, variables);
|
|
1106
|
+
return directiveArgs && extractKeyPath(directiveArgs, keyPath.slice(1));
|
|
1014
1107
|
}
|
|
1015
|
-
|
|
1108
|
+
return;
|
|
1016
1109
|
}
|
|
1017
|
-
if (
|
|
1018
|
-
var
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
}
|
|
1026
|
-
});
|
|
1027
|
-
var hasMergeFunction_1 = function (storeFieldName) {
|
|
1028
|
-
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
1029
|
-
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
1030
|
-
};
|
|
1031
|
-
Object.keys(fields).forEach(function (storeFieldName) {
|
|
1032
|
-
if (hasSelectionSet_1(storeFieldName) &&
|
|
1033
|
-
!hasMergeFunction_1(storeFieldName)) {
|
|
1034
|
-
warnAboutDataLoss(entityRef, fields, storeFieldName, context.store);
|
|
1035
|
-
}
|
|
1036
|
-
});
|
|
1110
|
+
if (firstChar === "$") {
|
|
1111
|
+
var variableName = firstKey.slice(1);
|
|
1112
|
+
if (variables && hasOwn.call(variables, variableName)) {
|
|
1113
|
+
var varKeyPath = keyPath.slice(0);
|
|
1114
|
+
varKeyPath[0] = variableName;
|
|
1115
|
+
return extractKeyPath(variables, varKeyPath);
|
|
1116
|
+
}
|
|
1117
|
+
return;
|
|
1037
1118
|
}
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
store.retain(ref.__ref);
|
|
1041
|
-
return ref;
|
|
1042
|
-
};
|
|
1043
|
-
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
1044
|
-
var _this = this;
|
|
1045
|
-
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
|
|
1046
|
-
var policies = this.cache.policies;
|
|
1047
|
-
var _b = policies.identify(result, selectionSet, context.fragmentMap), id = _b[0], keyObject = _b[1];
|
|
1048
|
-
dataId = dataId || id;
|
|
1049
|
-
if ("string" === typeof dataId) {
|
|
1050
|
-
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
1051
|
-
var ref = utilities.makeReference(dataId);
|
|
1052
|
-
if (sets.indexOf(selectionSet) >= 0)
|
|
1053
|
-
return ref;
|
|
1054
|
-
sets.push(selectionSet);
|
|
1055
|
-
if (this.reader && this.reader.isFresh(result, ref, selectionSet, context)) {
|
|
1056
|
-
return ref;
|
|
1119
|
+
if (args) {
|
|
1120
|
+
return extractKeyPath(args, keyPath);
|
|
1057
1121
|
}
|
|
1122
|
+
});
|
|
1123
|
+
var suffix = JSON.stringify(collected);
|
|
1124
|
+
if (args || suffix !== "{}") {
|
|
1125
|
+
fieldName += ":" + suffix;
|
|
1058
1126
|
}
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1127
|
+
return fieldName;
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
function collectSpecifierPaths(specifier, extractor) {
|
|
1131
|
+
var merger = new utilities.DeepMerger;
|
|
1132
|
+
return getSpecifierPaths(specifier).reduce(function (collected, path) {
|
|
1133
|
+
var _a;
|
|
1134
|
+
var toMerge = extractor(path);
|
|
1135
|
+
if (toMerge !== void 0) {
|
|
1136
|
+
for (var i = path.length - 1; i >= 0; --i) {
|
|
1137
|
+
toMerge = (_a = {}, _a[path[i]] = toMerge, _a);
|
|
1138
|
+
}
|
|
1139
|
+
collected = merger.merge(collected, toMerge);
|
|
1068
1140
|
}
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
var storeFieldName = policies.getStoreFieldName({
|
|
1082
|
-
typename: typename,
|
|
1083
|
-
fieldName: selection.name.value,
|
|
1084
|
-
field: selection,
|
|
1085
|
-
variables: context.variables,
|
|
1086
|
-
});
|
|
1087
|
-
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
1088
|
-
var incomingValue = _this.processFieldValue(value, selection, context, childTree);
|
|
1089
|
-
var childTypename = void 0;
|
|
1090
|
-
if (selection.selectionSet) {
|
|
1091
|
-
childTypename = context.store.getFieldValue(incomingValue, "__typename");
|
|
1092
|
-
if (!childTypename && utilities.isReference(incomingValue)) {
|
|
1093
|
-
var info = context.incomingById.get(incomingValue.__ref);
|
|
1094
|
-
childTypename = info && info.fields.__typename;
|
|
1095
|
-
}
|
|
1096
|
-
}
|
|
1097
|
-
var merge = policies.getMergeFunction(typename, selection.name.value, childTypename);
|
|
1098
|
-
if (merge) {
|
|
1099
|
-
childTree.info = {
|
|
1100
|
-
field: selection,
|
|
1101
|
-
typename: typename,
|
|
1102
|
-
merge: merge,
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
1105
|
-
else {
|
|
1106
|
-
maybeRecycleChildMergeTree(mergeTree, storeFieldName);
|
|
1107
|
-
}
|
|
1108
|
-
incomingFields = context.merge(incomingFields, (_a = {},
|
|
1109
|
-
_a[storeFieldName] = incomingValue,
|
|
1110
|
-
_a));
|
|
1111
|
-
}
|
|
1112
|
-
else if (!context.clientOnly &&
|
|
1113
|
-
!utilities.addTypenameToDocument.added(selection)) {
|
|
1114
|
-
__DEV__ && globals.invariant.error(("Missing field '" + utilities.resultKeyNameFromField(selection) + "' while writing result " + JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
1115
|
-
}
|
|
1116
|
-
context.clientOnly = wasClientOnly;
|
|
1141
|
+
return collected;
|
|
1142
|
+
}, Object.create(null));
|
|
1143
|
+
}
|
|
1144
|
+
function getSpecifierPaths(spec) {
|
|
1145
|
+
var info = lookupSpecifierInfo(spec);
|
|
1146
|
+
if (!info.paths) {
|
|
1147
|
+
var paths_1 = info.paths = [];
|
|
1148
|
+
var currentPath_1 = [];
|
|
1149
|
+
spec.forEach(function (s, i) {
|
|
1150
|
+
if (Array.isArray(s)) {
|
|
1151
|
+
getSpecifierPaths(s).forEach(function (p) { return paths_1.push(currentPath_1.concat(p)); });
|
|
1152
|
+
currentPath_1.length = 0;
|
|
1117
1153
|
}
|
|
1118
1154
|
else {
|
|
1119
|
-
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
|
|
1155
|
+
currentPath_1.push(s);
|
|
1156
|
+
if (!Array.isArray(spec[i + 1])) {
|
|
1157
|
+
paths_1.push(currentPath_1.slice(0));
|
|
1158
|
+
currentPath_1.length = 0;
|
|
1123
1159
|
}
|
|
1124
1160
|
}
|
|
1125
1161
|
});
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1162
|
+
}
|
|
1163
|
+
return info.paths;
|
|
1164
|
+
}
|
|
1165
|
+
function extractKey(object, key) {
|
|
1166
|
+
return object[key];
|
|
1167
|
+
}
|
|
1168
|
+
function extractKeyPath(object, path, extract) {
|
|
1169
|
+
extract = extract || extractKey;
|
|
1170
|
+
return normalize(path.reduce(function reducer(obj, key) {
|
|
1171
|
+
return Array.isArray(obj)
|
|
1172
|
+
? obj.map(function (child) { return reducer(child, key); })
|
|
1173
|
+
: obj && extract(obj, key);
|
|
1174
|
+
}, object));
|
|
1175
|
+
}
|
|
1176
|
+
function normalize(value) {
|
|
1177
|
+
if (utilities.isNonNullObject(value)) {
|
|
1178
|
+
if (Array.isArray(value)) {
|
|
1179
|
+
return value.map(normalize);
|
|
1180
|
+
}
|
|
1181
|
+
return collectSpecifierPaths(Object.keys(value).sort(), function (path) { return extractKeyPath(value, path); });
|
|
1182
|
+
}
|
|
1183
|
+
return value;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
utilities.getStoreKeyName.setStringify(canonicalStringify);
|
|
1187
|
+
function argsFromFieldSpecifier(spec) {
|
|
1188
|
+
return spec.args !== void 0 ? spec.args :
|
|
1189
|
+
spec.field ? utilities.argumentsObjectFromField(spec.field, spec.variables) : null;
|
|
1190
|
+
}
|
|
1191
|
+
var nullKeyFieldsFn = function () { return void 0; };
|
|
1192
|
+
var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
|
|
1193
|
+
var mergeTrueFn = function (existing, incoming, _a) {
|
|
1194
|
+
var mergeObjects = _a.mergeObjects;
|
|
1195
|
+
return mergeObjects(existing, incoming);
|
|
1196
|
+
};
|
|
1197
|
+
var mergeFalseFn = function (_, incoming) { return incoming; };
|
|
1198
|
+
var Policies = (function () {
|
|
1199
|
+
function Policies(config) {
|
|
1200
|
+
this.config = config;
|
|
1201
|
+
this.typePolicies = Object.create(null);
|
|
1202
|
+
this.toBeAdded = Object.create(null);
|
|
1203
|
+
this.supertypeMap = new Map();
|
|
1204
|
+
this.fuzzySubtypes = new Map();
|
|
1205
|
+
this.rootIdsByTypename = Object.create(null);
|
|
1206
|
+
this.rootTypenamesById = Object.create(null);
|
|
1207
|
+
this.usingPossibleTypes = false;
|
|
1208
|
+
this.config = tslib.__assign({ dataIdFromObject: defaultDataIdFromObject }, config);
|
|
1209
|
+
this.cache = this.config.cache;
|
|
1210
|
+
this.setRootTypename("Query");
|
|
1211
|
+
this.setRootTypename("Mutation");
|
|
1212
|
+
this.setRootTypename("Subscription");
|
|
1213
|
+
if (config.possibleTypes) {
|
|
1214
|
+
this.addPossibleTypes(config.possibleTypes);
|
|
1215
|
+
}
|
|
1216
|
+
if (config.typePolicies) {
|
|
1217
|
+
this.addTypePolicies(config.typePolicies);
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
Policies.prototype.identify = function (object, partialContext) {
|
|
1221
|
+
var _a;
|
|
1222
|
+
var policies = this;
|
|
1223
|
+
var typename = partialContext && (partialContext.typename ||
|
|
1224
|
+
((_a = partialContext.storeObject) === null || _a === void 0 ? void 0 : _a.__typename)) || object.__typename;
|
|
1225
|
+
if (typename === this.rootTypenamesById.ROOT_QUERY) {
|
|
1226
|
+
return ["ROOT_QUERY"];
|
|
1227
|
+
}
|
|
1228
|
+
var storeObject = partialContext && partialContext.storeObject || object;
|
|
1229
|
+
var context = tslib.__assign(tslib.__assign({}, partialContext), { typename: typename, storeObject: storeObject, readField: partialContext && partialContext.readField || function () {
|
|
1230
|
+
var options = normalizeReadFieldOptions(arguments, storeObject);
|
|
1231
|
+
return policies.readField(options, {
|
|
1232
|
+
store: policies.cache["data"],
|
|
1233
|
+
variables: options.variables,
|
|
1234
|
+
});
|
|
1235
|
+
} });
|
|
1236
|
+
var id;
|
|
1237
|
+
var policy = typename && this.getTypePolicy(typename);
|
|
1238
|
+
var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
|
|
1239
|
+
while (keyFn) {
|
|
1240
|
+
var specifierOrId = keyFn(object, context);
|
|
1241
|
+
if (Array.isArray(specifierOrId)) {
|
|
1242
|
+
keyFn = keyFieldsFnFromSpecifier(specifierOrId);
|
|
1133
1243
|
}
|
|
1134
1244
|
else {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
1138
|
-
selections: selections,
|
|
1139
|
-
});
|
|
1245
|
+
id = specifierOrId;
|
|
1246
|
+
break;
|
|
1140
1247
|
}
|
|
1141
|
-
return utilities.makeReference(dataId);
|
|
1142
1248
|
}
|
|
1143
|
-
|
|
1249
|
+
id = id ? String(id) : void 0;
|
|
1250
|
+
return context.keyObject ? [id, context.keyObject] : [id];
|
|
1144
1251
|
};
|
|
1145
|
-
|
|
1146
|
-
var _this = this;
|
|
1147
|
-
if (!field.selectionSet || value === null) {
|
|
1148
|
-
return __DEV__ ? utilities.cloneDeep(value) : value;
|
|
1149
|
-
}
|
|
1150
|
-
if (Array.isArray(value)) {
|
|
1151
|
-
return value.map(function (item, i) {
|
|
1152
|
-
var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
|
|
1153
|
-
maybeRecycleChildMergeTree(mergeTree, i);
|
|
1154
|
-
return value;
|
|
1155
|
-
});
|
|
1156
|
-
}
|
|
1157
|
-
return this.processSelectionSet({
|
|
1158
|
-
result: value,
|
|
1159
|
-
selectionSet: field.selectionSet,
|
|
1160
|
-
context: context,
|
|
1161
|
-
mergeTree: mergeTree,
|
|
1162
|
-
});
|
|
1163
|
-
};
|
|
1164
|
-
StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
|
|
1165
|
-
var _a;
|
|
1166
|
-
var _this = this;
|
|
1167
|
-
if (mergeTree.map.size && !utilities.isReference(incoming)) {
|
|
1168
|
-
var e_1 = (!Array.isArray(incoming) &&
|
|
1169
|
-
(utilities.isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
|
|
1170
|
-
var i_1 = incoming;
|
|
1171
|
-
if (e_1 && !getStorageArgs) {
|
|
1172
|
-
getStorageArgs = [utilities.isReference(e_1) ? e_1.__ref : e_1];
|
|
1173
|
-
}
|
|
1174
|
-
var changedFields_1;
|
|
1175
|
-
var getValue_1 = function (from, name) {
|
|
1176
|
-
return Array.isArray(from)
|
|
1177
|
-
? (typeof name === "number" ? from[name] : void 0)
|
|
1178
|
-
: context.store.getFieldValue(from, String(name));
|
|
1179
|
-
};
|
|
1180
|
-
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
1181
|
-
var eVal = getValue_1(e_1, storeFieldName);
|
|
1182
|
-
var iVal = getValue_1(i_1, storeFieldName);
|
|
1183
|
-
if (void 0 === iVal)
|
|
1184
|
-
return;
|
|
1185
|
-
if (getStorageArgs) {
|
|
1186
|
-
getStorageArgs.push(storeFieldName);
|
|
1187
|
-
}
|
|
1188
|
-
var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
|
|
1189
|
-
if (aVal !== iVal) {
|
|
1190
|
-
changedFields_1 = changedFields_1 || new Map;
|
|
1191
|
-
changedFields_1.set(storeFieldName, aVal);
|
|
1192
|
-
}
|
|
1193
|
-
if (getStorageArgs) {
|
|
1194
|
-
globals.invariant(getStorageArgs.pop() === storeFieldName);
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
|
-
if (changedFields_1) {
|
|
1198
|
-
incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
|
|
1199
|
-
changedFields_1.forEach(function (value, name) {
|
|
1200
|
-
incoming[name] = value;
|
|
1201
|
-
});
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
if (mergeTree.info) {
|
|
1205
|
-
return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
|
|
1206
|
-
}
|
|
1207
|
-
return incoming;
|
|
1208
|
-
};
|
|
1209
|
-
return StoreWriter;
|
|
1210
|
-
}());
|
|
1211
|
-
var emptyMergeTreePool = [];
|
|
1212
|
-
function getChildMergeTree(_a, name) {
|
|
1213
|
-
var map = _a.map;
|
|
1214
|
-
if (!map.has(name)) {
|
|
1215
|
-
map.set(name, emptyMergeTreePool.pop() || { map: new Map });
|
|
1216
|
-
}
|
|
1217
|
-
return map.get(name);
|
|
1218
|
-
}
|
|
1219
|
-
function mergeMergeTrees(left, right) {
|
|
1220
|
-
if (left === right || !right || mergeTreeIsEmpty(right))
|
|
1221
|
-
return left;
|
|
1222
|
-
if (!left || mergeTreeIsEmpty(left))
|
|
1223
|
-
return right;
|
|
1224
|
-
var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
|
|
1225
|
-
var needToMergeMaps = left.map.size && right.map.size;
|
|
1226
|
-
var map = needToMergeMaps ? new Map :
|
|
1227
|
-
left.map.size ? left.map : right.map;
|
|
1228
|
-
var merged = { info: info, map: map };
|
|
1229
|
-
if (needToMergeMaps) {
|
|
1230
|
-
var remainingRightKeys_1 = new Set(right.map.keys());
|
|
1231
|
-
left.map.forEach(function (leftTree, key) {
|
|
1232
|
-
merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
|
|
1233
|
-
remainingRightKeys_1.delete(key);
|
|
1234
|
-
});
|
|
1235
|
-
remainingRightKeys_1.forEach(function (key) {
|
|
1236
|
-
merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
|
|
1237
|
-
});
|
|
1238
|
-
}
|
|
1239
|
-
return merged;
|
|
1240
|
-
}
|
|
1241
|
-
function mergeTreeIsEmpty(tree) {
|
|
1242
|
-
return !tree || !(tree.info || tree.map.size);
|
|
1243
|
-
}
|
|
1244
|
-
function maybeRecycleChildMergeTree(_a, name) {
|
|
1245
|
-
var map = _a.map;
|
|
1246
|
-
var childTree = map.get(name);
|
|
1247
|
-
if (childTree && mergeTreeIsEmpty(childTree)) {
|
|
1248
|
-
emptyMergeTreePool.push(childTree);
|
|
1249
|
-
map.delete(name);
|
|
1250
|
-
}
|
|
1251
|
-
}
|
|
1252
|
-
var warnings = new Set();
|
|
1253
|
-
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
1254
|
-
var getChild = function (objOrRef) {
|
|
1255
|
-
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
1256
|
-
return typeof child === "object" && child;
|
|
1257
|
-
};
|
|
1258
|
-
var existing = getChild(existingRef);
|
|
1259
|
-
if (!existing)
|
|
1260
|
-
return;
|
|
1261
|
-
var incoming = getChild(incomingObj);
|
|
1262
|
-
if (!incoming)
|
|
1263
|
-
return;
|
|
1264
|
-
if (utilities.isReference(existing))
|
|
1265
|
-
return;
|
|
1266
|
-
if (equality.equal(existing, incoming))
|
|
1267
|
-
return;
|
|
1268
|
-
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
1269
|
-
return;
|
|
1270
|
-
}
|
|
1271
|
-
var parentType = store.getFieldValue(existingRef, "__typename") ||
|
|
1272
|
-
store.getFieldValue(incomingObj, "__typename");
|
|
1273
|
-
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
1274
|
-
var typeDotName = parentType + "." + fieldName;
|
|
1275
|
-
if (warnings.has(typeDotName))
|
|
1276
|
-
return;
|
|
1277
|
-
warnings.add(typeDotName);
|
|
1278
|
-
var childTypenames = [];
|
|
1279
|
-
if (!Array.isArray(existing) &&
|
|
1280
|
-
!Array.isArray(incoming)) {
|
|
1281
|
-
[existing, incoming].forEach(function (child) {
|
|
1282
|
-
var typename = store.getFieldValue(child, "__typename");
|
|
1283
|
-
if (typeof typename === "string" &&
|
|
1284
|
-
!childTypenames.includes(typename)) {
|
|
1285
|
-
childTypenames.push(typename);
|
|
1286
|
-
}
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
__DEV__ && globals.invariant.warn("Cache data may be lost when replacing the " + fieldName + " field of a " + parentType + " object.\n\nTo address this problem (which is not a bug in Apollo Client), " + (childTypenames.length
|
|
1290
|
-
? "either ensure all objects of type " +
|
|
1291
|
-
childTypenames.join(" and ") + " have an ID or a custom merge function, or "
|
|
1292
|
-
: "") + "define a custom merge function for the " + typeDotName + " field, so InMemoryCache can safely merge these objects:\n\n existing: " + JSON.stringify(existing).slice(0, 1000) + "\n incoming: " + JSON.stringify(incoming).slice(0, 1000) + "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n");
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
var cacheSlot = new context.Slot();
|
|
1296
|
-
var cacheInfoMap = new WeakMap();
|
|
1297
|
-
function getCacheInfo(cache) {
|
|
1298
|
-
var info = cacheInfoMap.get(cache);
|
|
1299
|
-
if (!info) {
|
|
1300
|
-
cacheInfoMap.set(cache, info = {
|
|
1301
|
-
vars: new Set,
|
|
1302
|
-
dep: optimism.dep(),
|
|
1303
|
-
});
|
|
1304
|
-
}
|
|
1305
|
-
return info;
|
|
1306
|
-
}
|
|
1307
|
-
function forgetCache(cache) {
|
|
1308
|
-
getCacheInfo(cache).vars.forEach(function (rv) { return rv.forgetCache(cache); });
|
|
1309
|
-
}
|
|
1310
|
-
function recallCache(cache) {
|
|
1311
|
-
getCacheInfo(cache).vars.forEach(function (rv) { return rv.attachCache(cache); });
|
|
1312
|
-
}
|
|
1313
|
-
function makeVar(value) {
|
|
1314
|
-
var caches = new Set();
|
|
1315
|
-
var listeners = new Set();
|
|
1316
|
-
var rv = function (newValue) {
|
|
1317
|
-
if (arguments.length > 0) {
|
|
1318
|
-
if (value !== newValue) {
|
|
1319
|
-
value = newValue;
|
|
1320
|
-
caches.forEach(function (cache) {
|
|
1321
|
-
getCacheInfo(cache).dep.dirty(rv);
|
|
1322
|
-
broadcast(cache);
|
|
1323
|
-
});
|
|
1324
|
-
var oldListeners = Array.from(listeners);
|
|
1325
|
-
listeners.clear();
|
|
1326
|
-
oldListeners.forEach(function (listener) { return listener(value); });
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
else {
|
|
1330
|
-
var cache = cacheSlot.getValue();
|
|
1331
|
-
if (cache) {
|
|
1332
|
-
attach(cache);
|
|
1333
|
-
getCacheInfo(cache).dep(rv);
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
return value;
|
|
1337
|
-
};
|
|
1338
|
-
rv.onNextChange = function (listener) {
|
|
1339
|
-
listeners.add(listener);
|
|
1340
|
-
return function () {
|
|
1341
|
-
listeners.delete(listener);
|
|
1342
|
-
};
|
|
1343
|
-
};
|
|
1344
|
-
var attach = rv.attachCache = function (cache) {
|
|
1345
|
-
caches.add(cache);
|
|
1346
|
-
getCacheInfo(cache).vars.add(rv);
|
|
1347
|
-
return rv;
|
|
1348
|
-
};
|
|
1349
|
-
rv.forgetCache = function (cache) { return caches.delete(cache); };
|
|
1350
|
-
return rv;
|
|
1351
|
-
}
|
|
1352
|
-
function broadcast(cache) {
|
|
1353
|
-
if (cache.broadcastWatches) {
|
|
1354
|
-
cache.broadcastWatches();
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
|
|
1358
|
-
utilities.getStoreKeyName.setStringify(canonicalStringify);
|
|
1359
|
-
function argsFromFieldSpecifier(spec) {
|
|
1360
|
-
return spec.args !== void 0 ? spec.args :
|
|
1361
|
-
spec.field ? utilities.argumentsObjectFromField(spec.field, spec.variables) : null;
|
|
1362
|
-
}
|
|
1363
|
-
var nullKeyFieldsFn = function () { return void 0; };
|
|
1364
|
-
var simpleKeyArgsFn = function (_args, context) { return context.fieldName; };
|
|
1365
|
-
var mergeTrueFn = function (existing, incoming, _a) {
|
|
1366
|
-
var mergeObjects = _a.mergeObjects;
|
|
1367
|
-
return mergeObjects(existing, incoming);
|
|
1368
|
-
};
|
|
1369
|
-
var mergeFalseFn = function (_, incoming) { return incoming; };
|
|
1370
|
-
var Policies = (function () {
|
|
1371
|
-
function Policies(config) {
|
|
1372
|
-
this.config = config;
|
|
1373
|
-
this.typePolicies = Object.create(null);
|
|
1374
|
-
this.toBeAdded = Object.create(null);
|
|
1375
|
-
this.supertypeMap = new Map();
|
|
1376
|
-
this.fuzzySubtypes = new Map();
|
|
1377
|
-
this.rootIdsByTypename = Object.create(null);
|
|
1378
|
-
this.rootTypenamesById = Object.create(null);
|
|
1379
|
-
this.usingPossibleTypes = false;
|
|
1380
|
-
this.config = tslib.__assign({ dataIdFromObject: defaultDataIdFromObject }, config);
|
|
1381
|
-
this.cache = this.config.cache;
|
|
1382
|
-
this.setRootTypename("Query");
|
|
1383
|
-
this.setRootTypename("Mutation");
|
|
1384
|
-
this.setRootTypename("Subscription");
|
|
1385
|
-
if (config.possibleTypes) {
|
|
1386
|
-
this.addPossibleTypes(config.possibleTypes);
|
|
1387
|
-
}
|
|
1388
|
-
if (config.typePolicies) {
|
|
1389
|
-
this.addTypePolicies(config.typePolicies);
|
|
1390
|
-
}
|
|
1391
|
-
}
|
|
1392
|
-
Policies.prototype.identify = function (object, selectionSet, fragmentMap) {
|
|
1393
|
-
var typename = selectionSet && fragmentMap
|
|
1394
|
-
? utilities.getTypenameFromResult(object, selectionSet, fragmentMap)
|
|
1395
|
-
: object.__typename;
|
|
1396
|
-
if (typename === this.rootTypenamesById.ROOT_QUERY) {
|
|
1397
|
-
return ["ROOT_QUERY"];
|
|
1398
|
-
}
|
|
1399
|
-
var context = {
|
|
1400
|
-
typename: typename,
|
|
1401
|
-
selectionSet: selectionSet,
|
|
1402
|
-
fragmentMap: fragmentMap,
|
|
1403
|
-
};
|
|
1404
|
-
var id;
|
|
1405
|
-
var policy = typename && this.getTypePolicy(typename);
|
|
1406
|
-
var keyFn = policy && policy.keyFn || this.config.dataIdFromObject;
|
|
1407
|
-
while (keyFn) {
|
|
1408
|
-
var specifierOrId = keyFn(object, context);
|
|
1409
|
-
if (Array.isArray(specifierOrId)) {
|
|
1410
|
-
keyFn = keyFieldsFnFromSpecifier(specifierOrId);
|
|
1411
|
-
}
|
|
1412
|
-
else {
|
|
1413
|
-
id = specifierOrId;
|
|
1414
|
-
break;
|
|
1415
|
-
}
|
|
1416
|
-
}
|
|
1417
|
-
id = id ? String(id) : void 0;
|
|
1418
|
-
return context.keyObject ? [id, context.keyObject] : [id];
|
|
1419
|
-
};
|
|
1420
|
-
Policies.prototype.addTypePolicies = function (typePolicies) {
|
|
1252
|
+
Policies.prototype.addTypePolicies = function (typePolicies) {
|
|
1421
1253
|
var _this = this;
|
|
1422
1254
|
Object.keys(typePolicies).forEach(function (typename) {
|
|
1423
1255
|
var _a = typePolicies[typename], queryType = _a.queryType, mutationType = _a.mutationType, subscriptionType = _a.subscriptionType, incoming = tslib.__rest(_a, ["queryType", "mutationType", "subscriptionType"]);
|
|
@@ -1482,7 +1314,7 @@ var Policies = (function () {
|
|
|
1482
1314
|
var rootId = "ROOT_" + which.toUpperCase();
|
|
1483
1315
|
var old = this.rootTypenamesById[rootId];
|
|
1484
1316
|
if (typename !== old) {
|
|
1485
|
-
__DEV__ ? globals.invariant(!old || old === which, "Cannot change root "
|
|
1317
|
+
__DEV__ ? globals.invariant(!old || old === which, "Cannot change root ".concat(which, " __typename more than once")) : globals.invariant(!old || old === which, 3);
|
|
1486
1318
|
if (old)
|
|
1487
1319
|
delete this.rootIdsByTypename[old];
|
|
1488
1320
|
this.rootIdsByTypename[typename] = rootId;
|
|
@@ -1566,7 +1398,7 @@ var Policies = (function () {
|
|
|
1566
1398
|
if (supertypeSet.has(supertype)) {
|
|
1567
1399
|
if (!typenameSupertypeSet.has(supertype)) {
|
|
1568
1400
|
if (checkingFuzzySubtypes) {
|
|
1569
|
-
__DEV__ && globals.invariant.warn("Inferring subtype "
|
|
1401
|
+
__DEV__ && globals.invariant.warn("Inferring subtype ".concat(typename, " of supertype ").concat(supertype));
|
|
1570
1402
|
}
|
|
1571
1403
|
typenameSupertypeSet.add(supertype);
|
|
1572
1404
|
}
|
|
@@ -1654,6 +1486,10 @@ var Policies = (function () {
|
|
|
1654
1486
|
}
|
|
1655
1487
|
return existing;
|
|
1656
1488
|
};
|
|
1489
|
+
Policies.prototype.getReadFunction = function (typename, fieldName) {
|
|
1490
|
+
var policy = this.getFieldPolicy(typename, fieldName, false);
|
|
1491
|
+
return policy && policy.read;
|
|
1492
|
+
};
|
|
1657
1493
|
Policies.prototype.getMergeFunction = function (parentTypename, fieldName, childTypename) {
|
|
1658
1494
|
var policy = this.getFieldPolicy(parentTypename, fieldName, false);
|
|
1659
1495
|
var merge = policy && policy.merge;
|
|
@@ -1694,144 +1530,456 @@ function makeFieldFunctionOptions(policies, objectOrReference, fieldSpec, contex
|
|
|
1694
1530
|
storage: storage,
|
|
1695
1531
|
cache: policies.cache,
|
|
1696
1532
|
canRead: canRead,
|
|
1697
|
-
readField: function (
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1533
|
+
readField: function () {
|
|
1534
|
+
return policies.readField(normalizeReadFieldOptions(arguments, objectOrReference, context), context);
|
|
1535
|
+
},
|
|
1536
|
+
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
1537
|
+
};
|
|
1538
|
+
}
|
|
1539
|
+
function normalizeReadFieldOptions(readFieldArgs, objectOrReference, variables) {
|
|
1540
|
+
var fieldNameOrOptions = readFieldArgs[0], from = readFieldArgs[1], argc = readFieldArgs.length;
|
|
1541
|
+
var options;
|
|
1542
|
+
if (typeof fieldNameOrOptions === "string") {
|
|
1543
|
+
options = {
|
|
1544
|
+
fieldName: fieldNameOrOptions,
|
|
1545
|
+
from: argc > 1 ? from : objectOrReference,
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
else {
|
|
1549
|
+
options = tslib.__assign({}, fieldNameOrOptions);
|
|
1550
|
+
if (!hasOwn.call(options, "from")) {
|
|
1551
|
+
options.from = objectOrReference;
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
if (__DEV__ && options.from === void 0) {
|
|
1555
|
+
__DEV__ && globals.invariant.warn("Undefined 'from' passed to readField with arguments ".concat(utilities.stringifyForDisplay(Array.from(readFieldArgs))));
|
|
1556
|
+
}
|
|
1557
|
+
if (void 0 === options.variables) {
|
|
1558
|
+
options.variables = variables;
|
|
1559
|
+
}
|
|
1560
|
+
return options;
|
|
1561
|
+
}
|
|
1562
|
+
function makeMergeObjectsFunction(store) {
|
|
1563
|
+
return function mergeObjects(existing, incoming) {
|
|
1564
|
+
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
1565
|
+
throw __DEV__ ? new globals.InvariantError("Cannot automatically merge arrays") : new globals.InvariantError(4);
|
|
1566
|
+
}
|
|
1567
|
+
if (utilities.isNonNullObject(existing) &&
|
|
1568
|
+
utilities.isNonNullObject(incoming)) {
|
|
1569
|
+
var eType = store.getFieldValue(existing, "__typename");
|
|
1570
|
+
var iType = store.getFieldValue(incoming, "__typename");
|
|
1571
|
+
var typesDiffer = eType && iType && eType !== iType;
|
|
1572
|
+
if (typesDiffer) {
|
|
1573
|
+
return incoming;
|
|
1574
|
+
}
|
|
1575
|
+
if (utilities.isReference(existing) &&
|
|
1576
|
+
storeValueIsStoreObject(incoming)) {
|
|
1577
|
+
store.merge(existing.__ref, incoming);
|
|
1578
|
+
return existing;
|
|
1579
|
+
}
|
|
1580
|
+
if (storeValueIsStoreObject(existing) &&
|
|
1581
|
+
utilities.isReference(incoming)) {
|
|
1582
|
+
store.merge(existing, incoming.__ref);
|
|
1583
|
+
return incoming;
|
|
1584
|
+
}
|
|
1585
|
+
if (storeValueIsStoreObject(existing) &&
|
|
1586
|
+
storeValueIsStoreObject(incoming)) {
|
|
1587
|
+
return tslib.__assign(tslib.__assign({}, existing), incoming);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
return incoming;
|
|
1591
|
+
};
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
function getContextFlavor(context, clientOnly, deferred) {
|
|
1595
|
+
var key = "".concat(clientOnly).concat(deferred);
|
|
1596
|
+
var flavored = context.flavors.get(key);
|
|
1597
|
+
if (!flavored) {
|
|
1598
|
+
context.flavors.set(key, flavored = (context.clientOnly === clientOnly &&
|
|
1599
|
+
context.deferred === deferred) ? context : tslib.__assign(tslib.__assign({}, context), { clientOnly: clientOnly, deferred: deferred }));
|
|
1600
|
+
}
|
|
1601
|
+
return flavored;
|
|
1602
|
+
}
|
|
1603
|
+
var StoreWriter = (function () {
|
|
1604
|
+
function StoreWriter(cache, reader) {
|
|
1605
|
+
this.cache = cache;
|
|
1606
|
+
this.reader = reader;
|
|
1607
|
+
}
|
|
1608
|
+
StoreWriter.prototype.writeToStore = function (store, _a) {
|
|
1609
|
+
var _this = this;
|
|
1610
|
+
var query = _a.query, result = _a.result, dataId = _a.dataId, variables = _a.variables, overwrite = _a.overwrite;
|
|
1611
|
+
var operationDefinition = utilities.getOperationDefinition(query);
|
|
1612
|
+
var merger = makeProcessedFieldsMerger();
|
|
1613
|
+
variables = tslib.__assign(tslib.__assign({}, utilities.getDefaultValues(operationDefinition)), variables);
|
|
1614
|
+
var context = {
|
|
1615
|
+
store: store,
|
|
1616
|
+
written: Object.create(null),
|
|
1617
|
+
merge: function (existing, incoming) {
|
|
1618
|
+
return merger.merge(existing, incoming);
|
|
1619
|
+
},
|
|
1620
|
+
variables: variables,
|
|
1621
|
+
varString: canonicalStringify(variables),
|
|
1622
|
+
fragmentMap: utilities.createFragmentMap(utilities.getFragmentDefinitions(query)),
|
|
1623
|
+
overwrite: !!overwrite,
|
|
1624
|
+
incomingById: new Map,
|
|
1625
|
+
clientOnly: false,
|
|
1626
|
+
deferred: false,
|
|
1627
|
+
flavors: new Map,
|
|
1628
|
+
};
|
|
1629
|
+
var ref = this.processSelectionSet({
|
|
1630
|
+
result: result || Object.create(null),
|
|
1631
|
+
dataId: dataId,
|
|
1632
|
+
selectionSet: operationDefinition.selectionSet,
|
|
1633
|
+
mergeTree: { map: new Map },
|
|
1634
|
+
context: context,
|
|
1635
|
+
});
|
|
1636
|
+
if (!utilities.isReference(ref)) {
|
|
1637
|
+
throw __DEV__ ? new globals.InvariantError("Could not identify object ".concat(JSON.stringify(result))) : new globals.InvariantError(6);
|
|
1638
|
+
}
|
|
1639
|
+
context.incomingById.forEach(function (_a, dataId) {
|
|
1640
|
+
var storeObject = _a.storeObject, mergeTree = _a.mergeTree, fieldNodeSet = _a.fieldNodeSet;
|
|
1641
|
+
var entityRef = utilities.makeReference(dataId);
|
|
1642
|
+
if (mergeTree && mergeTree.map.size) {
|
|
1643
|
+
var applied = _this.applyMerges(mergeTree, entityRef, storeObject, context);
|
|
1644
|
+
if (utilities.isReference(applied)) {
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
storeObject = applied;
|
|
1648
|
+
}
|
|
1649
|
+
if (__DEV__ && !context.overwrite) {
|
|
1650
|
+
var fieldsWithSelectionSets_1 = Object.create(null);
|
|
1651
|
+
fieldNodeSet.forEach(function (field) {
|
|
1652
|
+
if (field.selectionSet) {
|
|
1653
|
+
fieldsWithSelectionSets_1[field.name.value] = true;
|
|
1654
|
+
}
|
|
1655
|
+
});
|
|
1656
|
+
var hasSelectionSet_1 = function (storeFieldName) {
|
|
1657
|
+
return fieldsWithSelectionSets_1[fieldNameFromStoreName(storeFieldName)] === true;
|
|
1658
|
+
};
|
|
1659
|
+
var hasMergeFunction_1 = function (storeFieldName) {
|
|
1660
|
+
var childTree = mergeTree && mergeTree.map.get(storeFieldName);
|
|
1661
|
+
return Boolean(childTree && childTree.info && childTree.info.merge);
|
|
1703
1662
|
};
|
|
1663
|
+
Object.keys(storeObject).forEach(function (storeFieldName) {
|
|
1664
|
+
if (hasSelectionSet_1(storeFieldName) &&
|
|
1665
|
+
!hasMergeFunction_1(storeFieldName)) {
|
|
1666
|
+
warnAboutDataLoss(entityRef, storeObject, storeFieldName, context.store);
|
|
1667
|
+
}
|
|
1668
|
+
});
|
|
1704
1669
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1670
|
+
store.merge(dataId, storeObject);
|
|
1671
|
+
});
|
|
1672
|
+
store.retain(ref.__ref);
|
|
1673
|
+
return ref;
|
|
1674
|
+
};
|
|
1675
|
+
StoreWriter.prototype.processSelectionSet = function (_a) {
|
|
1676
|
+
var _this = this;
|
|
1677
|
+
var dataId = _a.dataId, result = _a.result, selectionSet = _a.selectionSet, context = _a.context, mergeTree = _a.mergeTree;
|
|
1678
|
+
var policies = this.cache.policies;
|
|
1679
|
+
var incoming = Object.create(null);
|
|
1680
|
+
var typename = (dataId && policies.rootTypenamesById[dataId]) ||
|
|
1681
|
+
utilities.getTypenameFromResult(result, selectionSet, context.fragmentMap) ||
|
|
1682
|
+
(dataId && context.store.get(dataId, "__typename"));
|
|
1683
|
+
if ("string" === typeof typename) {
|
|
1684
|
+
incoming.__typename = typename;
|
|
1685
|
+
}
|
|
1686
|
+
var readField = function () {
|
|
1687
|
+
var options = normalizeReadFieldOptions(arguments, incoming, context.variables);
|
|
1688
|
+
if (utilities.isReference(options.from)) {
|
|
1689
|
+
var info = context.incomingById.get(options.from.__ref);
|
|
1690
|
+
if (info) {
|
|
1691
|
+
var result_1 = policies.readField(tslib.__assign(tslib.__assign({}, options), { from: info.storeObject }), context);
|
|
1692
|
+
if (result_1 !== void 0) {
|
|
1693
|
+
return result_1;
|
|
1694
|
+
}
|
|
1709
1695
|
}
|
|
1710
1696
|
}
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1697
|
+
return policies.readField(options, context);
|
|
1698
|
+
};
|
|
1699
|
+
var fieldNodeSet = new Set();
|
|
1700
|
+
this.flattenFields(selectionSet, result, context, typename).forEach(function (context, field) {
|
|
1701
|
+
var _a;
|
|
1702
|
+
var resultFieldKey = utilities.resultKeyNameFromField(field);
|
|
1703
|
+
var value = result[resultFieldKey];
|
|
1704
|
+
fieldNodeSet.add(field);
|
|
1705
|
+
if (value !== void 0) {
|
|
1706
|
+
var storeFieldName = policies.getStoreFieldName({
|
|
1707
|
+
typename: typename,
|
|
1708
|
+
fieldName: field.name.value,
|
|
1709
|
+
field: field,
|
|
1710
|
+
variables: context.variables,
|
|
1711
|
+
});
|
|
1712
|
+
var childTree = getChildMergeTree(mergeTree, storeFieldName);
|
|
1713
|
+
var incomingValue = _this.processFieldValue(value, field, field.selectionSet
|
|
1714
|
+
? getContextFlavor(context, false, false)
|
|
1715
|
+
: context, childTree);
|
|
1716
|
+
var childTypename = void 0;
|
|
1717
|
+
if (field.selectionSet &&
|
|
1718
|
+
(utilities.isReference(incomingValue) ||
|
|
1719
|
+
storeValueIsStoreObject(incomingValue))) {
|
|
1720
|
+
childTypename = readField("__typename", incomingValue);
|
|
1721
|
+
}
|
|
1722
|
+
var merge = policies.getMergeFunction(typename, field.name.value, childTypename);
|
|
1723
|
+
if (merge) {
|
|
1724
|
+
childTree.info = {
|
|
1725
|
+
field: field,
|
|
1726
|
+
typename: typename,
|
|
1727
|
+
merge: merge,
|
|
1728
|
+
};
|
|
1729
|
+
}
|
|
1730
|
+
else {
|
|
1731
|
+
maybeRecycleChildMergeTree(mergeTree, storeFieldName);
|
|
1732
|
+
}
|
|
1733
|
+
incoming = context.merge(incoming, (_a = {},
|
|
1734
|
+
_a[storeFieldName] = incomingValue,
|
|
1735
|
+
_a));
|
|
1714
1736
|
}
|
|
1715
|
-
if (__DEV__ &&
|
|
1716
|
-
|
|
1737
|
+
else if (__DEV__ &&
|
|
1738
|
+
!context.clientOnly &&
|
|
1739
|
+
!context.deferred &&
|
|
1740
|
+
!utilities.addTypenameToDocument.added(field) &&
|
|
1741
|
+
!policies.getReadFunction(typename, field.name.value)) {
|
|
1742
|
+
__DEV__ && globals.invariant.error("Missing field '".concat(utilities.resultKeyNameFromField(field), "' while writing result ").concat(JSON.stringify(result, null, 2)).substring(0, 1000));
|
|
1717
1743
|
}
|
|
1718
|
-
|
|
1719
|
-
|
|
1744
|
+
});
|
|
1745
|
+
try {
|
|
1746
|
+
var _b = policies.identify(result, {
|
|
1747
|
+
typename: typename,
|
|
1748
|
+
selectionSet: selectionSet,
|
|
1749
|
+
fragmentMap: context.fragmentMap,
|
|
1750
|
+
storeObject: incoming,
|
|
1751
|
+
readField: readField,
|
|
1752
|
+
}), id = _b[0], keyObject = _b[1];
|
|
1753
|
+
dataId = dataId || id;
|
|
1754
|
+
if (keyObject) {
|
|
1755
|
+
incoming = context.merge(incoming, keyObject);
|
|
1720
1756
|
}
|
|
1721
|
-
return policies.readField(options, context);
|
|
1722
|
-
},
|
|
1723
|
-
mergeObjects: makeMergeObjectsFunction(context.store),
|
|
1724
|
-
};
|
|
1725
|
-
}
|
|
1726
|
-
function makeMergeObjectsFunction(store) {
|
|
1727
|
-
return function mergeObjects(existing, incoming) {
|
|
1728
|
-
if (Array.isArray(existing) || Array.isArray(incoming)) {
|
|
1729
|
-
throw __DEV__ ? new globals.InvariantError("Cannot automatically merge arrays") : new globals.InvariantError(3);
|
|
1730
1757
|
}
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
return
|
|
1758
|
+
catch (e) {
|
|
1759
|
+
if (!dataId)
|
|
1760
|
+
throw e;
|
|
1761
|
+
}
|
|
1762
|
+
if ("string" === typeof dataId) {
|
|
1763
|
+
var dataRef = utilities.makeReference(dataId);
|
|
1764
|
+
var sets = context.written[dataId] || (context.written[dataId] = []);
|
|
1765
|
+
if (sets.indexOf(selectionSet) >= 0)
|
|
1766
|
+
return dataRef;
|
|
1767
|
+
sets.push(selectionSet);
|
|
1768
|
+
if (this.reader && this.reader.isFresh(result, dataRef, selectionSet, context)) {
|
|
1769
|
+
return dataRef;
|
|
1743
1770
|
}
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1771
|
+
var previous_1 = context.incomingById.get(dataId);
|
|
1772
|
+
if (previous_1) {
|
|
1773
|
+
previous_1.storeObject = context.merge(previous_1.storeObject, incoming);
|
|
1774
|
+
previous_1.mergeTree = mergeMergeTrees(previous_1.mergeTree, mergeTree);
|
|
1775
|
+
fieldNodeSet.forEach(function (field) { return previous_1.fieldNodeSet.add(field); });
|
|
1748
1776
|
}
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1777
|
+
else {
|
|
1778
|
+
context.incomingById.set(dataId, {
|
|
1779
|
+
storeObject: incoming,
|
|
1780
|
+
mergeTree: mergeTreeIsEmpty(mergeTree) ? void 0 : mergeTree,
|
|
1781
|
+
fieldNodeSet: fieldNodeSet,
|
|
1782
|
+
});
|
|
1752
1783
|
}
|
|
1784
|
+
return dataRef;
|
|
1753
1785
|
}
|
|
1754
1786
|
return incoming;
|
|
1755
1787
|
};
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
function
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
computeKeyObject(object, specifier, true, aliasMap);
|
|
1775
|
-
return context.typename + ":" + JSON.stringify(keyObject);
|
|
1788
|
+
StoreWriter.prototype.processFieldValue = function (value, field, context, mergeTree) {
|
|
1789
|
+
var _this = this;
|
|
1790
|
+
if (!field.selectionSet || value === null) {
|
|
1791
|
+
return __DEV__ ? utilities.cloneDeep(value) : value;
|
|
1792
|
+
}
|
|
1793
|
+
if (Array.isArray(value)) {
|
|
1794
|
+
return value.map(function (item, i) {
|
|
1795
|
+
var value = _this.processFieldValue(item, field, context, getChildMergeTree(mergeTree, i));
|
|
1796
|
+
maybeRecycleChildMergeTree(mergeTree, i);
|
|
1797
|
+
return value;
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
return this.processSelectionSet({
|
|
1801
|
+
result: value,
|
|
1802
|
+
selectionSet: field.selectionSet,
|
|
1803
|
+
context: context,
|
|
1804
|
+
mergeTree: mergeTree,
|
|
1805
|
+
});
|
|
1776
1806
|
};
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1807
|
+
StoreWriter.prototype.flattenFields = function (selectionSet, result, context, typename) {
|
|
1808
|
+
if (typename === void 0) { typename = utilities.getTypenameFromResult(result, selectionSet, context.fragmentMap); }
|
|
1809
|
+
var fieldMap = new Map();
|
|
1810
|
+
var policies = this.cache.policies;
|
|
1811
|
+
var limitingTrie = new trie.Trie(false);
|
|
1812
|
+
(function flatten(selectionSet, inheritedContext) {
|
|
1813
|
+
var visitedNode = limitingTrie.lookup(selectionSet, inheritedContext.clientOnly, inheritedContext.deferred);
|
|
1814
|
+
if (visitedNode.visited)
|
|
1815
|
+
return;
|
|
1816
|
+
visitedNode.visited = true;
|
|
1817
|
+
selectionSet.selections.forEach(function (selection) {
|
|
1818
|
+
if (!utilities.shouldInclude(selection, context.variables))
|
|
1819
|
+
return;
|
|
1820
|
+
var clientOnly = inheritedContext.clientOnly, deferred = inheritedContext.deferred;
|
|
1821
|
+
if (!(clientOnly && deferred) &&
|
|
1822
|
+
utilities.isNonEmptyArray(selection.directives)) {
|
|
1823
|
+
selection.directives.forEach(function (dir) {
|
|
1824
|
+
var name = dir.name.value;
|
|
1825
|
+
if (name === "client")
|
|
1826
|
+
clientOnly = true;
|
|
1827
|
+
if (name === "defer") {
|
|
1828
|
+
var args = utilities.argumentsObjectFromField(dir, context.variables);
|
|
1829
|
+
if (!args || args.if !== false) {
|
|
1830
|
+
deferred = true;
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
if (utilities.isField(selection)) {
|
|
1836
|
+
var existing = fieldMap.get(selection);
|
|
1837
|
+
if (existing) {
|
|
1838
|
+
clientOnly = clientOnly && existing.clientOnly;
|
|
1839
|
+
deferred = deferred && existing.deferred;
|
|
1790
1840
|
}
|
|
1841
|
+
fieldMap.set(selection, getContextFlavor(context, clientOnly, deferred));
|
|
1791
1842
|
}
|
|
1792
|
-
|
|
1793
|
-
var
|
|
1794
|
-
|
|
1795
|
-
|
|
1843
|
+
else {
|
|
1844
|
+
var fragment = utilities.getFragmentFromSelection(selection, context.fragmentMap);
|
|
1845
|
+
if (fragment &&
|
|
1846
|
+
policies.fragmentMatches(fragment, typename, result, context.variables)) {
|
|
1847
|
+
flatten(fragment.selectionSet, getContextFlavor(context, clientOnly, deferred));
|
|
1848
|
+
}
|
|
1796
1849
|
}
|
|
1850
|
+
});
|
|
1851
|
+
})(selectionSet, context);
|
|
1852
|
+
return fieldMap;
|
|
1853
|
+
};
|
|
1854
|
+
StoreWriter.prototype.applyMerges = function (mergeTree, existing, incoming, context, getStorageArgs) {
|
|
1855
|
+
var _a;
|
|
1856
|
+
var _this = this;
|
|
1857
|
+
if (mergeTree.map.size && !utilities.isReference(incoming)) {
|
|
1858
|
+
var e_1 = (!Array.isArray(incoming) &&
|
|
1859
|
+
(utilities.isReference(existing) || storeValueIsStoreObject(existing))) ? existing : void 0;
|
|
1860
|
+
var i_1 = incoming;
|
|
1861
|
+
if (e_1 && !getStorageArgs) {
|
|
1862
|
+
getStorageArgs = [utilities.isReference(e_1) ? e_1.__ref : e_1];
|
|
1797
1863
|
}
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1864
|
+
var changedFields_1;
|
|
1865
|
+
var getValue_1 = function (from, name) {
|
|
1866
|
+
return Array.isArray(from)
|
|
1867
|
+
? (typeof name === "number" ? from[name] : void 0)
|
|
1868
|
+
: context.store.getFieldValue(from, String(name));
|
|
1869
|
+
};
|
|
1870
|
+
mergeTree.map.forEach(function (childTree, storeFieldName) {
|
|
1871
|
+
var eVal = getValue_1(e_1, storeFieldName);
|
|
1872
|
+
var iVal = getValue_1(i_1, storeFieldName);
|
|
1873
|
+
if (void 0 === iVal)
|
|
1874
|
+
return;
|
|
1875
|
+
if (getStorageArgs) {
|
|
1876
|
+
getStorageArgs.push(storeFieldName);
|
|
1877
|
+
}
|
|
1878
|
+
var aVal = _this.applyMerges(childTree, eVal, iVal, context, getStorageArgs);
|
|
1879
|
+
if (aVal !== iVal) {
|
|
1880
|
+
changedFields_1 = changedFields_1 || new Map;
|
|
1881
|
+
changedFields_1.set(storeFieldName, aVal);
|
|
1882
|
+
}
|
|
1883
|
+
if (getStorageArgs) {
|
|
1884
|
+
globals.invariant(getStorageArgs.pop() === storeFieldName);
|
|
1802
1885
|
}
|
|
1886
|
+
});
|
|
1887
|
+
if (changedFields_1) {
|
|
1888
|
+
incoming = (Array.isArray(i_1) ? i_1.slice(0) : tslib.__assign({}, i_1));
|
|
1889
|
+
changedFields_1.forEach(function (value, name) {
|
|
1890
|
+
incoming[name] = value;
|
|
1891
|
+
});
|
|
1803
1892
|
}
|
|
1893
|
+
}
|
|
1894
|
+
if (mergeTree.info) {
|
|
1895
|
+
return this.cache.policies.runMergeFunction(existing, incoming, mergeTree.info, context, getStorageArgs && (_a = context.store).getStorage.apply(_a, getStorageArgs));
|
|
1896
|
+
}
|
|
1897
|
+
return incoming;
|
|
1898
|
+
};
|
|
1899
|
+
return StoreWriter;
|
|
1900
|
+
}());
|
|
1901
|
+
var emptyMergeTreePool = [];
|
|
1902
|
+
function getChildMergeTree(_a, name) {
|
|
1903
|
+
var map = _a.map;
|
|
1904
|
+
if (!map.has(name)) {
|
|
1905
|
+
map.set(name, emptyMergeTreePool.pop() || { map: new Map });
|
|
1906
|
+
}
|
|
1907
|
+
return map.get(name);
|
|
1908
|
+
}
|
|
1909
|
+
function mergeMergeTrees(left, right) {
|
|
1910
|
+
if (left === right || !right || mergeTreeIsEmpty(right))
|
|
1911
|
+
return left;
|
|
1912
|
+
if (!left || mergeTreeIsEmpty(left))
|
|
1913
|
+
return right;
|
|
1914
|
+
var info = left.info && right.info ? tslib.__assign(tslib.__assign({}, left.info), right.info) : left.info || right.info;
|
|
1915
|
+
var needToMergeMaps = left.map.size && right.map.size;
|
|
1916
|
+
var map = needToMergeMaps ? new Map :
|
|
1917
|
+
left.map.size ? left.map : right.map;
|
|
1918
|
+
var merged = { info: info, map: map };
|
|
1919
|
+
if (needToMergeMaps) {
|
|
1920
|
+
var remainingRightKeys_1 = new Set(right.map.keys());
|
|
1921
|
+
left.map.forEach(function (leftTree, key) {
|
|
1922
|
+
merged.map.set(key, mergeMergeTrees(leftTree, right.map.get(key)));
|
|
1923
|
+
remainingRightKeys_1.delete(key);
|
|
1804
1924
|
});
|
|
1805
|
-
|
|
1806
|
-
|
|
1925
|
+
remainingRightKeys_1.forEach(function (key) {
|
|
1926
|
+
merged.map.set(key, mergeMergeTrees(right.map.get(key), left.map.get(key)));
|
|
1927
|
+
});
|
|
1928
|
+
}
|
|
1929
|
+
return merged;
|
|
1807
1930
|
}
|
|
1808
|
-
function
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1931
|
+
function mergeTreeIsEmpty(tree) {
|
|
1932
|
+
return !tree || !(tree.info || tree.map.size);
|
|
1933
|
+
}
|
|
1934
|
+
function maybeRecycleChildMergeTree(_a, name) {
|
|
1935
|
+
var map = _a.map;
|
|
1936
|
+
var childTree = map.get(name);
|
|
1937
|
+
if (childTree && mergeTreeIsEmpty(childTree)) {
|
|
1938
|
+
emptyMergeTreePool.push(childTree);
|
|
1939
|
+
map.delete(name);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
var warnings = new Set();
|
|
1943
|
+
function warnAboutDataLoss(existingRef, incomingObj, storeFieldName, store) {
|
|
1944
|
+
var getChild = function (objOrRef) {
|
|
1945
|
+
var child = store.getFieldValue(objOrRef, storeFieldName);
|
|
1946
|
+
return typeof child === "object" && child;
|
|
1947
|
+
};
|
|
1948
|
+
var existing = getChild(existingRef);
|
|
1949
|
+
if (!existing)
|
|
1950
|
+
return;
|
|
1951
|
+
var incoming = getChild(incomingObj);
|
|
1952
|
+
if (!incoming)
|
|
1953
|
+
return;
|
|
1954
|
+
if (utilities.isReference(existing))
|
|
1955
|
+
return;
|
|
1956
|
+
if (equality.equal(existing, incoming))
|
|
1957
|
+
return;
|
|
1958
|
+
if (Object.keys(existing).every(function (key) { return store.getFieldValue(incoming, key) !== void 0; })) {
|
|
1959
|
+
return;
|
|
1960
|
+
}
|
|
1961
|
+
var parentType = store.getFieldValue(existingRef, "__typename") ||
|
|
1962
|
+
store.getFieldValue(incomingObj, "__typename");
|
|
1963
|
+
var fieldName = fieldNameFromStoreName(storeFieldName);
|
|
1964
|
+
var typeDotName = "".concat(parentType, ".").concat(fieldName);
|
|
1965
|
+
if (warnings.has(typeDotName))
|
|
1966
|
+
return;
|
|
1967
|
+
warnings.add(typeDotName);
|
|
1968
|
+
var childTypenames = [];
|
|
1969
|
+
if (!Array.isArray(existing) &&
|
|
1970
|
+
!Array.isArray(incoming)) {
|
|
1971
|
+
[existing, incoming].forEach(function (child) {
|
|
1972
|
+
var typename = store.getFieldValue(child, "__typename");
|
|
1973
|
+
if (typeof typename === "string" &&
|
|
1974
|
+
!childTypenames.includes(typename)) {
|
|
1975
|
+
childTypenames.push(typename);
|
|
1831
1976
|
}
|
|
1832
|
-
}
|
|
1833
|
-
}
|
|
1834
|
-
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
__DEV__ && globals.invariant.warn("Cache data may be lost when replacing the ".concat(fieldName, " field of a ").concat(parentType, " object.\n\nTo address this problem (which is not a bug in Apollo Client), ").concat(childTypenames.length
|
|
1980
|
+
? "either ensure all objects of type " +
|
|
1981
|
+
childTypenames.join(" and ") + " have an ID or a custom merge function, or "
|
|
1982
|
+
: "", "define a custom merge function for the ").concat(typeDotName, " field, so InMemoryCache can safely merge these objects:\n\n existing: ").concat(JSON.stringify(existing).slice(0, 1000), "\n incoming: ").concat(JSON.stringify(incoming).slice(0, 1000), "\n\nFor more information about these options, please refer to the documentation:\n\n * Ensuring entity objects have IDs: https://go.apollo.dev/c/generating-unique-identifiers\n * Defining custom merge functions: https://go.apollo.dev/c/merging-non-normalized-objects\n"));
|
|
1835
1983
|
}
|
|
1836
1984
|
|
|
1837
1985
|
var InMemoryCache = (function (_super) {
|
|
@@ -1980,8 +2128,14 @@ var InMemoryCache = (function (_super) {
|
|
|
1980
2128
|
return (optimistic ? this.optimisticData : this.data).release(rootId);
|
|
1981
2129
|
};
|
|
1982
2130
|
InMemoryCache.prototype.identify = function (object) {
|
|
1983
|
-
|
|
1984
|
-
|
|
2131
|
+
if (utilities.isReference(object))
|
|
2132
|
+
return object.__ref;
|
|
2133
|
+
try {
|
|
2134
|
+
return this.policies.identify(object)[0];
|
|
2135
|
+
}
|
|
2136
|
+
catch (e) {
|
|
2137
|
+
__DEV__ && globals.invariant.warn(e);
|
|
2138
|
+
}
|
|
1985
2139
|
};
|
|
1986
2140
|
InMemoryCache.prototype.evict = function (options) {
|
|
1987
2141
|
if (!options.id) {
|
|
@@ -2024,6 +2178,7 @@ var InMemoryCache = (function (_super) {
|
|
|
2024
2178
|
InMemoryCache.prototype.batch = function (options) {
|
|
2025
2179
|
var _this = this;
|
|
2026
2180
|
var update = options.update, _a = options.optimistic, optimistic = _a === void 0 ? true : _a, removeOptimistic = options.removeOptimistic, onWatchUpdated = options.onWatchUpdated;
|
|
2181
|
+
var updateResult;
|
|
2027
2182
|
var perform = function (layer) {
|
|
2028
2183
|
var _a = _this, data = _a.data, optimisticData = _a.optimisticData;
|
|
2029
2184
|
++_this.txCount;
|
|
@@ -2031,7 +2186,7 @@ var InMemoryCache = (function (_super) {
|
|
|
2031
2186
|
_this.data = _this.optimisticData = layer;
|
|
2032
2187
|
}
|
|
2033
2188
|
try {
|
|
2034
|
-
update(_this);
|
|
2189
|
+
return updateResult = update(_this);
|
|
2035
2190
|
}
|
|
2036
2191
|
finally {
|
|
2037
2192
|
--_this.txCount;
|
|
@@ -2073,6 +2228,7 @@ var InMemoryCache = (function (_super) {
|
|
|
2073
2228
|
else {
|
|
2074
2229
|
this.broadcastWatches(options);
|
|
2075
2230
|
}
|
|
2231
|
+
return updateResult;
|
|
2076
2232
|
};
|
|
2077
2233
|
InMemoryCache.prototype.performTransaction = function (update, optimisticId) {
|
|
2078
2234
|
return this.batch({
|
|
@@ -2129,4 +2285,4 @@ exports.canonicalStringify = canonicalStringify;
|
|
|
2129
2285
|
exports.defaultDataIdFromObject = defaultDataIdFromObject;
|
|
2130
2286
|
exports.fieldNameFromStoreName = fieldNameFromStoreName;
|
|
2131
2287
|
exports.makeVar = makeVar;
|
|
2132
|
-
//# sourceMappingURL=cache.cjs.
|
|
2288
|
+
//# sourceMappingURL=cache.cjs.map
|