@apollo/client 4.3.0-alpha.0 → 4.3.0-alpha.10
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/CHANGELOG.md +490 -0
- package/README.md +3 -7
- package/__cjs/cache/core/Scalar.cjs +36 -0
- package/__cjs/cache/core/Scalar.cjs.map +1 -0
- package/__cjs/cache/core/Scalar.d.cts +20 -0
- package/__cjs/cache/core/cache.cjs +32 -1
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +89 -6
- package/__cjs/cache/core/types/Cache.d.cts +25 -0
- package/__cjs/cache/index.cjs +3 -1
- package/__cjs/cache/index.cjs.map +1 -1
- package/__cjs/cache/index.d.cts +3 -2
- package/__cjs/cache/inmemory/entityStore.cjs +48 -5
- package/__cjs/cache/inmemory/entityStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/entityStore.d.cts +3 -0
- package/__cjs/cache/inmemory/helpers.d.cts +9 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs +83 -4
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +44 -5
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +35 -6
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/policies.d.cts +4 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +490 -49
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.d.cts +11 -2
- package/__cjs/cache/inmemory/types.d.cts +29 -4
- package/__cjs/cache/inmemory/writeToStore.cjs +6 -6
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +37 -38
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +44 -10
- package/__cjs/core/ObservableQuery.cjs +228 -76
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +16 -8
- package/__cjs/core/QueryInfo.cjs +178 -190
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +17 -22
- package/__cjs/core/QueryManager.cjs +88 -59
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +1 -3
- package/__cjs/core/RefetchEventManager.cjs +3 -3
- package/__cjs/core/dataStateErrorCache.cjs +12 -0
- package/__cjs/core/dataStateErrorCache.cjs.map +1 -0
- package/__cjs/core/dataStateErrorCache.d.cts +3 -0
- package/__cjs/core/index.cjs +2 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +4 -3
- package/__cjs/core/types.d.cts +12 -6
- package/__cjs/incremental/GraphQLCodegenIncremental.cjs +3 -0
- package/__cjs/incremental/GraphQLCodegenIncremental.cjs.map +1 -0
- package/__cjs/incremental/GraphQLCodegenIncremental.d.cts +55 -0
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +2 -4
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +47 -16
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/graphql17Alpha9.d.cts +29 -6
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/index.cjs.map +1 -1
- package/__cjs/incremental/index.d.cts +1 -0
- package/__cjs/incremental/internal/types.cjs +3 -0
- package/__cjs/incremental/internal/types.cjs.map +1 -0
- package/__cjs/incremental/internal/types.d.cts +17 -0
- package/__cjs/incremental/types.d.cts +55 -4
- package/__cjs/invariantErrorCodes.cjs +167 -112
- package/__cjs/link/core/ApolloLink.cjs +3 -3
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +2 -2
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/ws/index.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +11 -11
- package/__cjs/masking/internal/types.d.cts +1 -2
- package/__cjs/masking/maskDefinition.cjs +2 -2
- package/__cjs/masking/maskFragment.cjs +2 -2
- package/__cjs/masking/maskOperation.cjs +1 -1
- package/__cjs/masking/utils.cjs +3 -3
- package/__cjs/react/context/ApolloContext.cjs +1 -1
- package/__cjs/react/context/ApolloProvider.cjs +1 -1
- package/__cjs/react/hooks/internal/validateSuspenseHookOptions.cjs +2 -2
- package/__cjs/react/hooks/useApolloClient.cjs +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +100 -47
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +39 -33
- package/__cjs/react/hooks/useLoadableQuery.cjs +2 -2
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +23 -15
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +10 -7
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +74 -32
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +83 -34
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/types.d.cts +14 -3
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +20 -5
- package/__cjs/react/ssr/prerenderStatic.cjs +2 -2
- package/__cjs/react/types/deprecated.d.cts +5 -4
- package/__cjs/testing/core/mocking/mockLink.cjs +25 -5
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +1 -2
- package/__cjs/utilities/caching/sizes.cjs.map +1 -1
- package/__cjs/utilities/caching/sizes.d.cts +39 -1
- package/__cjs/utilities/graphql/DocumentTransform.cjs +1 -1
- package/__cjs/utilities/index.cjs.map +1 -1
- package/__cjs/utilities/index.d.cts +1 -0
- package/__cjs/utilities/internal/StreamArrayState.cjs +27 -0
- package/__cjs/utilities/internal/StreamArrayState.cjs.map +1 -0
- package/__cjs/utilities/internal/StreamArrayState.d.cts +12 -0
- package/__cjs/utilities/internal/addDeferFragmentLabels.cjs +33 -0
- package/__cjs/utilities/internal/addDeferFragmentLabels.cjs.map +1 -0
- package/__cjs/utilities/internal/addDeferFragmentLabels.d.cts +3 -0
- package/__cjs/utilities/internal/capitalize.cjs +12 -0
- package/__cjs/utilities/internal/capitalize.cjs.map +1 -0
- package/__cjs/utilities/internal/capitalize.d.cts +7 -0
- package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs +69 -0
- package/__cjs/utilities/internal/coerceScalarFieldsToParsed.cjs.map +1 -0
- package/__cjs/utilities/internal/coerceScalarFieldsToParsed.d.cts +9 -0
- package/__cjs/utilities/internal/constants.cjs +20 -1
- package/__cjs/utilities/internal/constants.cjs.map +1 -1
- package/__cjs/utilities/internal/constants.d.cts +19 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.cjs +19 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.cjs.map +1 -0
- package/__cjs/utilities/internal/getDirectiveArgValue.d.cts +9 -0
- package/__cjs/utilities/internal/getFragmentDefinition.cjs +3 -3
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +2 -2
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +2 -2
- package/__cjs/utilities/internal/getMainDefinition.cjs +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.cjs +6 -0
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.d.cts +4 -0
- package/__cjs/utilities/internal/getQueryDefinition.cjs +1 -1
- package/__cjs/utilities/internal/getUnwrappedType.cjs +20 -0
- package/__cjs/utilities/internal/getUnwrappedType.cjs.map +1 -0
- package/__cjs/utilities/internal/getUnwrappedType.d.cts +8 -0
- package/__cjs/utilities/internal/index.cjs +25 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +16 -1
- package/__cjs/utilities/internal/isDeferredFragment.cjs +38 -0
- package/__cjs/utilities/internal/isDeferredFragment.cjs.map +1 -0
- package/__cjs/utilities/internal/isDeferredFragment.d.cts +9 -0
- package/__cjs/utilities/internal/isStreamField.cjs +37 -0
- package/__cjs/utilities/internal/isStreamField.cjs.map +1 -0
- package/__cjs/utilities/internal/isStreamField.d.cts +9 -0
- package/__cjs/utilities/internal/isTypenameField.cjs +7 -0
- package/__cjs/utilities/internal/isTypenameField.cjs.map +1 -0
- package/__cjs/utilities/internal/isTypenameField.d.cts +3 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs +17 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.cjs.map +1 -0
- package/__cjs/utilities/internal/makeStreamInfoTrie.d.cts +8 -0
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +1 -1
- package/__cjs/utilities/internal/shouldInclude.cjs +4 -4
- package/__cjs/utilities/internal/toDiffWithDataState.cjs +20 -0
- package/__cjs/utilities/internal/toDiffWithDataState.cjs.map +1 -0
- package/__cjs/utilities/internal/toDiffWithDataState.d.cts +8 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs +3 -0
- package/__cjs/utilities/internal/types/DeferInfo.cjs.map +1 -0
- package/__cjs/utilities/internal/types/DeferInfo.d.cts +10 -0
- package/__cjs/utilities/internal/types/Exact.cjs +3 -0
- package/__cjs/utilities/internal/types/Exact.cjs.map +1 -0
- package/__cjs/utilities/internal/types/Exact.d.cts +2 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.cjs +3 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.cjs.map +1 -0
- package/__cjs/utilities/internal/types/IsLooselyEqual.d.cts +10 -0
- package/__cjs/utilities/internal/types/IsNeverish.cjs +3 -0
- package/__cjs/utilities/internal/types/IsNeverish.cjs.map +1 -0
- package/__cjs/utilities/internal/types/IsNeverish.d.cts +4 -0
- package/__cjs/utilities/internal/types/StreamInfoTrie.d.cts +2 -0
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +1 -1
- package/__cjs/utilities/policies/pagination.cjs.map +1 -1
- package/__cjs/utilities/policies/pagination.d.cts +1 -1
- package/__cjs/utilities/subscriptions/relay/index.cjs +1 -0
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/__cjs/version.cjs.map +1 -1
- package/cache/core/Scalar.d.ts +20 -0
- package/cache/core/Scalar.js +32 -0
- package/cache/core/Scalar.js.map +1 -0
- package/cache/core/cache.d.ts +89 -6
- package/cache/core/cache.js +33 -2
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +25 -0
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/index.d.ts +3 -2
- package/cache/index.js +1 -0
- package/cache/index.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +3 -0
- package/cache/inmemory/entityStore.js +49 -6
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/helpers.d.ts +9 -1
- package/cache/inmemory/inMemoryCache.d.ts +44 -5
- package/cache/inmemory/inMemoryCache.js +84 -5
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.d.ts +4 -1
- package/cache/inmemory/policies.js +35 -6
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +11 -2
- package/cache/inmemory/readFromStore.js +486 -49
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +30 -5
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +7 -7
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +44 -10
- package/core/ApolloClient.js +37 -38
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +16 -8
- package/core/ObservableQuery.js +225 -77
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +18 -23
- package/core/QueryInfo.js +174 -190
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +1 -3
- package/core/QueryManager.js +89 -60
- package/core/QueryManager.js.map +1 -1
- package/core/RefetchEventManager.js +3 -3
- package/core/dataStateErrorCache.d.ts +3 -0
- package/core/dataStateErrorCache.js +9 -0
- package/core/dataStateErrorCache.js.map +1 -0
- package/core/index.d.ts +4 -3
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +12 -6
- package/core/types.js.map +1 -1
- package/incremental/GraphQLCodegenIncremental.d.ts +55 -0
- package/incremental/GraphQLCodegenIncremental.js +2 -0
- package/incremental/GraphQLCodegenIncremental.js.map +1 -0
- package/incremental/handlers/defer20220824.d.ts +2 -4
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.d.ts +29 -6
- package/incremental/handlers/graphql17Alpha9.js +48 -17
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/index.d.ts +1 -0
- package/incremental/index.js.map +1 -1
- package/incremental/internal/types.d.ts +17 -0
- package/incremental/internal/types.js +2 -0
- package/incremental/internal/types.js.map +1 -0
- package/incremental/types.d.ts +55 -4
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +167 -112
- package/link/core/ApolloLink.js +3 -3
- package/link/http/checkFetcher.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +2 -2
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/ws/index.js +1 -1
- package/local-state/LocalState.js +11 -11
- package/masking/internal/types.d.ts +1 -2
- package/masking/internal/types.js.map +1 -1
- package/masking/maskDefinition.js +2 -2
- package/masking/maskFragment.js +2 -2
- package/masking/maskOperation.js +1 -1
- package/masking/utils.js +3 -3
- package/package.json +1 -1
- package/react/context/ApolloContext.js +1 -1
- package/react/context/ApolloProvider.js +1 -1
- package/react/hooks/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks/useApolloClient.js +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +100 -47
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +39 -33
- package/react/hooks/useLazyQuery.js +2 -2
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +23 -15
- package/react/hooks/useLoadableQuery.js +2 -2
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +10 -7
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +74 -32
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +83 -34
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/internal/validateSuspenseHookOptions.js +2 -2
- package/react/hooks-compiled/useApolloClient.js +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +100 -47
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +39 -33
- package/react/hooks-compiled/useLazyQuery.js +2 -2
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +23 -15
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +10 -7
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +74 -32
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +83 -34
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/internal/types.d.ts +15 -4
- package/react/internal/types.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +20 -5
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/ssr/prerenderStatic.js +2 -2
- package/react/types/deprecated.d.ts +5 -4
- package/react/types/deprecated.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +1 -2
- package/testing/core/mocking/mockLink.js +25 -5
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/caching/sizes.d.ts +39 -1
- package/utilities/caching/sizes.js.map +1 -1
- package/utilities/graphql/DocumentTransform.js +1 -1
- package/utilities/index.d.ts +1 -0
- package/utilities/index.js.map +1 -1
- package/utilities/internal/StreamArrayState.d.ts +12 -0
- package/utilities/internal/StreamArrayState.js +23 -0
- package/utilities/internal/StreamArrayState.js.map +1 -0
- package/utilities/internal/addDeferFragmentLabels.d.ts +3 -0
- package/utilities/internal/addDeferFragmentLabels.js +30 -0
- package/utilities/internal/addDeferFragmentLabels.js.map +1 -0
- package/utilities/internal/capitalize.d.ts +7 -0
- package/utilities/internal/capitalize.js +9 -0
- package/utilities/internal/capitalize.js.map +1 -0
- package/utilities/internal/coerceScalarFieldsToParsed.d.ts +9 -0
- package/utilities/internal/coerceScalarFieldsToParsed.js +66 -0
- package/utilities/internal/coerceScalarFieldsToParsed.js.map +1 -0
- package/utilities/internal/constants.d.ts +19 -0
- package/utilities/internal/constants.js +19 -0
- package/utilities/internal/constants.js.map +1 -1
- package/utilities/internal/getDirectiveArgValue.d.ts +9 -0
- package/utilities/internal/getDirectiveArgValue.js +16 -0
- package/utilities/internal/getDirectiveArgValue.js.map +1 -0
- package/utilities/internal/getFragmentDefinition.js +3 -3
- package/utilities/internal/getFragmentFromSelection.js +2 -2
- package/utilities/internal/getFragmentFromSelection.js.map +1 -1
- package/utilities/internal/getFragmentQueryDocument.js +2 -2
- package/utilities/internal/getMainDefinition.js +1 -1
- package/utilities/internal/getMemoryInternals.d.ts +4 -0
- package/utilities/internal/getMemoryInternals.js +6 -0
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/getQueryDefinition.js +1 -1
- package/utilities/internal/getUnwrappedType.d.ts +8 -0
- package/utilities/internal/getUnwrappedType.js +17 -0
- package/utilities/internal/getUnwrappedType.js.map +1 -0
- package/utilities/internal/index.d.ts +16 -1
- package/utilities/internal/index.js +12 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isDeferredFragment.d.ts +9 -0
- package/utilities/internal/isDeferredFragment.js +35 -0
- package/utilities/internal/isDeferredFragment.js.map +1 -0
- package/utilities/internal/isStreamField.d.ts +9 -0
- package/utilities/internal/isStreamField.js +34 -0
- package/utilities/internal/isStreamField.js.map +1 -0
- package/utilities/internal/isTypenameField.d.ts +3 -0
- package/utilities/internal/isTypenameField.js +4 -0
- package/utilities/internal/isTypenameField.js.map +1 -0
- package/utilities/internal/makeStreamInfoTrie.d.ts +8 -0
- package/utilities/internal/makeStreamInfoTrie.js +14 -0
- package/utilities/internal/makeStreamInfoTrie.js.map +1 -0
- package/utilities/internal/removeDirectivesFromDocument.js +1 -1
- package/utilities/internal/shouldInclude.js +4 -4
- package/utilities/internal/toDiffWithDataState.d.ts +8 -0
- package/utilities/internal/toDiffWithDataState.js +17 -0
- package/utilities/internal/toDiffWithDataState.js.map +1 -0
- package/utilities/internal/types/DeferInfo.d.ts +10 -0
- package/utilities/internal/types/DeferInfo.js +2 -0
- package/utilities/internal/types/DeferInfo.js.map +1 -0
- package/utilities/internal/types/Exact.d.ts +2 -0
- package/utilities/internal/types/Exact.js +2 -0
- package/utilities/internal/types/Exact.js.map +1 -0
- package/utilities/internal/types/IsLooselyEqual.d.ts +10 -0
- package/utilities/internal/types/IsLooselyEqual.js +2 -0
- package/utilities/internal/types/IsLooselyEqual.js.map +1 -0
- package/utilities/internal/types/IsNeverish.d.ts +4 -0
- package/utilities/internal/types/IsNeverish.js +2 -0
- package/utilities/internal/types/IsNeverish.js.map +1 -0
- package/utilities/internal/types/StreamInfoTrie.d.ts +2 -0
- package/utilities/internal/types/StreamInfoTrie.js.map +1 -1
- package/utilities/internal/valueToObjectRepresentation.js +1 -1
- package/utilities/policies/pagination.d.ts +1 -1
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/subscriptions/relay/index.js +1 -0
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";;
|
|
2
|
+
const {
|
|
3
|
+
__DEV__
|
|
4
|
+
} = require("@apollo/client/utilities/environment");
|
|
5
|
+
|
|
2
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
7
|
exports.StoreReader = void 0;
|
|
8
|
+
const equality_1 = require("@wry/equality");
|
|
9
|
+
const trie_1 = require("@wry/trie");
|
|
4
10
|
const graphql_1 = require("graphql");
|
|
5
11
|
const optimism_1 = require("optimism");
|
|
6
12
|
const utilities_1 = require("@apollo/client/utilities");
|
|
@@ -18,8 +24,11 @@ class StoreReader {
|
|
|
18
24
|
executeSelectionSet;
|
|
19
25
|
// cached version of executeSubSelectedArray
|
|
20
26
|
executeSubSelectedArray;
|
|
27
|
+
prunePartialStreamArray;
|
|
28
|
+
prunePartialBoundaries;
|
|
21
29
|
config;
|
|
22
30
|
knownResults = new WeakMap();
|
|
31
|
+
keyMaker = new trie_1.Trie();
|
|
23
32
|
constructor(config) {
|
|
24
33
|
this.config = config;
|
|
25
34
|
// memoized functions in this class will be "garbage-collected"
|
|
@@ -62,47 +71,124 @@ class StoreReader {
|
|
|
62
71
|
}
|
|
63
72
|
},
|
|
64
73
|
});
|
|
74
|
+
this.prunePartialBoundaries = (0, optimism_1.wrap)((options) => this.prunePartialBoundariesImpl(options), {
|
|
75
|
+
max: utilities_1.cacheSizes["inMemoryCache.prunePartialBoundaries"] ||
|
|
76
|
+
20000 /* defaultCacheSizes["inMemoryCache.prunePartialBoundaries"] */,
|
|
77
|
+
makeCacheKey: ({ boundaries, context, selectionSet }) => {
|
|
78
|
+
if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
|
|
79
|
+
return this.keyMaker.lookup(selectionSet, boundaries, context.streamInfo, context.deferInfo);
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
this.prunePartialStreamArray = (0, optimism_1.wrap)((options) => {
|
|
84
|
+
const { field, context, path } = options;
|
|
85
|
+
if ((0, internal_1.isStreamField)(field, context.variables)) {
|
|
86
|
+
context.streamInfo?.lookupArray(path).state.depend();
|
|
87
|
+
}
|
|
88
|
+
return this.prunePartialStreamArrayImpl(options);
|
|
89
|
+
}, {
|
|
90
|
+
max: utilities_1.cacheSizes["inMemoryCache.prunePartialStreamArray"] ||
|
|
91
|
+
20000 /* defaultCacheSizes["inMemoryCache.prunePartialStreamArray"] */,
|
|
92
|
+
makeCacheKey: ({ field, context, boundaries }) => {
|
|
93
|
+
if ((0, entityStore_js_1.supportsResultCaching)(context.store)) {
|
|
94
|
+
return this.keyMaker.lookup(field, boundaries, context.streamInfo, context.deferInfo);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
65
98
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* identify if any data was missing from the store.
|
|
69
|
-
*/
|
|
70
|
-
diffQueryAgainstStore({ store, query, rootId = "ROOT_QUERY", variables, returnPartialData = true, }) {
|
|
99
|
+
diffQueryAgainstStore({ store, query, rootId = "ROOT_QUERY", variables, returnPartialData = true, ...options }) {
|
|
100
|
+
const returnIncremental = Object.hasOwn(options, internal_1.handleIncrementalSymbol);
|
|
71
101
|
const policies = this.config.cache.policies;
|
|
72
|
-
variables =
|
|
73
|
-
...(0, internal_1.getDefaultValues)((0, internal_1.getQueryDefinition)(query)),
|
|
74
|
-
...variables,
|
|
75
|
-
};
|
|
102
|
+
variables = (0, internal_1.compact)((0, internal_1.getDefaultValues)((0, internal_1.getQueryDefinition)(query)), variables);
|
|
76
103
|
const rootRef = (0, internal_1.makeReference)(rootId);
|
|
77
|
-
const
|
|
104
|
+
const context = {
|
|
105
|
+
store,
|
|
106
|
+
query,
|
|
107
|
+
policies,
|
|
108
|
+
variables,
|
|
109
|
+
varString: (0, utilities_1.canonicalStringify)(variables),
|
|
110
|
+
...(0, helpers_js_1.extractFragmentContext)(query, this.config.fragments),
|
|
111
|
+
...options[internal_1.handleIncrementalSymbol],
|
|
112
|
+
};
|
|
113
|
+
let execResult = this.executeSelectionSet({
|
|
78
114
|
selectionSet: (0, internal_1.getMainDefinition)(query).selectionSet,
|
|
79
115
|
objectOrReference: rootRef,
|
|
80
116
|
enclosingRef: rootRef,
|
|
81
|
-
context
|
|
82
|
-
store,
|
|
83
|
-
query,
|
|
84
|
-
policies,
|
|
85
|
-
variables,
|
|
86
|
-
varString: (0, utilities_1.canonicalStringify)(variables),
|
|
87
|
-
...(0, helpers_js_1.extractFragmentContext)(query, this.config.fragments),
|
|
88
|
-
},
|
|
117
|
+
context,
|
|
89
118
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
119
|
+
// Since executeSelectionSet doesn't know about returnPartialData, we need
|
|
120
|
+
// to perform a 2nd pass over the result to prune any fields inside
|
|
121
|
+
// partial defer boundaries. The "deferPartial" data state tells us that the
|
|
122
|
+
// only part of the result that contributed to its partiality is data inside
|
|
123
|
+
// a defer boundary.
|
|
124
|
+
if (returnIncremental && shouldPrune(execResult, context)) {
|
|
125
|
+
const pruned = this.prunePartialBoundaries({
|
|
126
|
+
selectionSet: (0, internal_1.getMainDefinition)(query).selectionSet,
|
|
127
|
+
data: execResult.result,
|
|
128
|
+
boundaries: execResult.partialBoundaries,
|
|
129
|
+
context,
|
|
130
|
+
path: [],
|
|
131
|
+
});
|
|
132
|
+
const changed = execResult.result !== pruned.result;
|
|
133
|
+
// It's possible that pruning didn't actually change the result which can
|
|
134
|
+
// happen if a defer boundary is misclassified as "deferPartial" instead
|
|
135
|
+
// of "streaming" (sibling defer boundaries with overlapping selection
|
|
136
|
+
// sets, one of which is complete). In this case, pruning corrects the
|
|
137
|
+
// dataState to streaming instead of leaving it as partial. If we tolerate
|
|
138
|
+
// partial results and pruning changed the result by dropping fields, then
|
|
139
|
+
// we want to keep the original execResult which contains the partial
|
|
140
|
+
// data.
|
|
141
|
+
if (!changed || !returnPartialData) {
|
|
142
|
+
// Omit `missing` property since pruning puts it in a state that doesn't
|
|
143
|
+
// report missing fields.
|
|
144
|
+
execResult = {
|
|
145
|
+
result: pruned.result,
|
|
146
|
+
partialBoundaries: execResult.partialBoundaries,
|
|
147
|
+
dataState: pruned.dataState,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
93
150
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
151
|
+
let { result, dataState, missing } = execResult;
|
|
152
|
+
// Evaluate this condition before we start mucking with dataState for the
|
|
153
|
+
// publicly returned value
|
|
154
|
+
const includeMissing = !!missing &&
|
|
155
|
+
// We don't need to report missing fields inside defer boundaries since
|
|
156
|
+
// the "streaming" dataState tells us that the only missing fields in
|
|
157
|
+
// the object is inside a defer boundary.
|
|
158
|
+
(dataState !== "streaming" || !returnIncremental);
|
|
159
|
+
// If we get all root @defer boundaries with an empty result, report it as
|
|
160
|
+
// empty instead of streaming.
|
|
161
|
+
if (dataState === "streaming" && Object.keys(result).length === 0) {
|
|
162
|
+
dataState = "empty";
|
|
163
|
+
}
|
|
164
|
+
let missingError;
|
|
165
|
+
if (dataState === "deferPartial" ||
|
|
166
|
+
dataState === "streamPartial" ||
|
|
167
|
+
(dataState === "streaming" && !returnIncremental)) {
|
|
168
|
+
dataState = "partial";
|
|
169
|
+
}
|
|
170
|
+
if (dataState === "partial" && !returnPartialData) {
|
|
171
|
+
dataState = "empty";
|
|
172
|
+
}
|
|
173
|
+
const complete = dataState === "complete";
|
|
174
|
+
const keepResult = complete ||
|
|
175
|
+
dataState === "streaming" ||
|
|
176
|
+
(returnPartialData && Object.keys(result).length);
|
|
177
|
+
const diffResult = {
|
|
178
|
+
result: keepResult ? result : null,
|
|
103
179
|
complete,
|
|
104
|
-
missing
|
|
180
|
+
get missing() {
|
|
181
|
+
if (includeMissing) {
|
|
182
|
+
missingError ||= new common_js_1.MissingFieldError(firstMissing(missing), missing, query, variables);
|
|
183
|
+
}
|
|
184
|
+
return missingError;
|
|
185
|
+
},
|
|
105
186
|
};
|
|
187
|
+
if (returnIncremental) {
|
|
188
|
+
diffResult.dataState =
|
|
189
|
+
dataState;
|
|
190
|
+
}
|
|
191
|
+
return diffResult;
|
|
106
192
|
}
|
|
107
193
|
isFresh(result, parent, selectionSet, context) {
|
|
108
194
|
if ((0, entityStore_js_1.supportsResultCaching)(context.store) &&
|
|
@@ -121,14 +207,18 @@ class StoreReader {
|
|
|
121
207
|
!context.store.has(objectOrReference.__ref)) {
|
|
122
208
|
return {
|
|
123
209
|
result: {},
|
|
210
|
+
dataState: "empty",
|
|
124
211
|
missing: `Dangling reference to missing ${objectOrReference.__ref} object`,
|
|
212
|
+
partialBoundaries: new PartialBoundaries(),
|
|
125
213
|
};
|
|
126
214
|
}
|
|
127
215
|
const { variables, policies, store } = context;
|
|
128
216
|
const typename = store.getFieldValue(objectOrReference, "__typename");
|
|
129
217
|
const objectsToMerge = [];
|
|
218
|
+
let dataState;
|
|
130
219
|
let missing;
|
|
131
220
|
const missingMerger = new internal_1.DeepMerger();
|
|
221
|
+
const partialBoundaries = new PartialBoundaries();
|
|
132
222
|
if (typeof typename === "string" && !policies.rootIdsByTypename[typename]) {
|
|
133
223
|
// Ensure we always include a default value for the __typename
|
|
134
224
|
// field, if we have one. Note that this field can be overridden by other
|
|
@@ -141,7 +231,7 @@ class StoreReader {
|
|
|
141
231
|
[resultName]: result.missing,
|
|
142
232
|
});
|
|
143
233
|
}
|
|
144
|
-
return result
|
|
234
|
+
return result;
|
|
145
235
|
}
|
|
146
236
|
const workSet = new Set(selectionSet.selections);
|
|
147
237
|
workSet.forEach((selection) => {
|
|
@@ -159,36 +249,75 @@ class StoreReader {
|
|
|
159
249
|
const resultName = (0, internal_1.resultKeyNameFromField)(selection);
|
|
160
250
|
if (fieldValue === void 0) {
|
|
161
251
|
if (!utilities_1.addTypenameToDocument.added(selection)) {
|
|
252
|
+
const id = (0, utilities_1.isReference)(objectOrReference) ? objectOrReference.__ref
|
|
253
|
+
: objectOrReference ? policies.identify(objectOrReference)[0]
|
|
254
|
+
: undefined;
|
|
162
255
|
missing = missingMerger.merge(missing, {
|
|
163
|
-
[resultName]: `Can't find field '${selection.name.value}' on ${
|
|
164
|
-
|
|
165
|
-
:
|
|
256
|
+
[resultName]: `Can't find field '${selection.name.value}' on ${id ?
|
|
257
|
+
`${id} object`
|
|
258
|
+
: `object ${JSON.stringify(objectOrReference || {}, null, 2)}`}`,
|
|
166
259
|
});
|
|
260
|
+
dataState = mergeDataState(dataState, "empty");
|
|
167
261
|
}
|
|
168
262
|
}
|
|
169
263
|
else if ((0, internal_1.isArray)(fieldValue)) {
|
|
170
264
|
if (fieldValue.length > 0) {
|
|
171
|
-
|
|
265
|
+
const execResult = handleMissing(this.executeSubSelectedArray({
|
|
172
266
|
field: selection,
|
|
173
267
|
array: fieldValue,
|
|
174
268
|
enclosingRef,
|
|
175
269
|
context,
|
|
176
270
|
}), resultName);
|
|
271
|
+
fieldValue = execResult.result;
|
|
272
|
+
dataState = mergeDataState(dataState, execResult.dataState);
|
|
273
|
+
partialBoundaries.set(resultName, execResult.partialBoundaries);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
dataState = mergeDataState(dataState, "complete");
|
|
177
277
|
}
|
|
178
278
|
}
|
|
179
279
|
else if (!selection.selectionSet) {
|
|
180
|
-
//
|
|
280
|
+
// Auto-inserted __typename should not affect dataState (see empty
|
|
281
|
+
// @defer boundaries, which must stay "empty" → parent "streaming").
|
|
282
|
+
if (!utilities_1.addTypenameToDocument.added(selection)) {
|
|
283
|
+
dataState = mergeDataState(dataState, "complete");
|
|
284
|
+
}
|
|
181
285
|
}
|
|
182
286
|
else if (fieldValue != null) {
|
|
287
|
+
if (environment_1.__DEV__) {
|
|
288
|
+
const fieldName = selection.name.value;
|
|
289
|
+
if (typename) {
|
|
290
|
+
const policy = policies["getFieldPolicy"](typename, fieldName);
|
|
291
|
+
if (policy?.scalar) {
|
|
292
|
+
__DEV__ && invariant_1.invariant.warn(116, `${typename}.${fieldName}`, policy.scalar);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
183
296
|
// In this case, because we know the field has a selection set,
|
|
184
297
|
// it must be trying to query a GraphQLObjectType, which is why
|
|
185
298
|
// fieldValue must be != null.
|
|
186
|
-
|
|
299
|
+
const execResult = handleMissing(this.executeSelectionSet({
|
|
187
300
|
selectionSet: selection.selectionSet,
|
|
188
301
|
objectOrReference: fieldValue,
|
|
189
302
|
enclosingRef: (0, utilities_1.isReference)(fieldValue) ? fieldValue : enclosingRef,
|
|
190
303
|
context,
|
|
191
304
|
}), resultName);
|
|
305
|
+
fieldValue = execResult.result;
|
|
306
|
+
partialBoundaries.set(resultName, execResult.partialBoundaries);
|
|
307
|
+
// If the object's fields resolved to an "empty" dataState (e.g. no
|
|
308
|
+
// field resolved with a non-undefined value), but the fieldValue
|
|
309
|
+
// object itself is present, this object should be considered
|
|
310
|
+
// partial instead of empty. This also ensures defer boundaries that
|
|
311
|
+
// select this object remain as partial defer boundaries rather than
|
|
312
|
+
// mistakenly get reported as streaming. This is especially necessary
|
|
313
|
+
// when combined with GraphQL Codegen which generates its type and
|
|
314
|
+
// relies on the outer object to be absent when its fields haven't
|
|
315
|
+
// streamed in. Reporting the defer boundary as "streaming" instead of
|
|
316
|
+
// "partial" would otherwise have the potential to cause runtime
|
|
317
|
+
// crashes since the runtime values and types would not line up
|
|
318
|
+
// properly (types expect object to be undefined, but its instead
|
|
319
|
+
// present without its fields)
|
|
320
|
+
dataState = mergeDataState(dataState, execResult.dataState === "empty" ? "partial" : execResult.dataState);
|
|
192
321
|
}
|
|
193
322
|
if (fieldValue !== void 0) {
|
|
194
323
|
objectsToMerge.push({ [resultName]: fieldValue });
|
|
@@ -197,15 +326,60 @@ class StoreReader {
|
|
|
197
326
|
else {
|
|
198
327
|
const fragment = (0, internal_1.getFragmentFromSelection)(selection, context.lookupFragment);
|
|
199
328
|
if (!fragment && selection.kind === graphql_1.Kind.FRAGMENT_SPREAD) {
|
|
200
|
-
throw (0, invariant_1.newInvariantError)(
|
|
329
|
+
throw (0, invariant_1.newInvariantError)(117, selection.name.value);
|
|
201
330
|
}
|
|
202
331
|
if (fragment && policies.fragmentMatches(fragment, typename)) {
|
|
203
|
-
|
|
332
|
+
const isDeferBoundary = (0, internal_1.isDeferredFragment)(selection, context.variables);
|
|
333
|
+
// Prior to 4.3, this branch just flattened the fragment's
|
|
334
|
+
// selectionSet into the existing workSet so that it continued
|
|
335
|
+
// iterating as if the fragment didn't exist. The cache is
|
|
336
|
+
// incremental aware as of 4.3 and as such, we need to resolve the
|
|
337
|
+
// per-fragment selection set so that we can properly strip partial
|
|
338
|
+
// defer fragment data when returnPartialData is false. We need to
|
|
339
|
+
// call execSelectionSetImpl directly (non-cached version) so that we
|
|
340
|
+
// scope the dataState correctly for its fields. Using the cached
|
|
341
|
+
// executeSelectionSet can result in cache poisoning when combined
|
|
342
|
+
// with the fragment registry where it might cache either a) an error
|
|
343
|
+
// thrown when a registered fragment references a named fragment that
|
|
344
|
+
// the query is expected to supply and doesn't or b) resolve to the
|
|
345
|
+
// wrong data result when combined with queries that provide different
|
|
346
|
+
// implementations of the same fragment (see inmemory/fragmentRegistry and
|
|
347
|
+
// cache.diff/incremental tests which provide guards against this
|
|
348
|
+
// behavior).
|
|
349
|
+
const execResult = this.execSelectionSetImpl({
|
|
350
|
+
selectionSet: fragment.selectionSet,
|
|
351
|
+
objectOrReference,
|
|
352
|
+
enclosingRef,
|
|
353
|
+
context,
|
|
354
|
+
});
|
|
355
|
+
const { result, dataState: nextDataState } = execResult;
|
|
356
|
+
partialBoundaries.merge(execResult.partialBoundaries);
|
|
357
|
+
if (result !== void 0) {
|
|
358
|
+
objectsToMerge.push(result);
|
|
359
|
+
}
|
|
360
|
+
if (execResult.missing) {
|
|
361
|
+
missing = missingMerger.merge(missing, execResult.missing);
|
|
362
|
+
}
|
|
363
|
+
if (isDeferBoundary &&
|
|
364
|
+
(nextDataState === "partial" || nextDataState === "empty")) {
|
|
365
|
+
partialBoundaries.add(selection);
|
|
366
|
+
}
|
|
367
|
+
dataState = mergeDataState(dataState, isDeferBoundary ?
|
|
368
|
+
nextDataState === "empty" ? "streaming"
|
|
369
|
+
: nextDataState === "partial" ? "deferPartial"
|
|
370
|
+
: nextDataState
|
|
371
|
+
: nextDataState);
|
|
204
372
|
}
|
|
205
373
|
}
|
|
206
374
|
});
|
|
375
|
+
dataState ||= "complete";
|
|
207
376
|
const result = (0, internal_1.mergeDeepArray)(objectsToMerge);
|
|
208
|
-
const finalResult = {
|
|
377
|
+
const finalResult = {
|
|
378
|
+
result,
|
|
379
|
+
missing,
|
|
380
|
+
dataState,
|
|
381
|
+
partialBoundaries,
|
|
382
|
+
};
|
|
209
383
|
const frozen = (0, internal_1.maybeDeepFreeze)(finalResult);
|
|
210
384
|
// Store this result with its selection set so that we can quickly
|
|
211
385
|
// recognize it again in the StoreReader#isFresh method.
|
|
@@ -216,8 +390,11 @@ class StoreReader {
|
|
|
216
390
|
}
|
|
217
391
|
// Uncached version of executeSubSelectedArray.
|
|
218
392
|
execSubSelectedArrayImpl({ field, array, enclosingRef, context, }) {
|
|
393
|
+
let dataState = "complete";
|
|
219
394
|
let missing;
|
|
220
395
|
let missingMerger = new internal_1.DeepMerger();
|
|
396
|
+
const partialBoundaries = new PartialBoundaries();
|
|
397
|
+
const isStreamed = (0, internal_1.isStreamField)(field, context.variables);
|
|
221
398
|
function handleMissing(childResult, i) {
|
|
222
399
|
if (childResult.missing) {
|
|
223
400
|
missing = missingMerger.merge(missing, { [i]: childResult.missing });
|
|
@@ -232,23 +409,36 @@ class StoreReader {
|
|
|
232
409
|
if (item === null) {
|
|
233
410
|
return null;
|
|
234
411
|
}
|
|
412
|
+
let execResult;
|
|
235
413
|
// This is a nested array, recurse
|
|
236
414
|
if ((0, internal_1.isArray)(item)) {
|
|
237
|
-
|
|
415
|
+
execResult = this.executeSubSelectedArray({
|
|
238
416
|
field,
|
|
239
417
|
array: item,
|
|
240
418
|
enclosingRef,
|
|
241
419
|
context,
|
|
242
|
-
})
|
|
420
|
+
});
|
|
243
421
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
return handleMissing(this.executeSelectionSet({
|
|
422
|
+
else if (field.selectionSet) {
|
|
423
|
+
execResult = this.executeSelectionSet({
|
|
247
424
|
selectionSet: field.selectionSet,
|
|
248
425
|
objectOrReference: item,
|
|
249
426
|
enclosingRef: (0, utilities_1.isReference)(item) ? item : enclosingRef,
|
|
250
427
|
context,
|
|
251
|
-
})
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
if (execResult) {
|
|
431
|
+
const { dataState: nextDataState } = execResult;
|
|
432
|
+
partialBoundaries.set(i, nextDataState === "partial" ?
|
|
433
|
+
// avoid mutating the execResult partialBoundaries object
|
|
434
|
+
execResult.partialBoundaries.clone().add(field)
|
|
435
|
+
: execResult.partialBoundaries);
|
|
436
|
+
dataState = mergeDataState(dataState, isStreamed ?
|
|
437
|
+
nextDataState === "partial" ?
|
|
438
|
+
"streamPartial"
|
|
439
|
+
: nextDataState
|
|
440
|
+
: nextDataState);
|
|
441
|
+
return handleMissing(execResult, i);
|
|
252
442
|
}
|
|
253
443
|
if (environment_1.__DEV__) {
|
|
254
444
|
assertSelectionSetForIdValue(context.store, field, item);
|
|
@@ -257,9 +447,162 @@ class StoreReader {
|
|
|
257
447
|
});
|
|
258
448
|
return {
|
|
259
449
|
result: array,
|
|
450
|
+
dataState,
|
|
260
451
|
missing,
|
|
452
|
+
partialBoundaries,
|
|
261
453
|
};
|
|
262
454
|
}
|
|
455
|
+
prunePartialBoundariesImpl({ boundaries, context, data, path, selectionSet, }) {
|
|
456
|
+
const { variables, lookupFragment, policies } = context;
|
|
457
|
+
if (data == null || !boundaries) {
|
|
458
|
+
return { result: data, dataState: "complete" };
|
|
459
|
+
}
|
|
460
|
+
const merger = new internal_1.DeepMerger();
|
|
461
|
+
let changed = false;
|
|
462
|
+
let dataState = "complete";
|
|
463
|
+
const result = {};
|
|
464
|
+
// __typename might not be part of the selection set, so preserve it when
|
|
465
|
+
// available, otherwise it gets removed since it's never visited when
|
|
466
|
+
// iterating the selection set.
|
|
467
|
+
if (Object.hasOwn(data, "__typename")) {
|
|
468
|
+
result.__typename = data.__typename;
|
|
469
|
+
}
|
|
470
|
+
const workSet = new Set(selectionSet.selections);
|
|
471
|
+
workSet.forEach((selection) => {
|
|
472
|
+
if (!(0, internal_1.shouldInclude)(selection, variables))
|
|
473
|
+
return;
|
|
474
|
+
if ((0, internal_1.isField)(selection)) {
|
|
475
|
+
const resultName = (0, internal_1.resultKeyNameFromField)(selection);
|
|
476
|
+
if (!Object.hasOwn(data, resultName)) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
const fieldValue = data[resultName];
|
|
480
|
+
if (Array.isArray(fieldValue)) {
|
|
481
|
+
const pruned = this.prunePartialStreamArray({
|
|
482
|
+
field: selection,
|
|
483
|
+
array: fieldValue,
|
|
484
|
+
boundaries: boundaries.getChild(resultName),
|
|
485
|
+
context,
|
|
486
|
+
path: path.concat(resultName),
|
|
487
|
+
});
|
|
488
|
+
changed ||= pruned.result !== fieldValue;
|
|
489
|
+
result[resultName] = pruned.result;
|
|
490
|
+
dataState = mergeDataState(dataState, pruned.dataState);
|
|
491
|
+
}
|
|
492
|
+
else if (!selection.selectionSet) {
|
|
493
|
+
result[resultName] = fieldValue;
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
496
|
+
const pruned = this.prunePartialBoundaries({
|
|
497
|
+
data: fieldValue,
|
|
498
|
+
selectionSet: selection.selectionSet,
|
|
499
|
+
boundaries: boundaries.getChild(resultName),
|
|
500
|
+
context,
|
|
501
|
+
path: path.concat(resultName),
|
|
502
|
+
});
|
|
503
|
+
changed ||= pruned.result !== fieldValue;
|
|
504
|
+
dataState = mergeDataState(dataState, pruned.dataState);
|
|
505
|
+
// A response key can be selected by more than one selection (e.g. a
|
|
506
|
+
// field and an overlapping fragment), so merge their kept fields.
|
|
507
|
+
result[resultName] =
|
|
508
|
+
Object.hasOwn(result, resultName) ?
|
|
509
|
+
merger.merge(result[resultName], pruned.result)
|
|
510
|
+
: pruned.result;
|
|
511
|
+
}
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
// Note: we do NOT set `changed` to true anywhere in this branch of the
|
|
515
|
+
// conditional, despite the fact that we might have encountered a
|
|
516
|
+
// partial @defer boundary. Dropping a fragment does not guarantee keys
|
|
517
|
+
// are actually dropped which can happen when overlapping sibling
|
|
518
|
+
// selections contribute to the construction of the object. The final
|
|
519
|
+
// Object.keys(result).length check actually detects whether keys were
|
|
520
|
+
// dropped or not.
|
|
521
|
+
const fragment = (0, internal_1.getFragmentFromSelection)(selection, lookupFragment);
|
|
522
|
+
let prune = false;
|
|
523
|
+
if (context.deferInfo && (0, internal_1.isDeferredFragment)(selection, variables)) {
|
|
524
|
+
const directive = selection.directives?.find((d) => d.name.value === "defer");
|
|
525
|
+
const label = directive && (0, internal_1.getDirectiveArgValue)(directive, "label", graphql_1.Kind.STRING);
|
|
526
|
+
prune = !!context.deferInfo.peekArray(path.concat(label || []));
|
|
527
|
+
}
|
|
528
|
+
if (fragment && policies.fragmentMatches(fragment, data.__typename)) {
|
|
529
|
+
if (boundaries.has(selection) || prune) {
|
|
530
|
+
dataState = mergeDataState(dataState, "streaming");
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
fragment.selectionSet.selections.forEach(workSet.add, workSet);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
if (Object.keys(result).length !== Object.keys(data).length) {
|
|
538
|
+
changed = true;
|
|
539
|
+
}
|
|
540
|
+
else if (changed && boundaries.hasSelections()) {
|
|
541
|
+
// Overlapping siblings may rebuild the same fields under a new object
|
|
542
|
+
// identity (e.g. changed === true) after a partial @defer is skipped.
|
|
543
|
+
// We perform a deep equality check to verify whether anything was
|
|
544
|
+
// actually dropped by the partial @defer fragment.
|
|
545
|
+
changed = !(0, equality_1.equal)(result, data);
|
|
546
|
+
}
|
|
547
|
+
return { result: changed ? result : data, dataState };
|
|
548
|
+
}
|
|
549
|
+
prunePartialStreamArrayImpl({ field, array, boundaries, context, path, }) {
|
|
550
|
+
if (!boundaries)
|
|
551
|
+
return { result: array, dataState: "complete" };
|
|
552
|
+
let changed = false;
|
|
553
|
+
let dataState = "complete";
|
|
554
|
+
let pruned = [];
|
|
555
|
+
const state = context.streamInfo?.peekArray(path)?.state;
|
|
556
|
+
const length = Math.min(array.length, state?.truncate ? state.streamPosition : Number.MAX_SAFE_INTEGER);
|
|
557
|
+
for (let i = 0; i < length; i++) {
|
|
558
|
+
const item = array[i];
|
|
559
|
+
let prunedResult = {
|
|
560
|
+
result: item,
|
|
561
|
+
dataState: "complete",
|
|
562
|
+
};
|
|
563
|
+
const boundary = boundaries.getChild(i);
|
|
564
|
+
if (boundary?.has(field)) {
|
|
565
|
+
// The presence of streamInfo determines how we truncate partial
|
|
566
|
+
// stream arrays. Stream info is only given to cache.diff during
|
|
567
|
+
// in-flight requests so we want keep items in the array equal to the
|
|
568
|
+
// total that have streamed in (this is represented by streamPosition
|
|
569
|
+
// above). For all other cache reads, partial stream boundaries are
|
|
570
|
+
// pruned back to an empty array.
|
|
571
|
+
if (state) {
|
|
572
|
+
state.truncate = true;
|
|
573
|
+
pruned = pruned.slice(0, state.streamPosition);
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
pruned = [];
|
|
577
|
+
dataState = "complete";
|
|
578
|
+
}
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
if (Array.isArray(item)) {
|
|
582
|
+
prunedResult = this.prunePartialStreamArray({
|
|
583
|
+
field,
|
|
584
|
+
array: item,
|
|
585
|
+
boundaries: boundaries.getChild(i),
|
|
586
|
+
context,
|
|
587
|
+
path: path.concat(i),
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
else if (field.selectionSet) {
|
|
591
|
+
prunedResult = this.prunePartialBoundaries({
|
|
592
|
+
data: item,
|
|
593
|
+
selectionSet: field.selectionSet,
|
|
594
|
+
boundaries: boundaries.getChild(i),
|
|
595
|
+
context,
|
|
596
|
+
path: path.concat(i),
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
pruned.push(prunedResult.result);
|
|
600
|
+
changed ||= prunedResult.result !== item;
|
|
601
|
+
dataState = mergeDataState(dataState, prunedResult.dataState);
|
|
602
|
+
}
|
|
603
|
+
changed ||= pruned.length !== array.length;
|
|
604
|
+
return { result: changed ? pruned : array, dataState };
|
|
605
|
+
}
|
|
263
606
|
}
|
|
264
607
|
exports.StoreReader = StoreReader;
|
|
265
608
|
function firstMissing(tree) {
|
|
@@ -281,7 +624,7 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
281
624
|
if ((0, internal_1.isNonNullObject)(value)) {
|
|
282
625
|
(0, invariant_1.invariant)(
|
|
283
626
|
!(0, utilities_1.isReference)(value),
|
|
284
|
-
|
|
627
|
+
118,
|
|
285
628
|
(0, helpers_js_1.getTypenameFromStoreObject)(store, value),
|
|
286
629
|
field.name.value
|
|
287
630
|
);
|
|
@@ -290,4 +633,102 @@ function assertSelectionSetForIdValue(store, field, fieldValue) {
|
|
|
290
633
|
});
|
|
291
634
|
}
|
|
292
635
|
}
|
|
636
|
+
// We deliberately leave `returnPartialData` out of `executeSelectionSet`'s
|
|
637
|
+
// cache key. `isFresh` runs during writes and cannot provide a reliable value
|
|
638
|
+
// for this option, so including it would prevent a reliable cache hit.
|
|
639
|
+
//
|
|
640
|
+
// When `returnPartialData` is false, `diffQueryAgainstStore` prunes data from
|
|
641
|
+
// partial @defer boundaries after reading the cached result. `PartialBoundaries`
|
|
642
|
+
// records the selection paths needed for that pass, including empty nodes along
|
|
643
|
+
// a path. Overlapping non-deferred selections must still be rebuilt so fields
|
|
644
|
+
// contributed only by a partial deferred sibling are removed. The prune pass
|
|
645
|
+
// can then skip unrelated result branches.
|
|
646
|
+
class PartialBoundaries {
|
|
647
|
+
selections = new Set();
|
|
648
|
+
children = new Map();
|
|
649
|
+
add(selection) {
|
|
650
|
+
this.selections.add(selection);
|
|
651
|
+
return this;
|
|
652
|
+
}
|
|
653
|
+
has(selection) {
|
|
654
|
+
return this.selections.has(selection);
|
|
655
|
+
}
|
|
656
|
+
hasSelections() {
|
|
657
|
+
return this.selections.size > 0;
|
|
658
|
+
}
|
|
659
|
+
getChild(key) {
|
|
660
|
+
return this.children.get(key);
|
|
661
|
+
}
|
|
662
|
+
clone() {
|
|
663
|
+
return new PartialBoundaries().merge(this);
|
|
664
|
+
}
|
|
665
|
+
set(key, boundary) {
|
|
666
|
+
const child = this.getChild(key);
|
|
667
|
+
this.children.set(key,
|
|
668
|
+
// Create a new PartialBoundaries instance to avoid mutating any cached
|
|
669
|
+
// execResult partialBoundaries objects
|
|
670
|
+
child ? child.clone().merge(boundary) : boundary);
|
|
671
|
+
}
|
|
672
|
+
merge(boundaries) {
|
|
673
|
+
boundaries.selections.forEach((selection) => this.add(selection));
|
|
674
|
+
boundaries.children.forEach((child, key) => this.set(key, child));
|
|
675
|
+
return this;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function shouldPrune({ dataState }, context) {
|
|
679
|
+
if (dataState === "deferPartial" || dataState === "streamPartial") {
|
|
680
|
+
return true;
|
|
681
|
+
}
|
|
682
|
+
if (dataState === "complete" || dataState === "streaming") {
|
|
683
|
+
return !!(
|
|
684
|
+
// If the last cache write repaired a partial @stream array to a
|
|
685
|
+
// complete array, the stream array might contain stale entries after
|
|
686
|
+
// the last written value. We only want to deliver the results up to
|
|
687
|
+
// the index the network wrote so we need to prune it too.
|
|
688
|
+
(context.streamInfo ||
|
|
689
|
+
// The network hasn't delivered these @defer boundaries yet, so prune
|
|
690
|
+
// the (possibly complete) cached data sitting at them.
|
|
691
|
+
context.deferInfo));
|
|
692
|
+
}
|
|
693
|
+
return false;
|
|
694
|
+
}
|
|
695
|
+
// Describes the data state transitions that change the running state when it's
|
|
696
|
+
// combined with the next data state. Omitted object values represent
|
|
697
|
+
// "impossible" merges where the data state should remain the same.
|
|
698
|
+
const DATA_STATE_MERGES = {
|
|
699
|
+
empty: {
|
|
700
|
+
complete: "partial",
|
|
701
|
+
deferPartial: "partial",
|
|
702
|
+
streaming: "partial",
|
|
703
|
+
streamPartial: "partial",
|
|
704
|
+
},
|
|
705
|
+
deferPartial: {
|
|
706
|
+
empty: "partial",
|
|
707
|
+
},
|
|
708
|
+
streamPartial: {
|
|
709
|
+
deferPartial: "deferPartial",
|
|
710
|
+
empty: "partial",
|
|
711
|
+
},
|
|
712
|
+
streaming: {
|
|
713
|
+
deferPartial: "deferPartial",
|
|
714
|
+
empty: "partial",
|
|
715
|
+
streamPartial: "streamPartial",
|
|
716
|
+
},
|
|
717
|
+
complete: {
|
|
718
|
+
deferPartial: "deferPartial",
|
|
719
|
+
streaming: "streaming",
|
|
720
|
+
streamPartial: "streamPartial",
|
|
721
|
+
empty: "partial",
|
|
722
|
+
},
|
|
723
|
+
partial: {},
|
|
724
|
+
};
|
|
725
|
+
function mergeDataState(current, next) {
|
|
726
|
+
if (next === "partial") {
|
|
727
|
+
return "partial";
|
|
728
|
+
}
|
|
729
|
+
if (!current || current === next) {
|
|
730
|
+
return next;
|
|
731
|
+
}
|
|
732
|
+
return DATA_STATE_MERGES[current][next] || current;
|
|
733
|
+
}
|
|
293
734
|
//# sourceMappingURL=readFromStore.cjs.map
|