@apollo/client 4.3.0-alpha.1 → 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 +484 -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 +16 -21
- 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 +11 -4
- 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/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 +17 -22
- 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 +11 -4
- 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/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
package/core/QueryInfo.d.ts
CHANGED
|
@@ -1,53 +1,48 @@
|
|
|
1
1
|
import type { DocumentNode, FormattedExecutionResult } from "graphql";
|
|
2
|
-
import type { Cache } from "@apollo/client/cache";
|
|
2
|
+
import type { Cache, DiffIncrementalInfo } from "@apollo/client/cache";
|
|
3
|
+
import type { Incremental } from "@apollo/client/incremental";
|
|
3
4
|
import type { ApolloLink } from "@apollo/client/link";
|
|
4
5
|
import type { Unmasked } from "@apollo/client/masking";
|
|
5
6
|
import type { ExtensionsWithStreamInfo } from "@apollo/client/utilities/internal";
|
|
6
7
|
import type { ApolloClient } from "./ApolloClient.js";
|
|
8
|
+
import { NetworkStatus } from "./networkStatus.js";
|
|
7
9
|
import type { ObservableQuery } from "./ObservableQuery.js";
|
|
8
10
|
import type { QueryManager } from "./QueryManager.js";
|
|
9
11
|
import type { DataValue, DefaultContext, InternalRefetchQueriesInclude, MutationUpdaterFunction, NormalizedExecutionResult, OnQueryUpdated, OperationVariables, TypedDocumentNode } from "./types.js";
|
|
10
|
-
import type { ErrorPolicy } from "./watchQueryOptions.js";
|
|
12
|
+
import type { ErrorPolicy, WatchQueryFetchPolicy } from "./watchQueryOptions.js";
|
|
11
13
|
type UpdateQueries<TData> = ApolloClient.MutateOptions<TData, any, any>["updateQueries"];
|
|
12
14
|
export declare const enum CacheWriteBehavior {
|
|
13
15
|
FORBID = 0,
|
|
14
16
|
OVERWRITE = 1,
|
|
15
17
|
MERGE = 2
|
|
16
18
|
}
|
|
17
|
-
interface LastWrite {
|
|
18
|
-
result: FormattedExecutionResult<any, ExtensionsWithStreamInfo>;
|
|
19
|
-
variables: ApolloClient.WatchQueryOptions["variables"];
|
|
20
|
-
dmCount: number | undefined;
|
|
21
|
-
}
|
|
22
19
|
interface OperationInfo<TData, TVariables extends OperationVariables, AllowedCacheWriteBehavior = CacheWriteBehavior> {
|
|
23
20
|
document: DocumentNode | TypedDocumentNode<TData, TVariables>;
|
|
24
21
|
variables: TVariables;
|
|
25
22
|
errorPolicy: ErrorPolicy;
|
|
26
23
|
cacheWriteBehavior: AllowedCacheWriteBehavior;
|
|
24
|
+
returnPartialData?: boolean | undefined;
|
|
25
|
+
}
|
|
26
|
+
interface MarkQueryResult<TData, TExtensions> extends FormattedExecutionResult<TData, TExtensions> {
|
|
27
|
+
dataState: "empty" | "partial" | "streaming" | "complete";
|
|
27
28
|
}
|
|
28
29
|
export declare class QueryInfo<TData, TVariables extends OperationVariables = OperationVariables, TCache extends Cache.Implementation = Cache.Implementation> {
|
|
29
|
-
lastRequestId: number;
|
|
30
30
|
private cache;
|
|
31
31
|
private queryManager;
|
|
32
32
|
readonly id: string;
|
|
33
33
|
private readonly observableQuery?;
|
|
34
34
|
private incremental?;
|
|
35
35
|
constructor(queryManager: QueryManager, observableQuery?: ObservableQuery<any, any>);
|
|
36
|
-
/**
|
|
37
|
-
* @internal
|
|
38
|
-
* For feud-preventing behaviour, `lastWrite` should be shared by all `QueryInfo` instances of an `ObservableQuery`.
|
|
39
|
-
* In the case of a standalone `QueryInfo`, we will keep a local version.
|
|
40
|
-
*
|
|
41
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
42
|
-
*/
|
|
43
|
-
_lastWrite?: LastWrite;
|
|
44
|
-
private get lastWrite();
|
|
45
|
-
private set lastWrite(value);
|
|
46
|
-
resetLastWrite(): void;
|
|
47
|
-
private shouldWrite;
|
|
48
36
|
get hasNext(): boolean;
|
|
37
|
+
get incrementalHandler(): Incremental.Handler<Record<string, unknown>>;
|
|
49
38
|
private maybeHandleIncrementalResult;
|
|
50
|
-
markQueryResult(incoming: ApolloLink.Result<TData>, { document: query, variables, errorPolicy, cacheWriteBehavior, }: OperationInfo<TData, TVariables>
|
|
39
|
+
markQueryResult(incoming: ApolloLink.Result<TData>, { document: query, variables, errorPolicy, cacheWriteBehavior, returnPartialData, fetchPolicy, networkStatus, prunePendingDeferFragments: prune, }: OperationInfo<TData, TVariables> & {
|
|
40
|
+
fetchPolicy: WatchQueryFetchPolicy;
|
|
41
|
+
networkStatus: NetworkStatus;
|
|
42
|
+
prunePendingDeferFragments: boolean;
|
|
43
|
+
}): MarkQueryResult<DataValue.Complete<TData> | DataValue.Streaming<TData>, ExtensionsWithStreamInfo>;
|
|
44
|
+
private getIncrementalInfo;
|
|
45
|
+
getDiff(options: Cache.DiffOptions<TData>, incrementalInfo?: DiffIncrementalInfo): Cache.InternalDiffResultWithDataState<TData>;
|
|
51
46
|
markMutationResult(incoming: ApolloLink.Result<TData>, mutation: OperationInfo<TData, TVariables, CacheWriteBehavior.FORBID | CacheWriteBehavior.MERGE> & {
|
|
52
47
|
context?: DefaultContext;
|
|
53
48
|
updateQueries: UpdateQueries<TData>;
|
|
@@ -67,4 +62,4 @@ export declare class QueryInfo<TData, TVariables extends OperationVariables = Op
|
|
|
67
62
|
markSubscriptionResult(result: FormattedExecutionResult<TData>, { document, variables, errorPolicy, cacheWriteBehavior, }: OperationInfo<TData, TVariables, CacheWriteBehavior.FORBID | CacheWriteBehavior.MERGE>): void;
|
|
68
63
|
}
|
|
69
64
|
export {};
|
|
70
|
-
//# sourceMappingURL=QueryInfo.d.ts.map
|
|
65
|
+
//# sourceMappingURL=QueryInfo.d.ts.map
|
package/core/QueryInfo.js
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Trie } from "@wry/trie";
|
|
2
|
+
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
3
|
+
import { getOperationName, graphQLResultHasError, handleIncrementalSymbol, hasDirectives, toDiffWithDataState, } from "@apollo/client/utilities/internal";
|
|
3
4
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
5
|
+
import { NetworkStatus } from "./networkStatus.js";
|
|
4
6
|
const IGNORE = {};
|
|
5
|
-
const destructiveMethodCounts = new WeakMap();
|
|
6
|
-
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
7
|
-
const original = cache[methodName];
|
|
8
|
-
if (typeof original === "function") {
|
|
9
|
-
// @ts-expect-error this is just too generic to be typed correctly
|
|
10
|
-
cache[methodName] = function () {
|
|
11
|
-
destructiveMethodCounts.set(cache,
|
|
12
|
-
// The %1e15 allows the count to wrap around to 0 safely every
|
|
13
|
-
// quadrillion evictions, so there's no risk of overflow. To be
|
|
14
|
-
// clear, this is more of a pedantic principle than something
|
|
15
|
-
// that matters in any conceivable practical scenario.
|
|
16
|
-
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
17
|
-
// @ts-expect-error this is just too generic to be typed correctly
|
|
18
|
-
return original.apply(this, arguments);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
7
|
const queryInfoIds = new WeakMap();
|
|
23
8
|
// A QueryInfo object represents a single network request, either initiated
|
|
24
9
|
// from the QueryManager or from an ObservableQuery.
|
|
@@ -26,182 +11,162 @@ const queryInfoIds = new WeakMap();
|
|
|
26
11
|
// It is responsible for reporting results to the cache, merging and in a no-cache
|
|
27
12
|
// scenario accumulating the response.
|
|
28
13
|
export class QueryInfo {
|
|
29
|
-
// TODO remove soon - this should be able to be handled by cancelling old operations before starting new ones
|
|
30
|
-
lastRequestId = 1;
|
|
31
14
|
cache;
|
|
32
15
|
queryManager;
|
|
33
16
|
id;
|
|
34
17
|
observableQuery;
|
|
35
18
|
incremental;
|
|
36
19
|
constructor(queryManager, observableQuery) {
|
|
37
|
-
|
|
20
|
+
this.cache = queryManager.cache;
|
|
38
21
|
const id = (queryInfoIds.get(queryManager) || 0) + 1;
|
|
39
22
|
queryInfoIds.set(queryManager, id);
|
|
40
23
|
this.id = id + "";
|
|
41
24
|
this.observableQuery = observableQuery;
|
|
42
25
|
this.queryManager = queryManager;
|
|
43
|
-
// Track how often cache.evict is called, since we want eviction to
|
|
44
|
-
// override the feud-stopping logic in the markQueryResult method, by
|
|
45
|
-
// causing shouldWrite to return true. Wrapping the cache.evict method
|
|
46
|
-
// is a bit of a hack, but it saves us from having to make eviction
|
|
47
|
-
// counting an official part of the ApolloCache API.
|
|
48
|
-
if (!destructiveMethodCounts.has(cache)) {
|
|
49
|
-
destructiveMethodCounts.set(cache, 0);
|
|
50
|
-
wrapDestructiveCacheMethod(cache, "evict");
|
|
51
|
-
wrapDestructiveCacheMethod(cache, "modify");
|
|
52
|
-
wrapDestructiveCacheMethod(cache, "reset");
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* @internal
|
|
57
|
-
* For feud-preventing behaviour, `lastWrite` should be shared by all `QueryInfo` instances of an `ObservableQuery`.
|
|
58
|
-
* In the case of a standalone `QueryInfo`, we will keep a local version.
|
|
59
|
-
*
|
|
60
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
61
|
-
*/
|
|
62
|
-
_lastWrite;
|
|
63
|
-
get lastWrite() {
|
|
64
|
-
return (this.observableQuery || this)._lastWrite;
|
|
65
|
-
}
|
|
66
|
-
set lastWrite(value) {
|
|
67
|
-
(this.observableQuery || this)._lastWrite = value;
|
|
68
|
-
}
|
|
69
|
-
resetLastWrite() {
|
|
70
|
-
this.lastWrite = void 0;
|
|
71
|
-
}
|
|
72
|
-
shouldWrite(result, variables) {
|
|
73
|
-
const { lastWrite } = this;
|
|
74
|
-
return !(lastWrite &&
|
|
75
|
-
// If cache.evict has been called since the last time we wrote this
|
|
76
|
-
// data into the cache, there's a chance writing this result into
|
|
77
|
-
// the cache will repair what was evicted.
|
|
78
|
-
lastWrite.dmCount === destructiveMethodCounts.get(this.cache) &&
|
|
79
|
-
equal(variables, lastWrite.variables) &&
|
|
80
|
-
equal(result.data, lastWrite.result.data) &&
|
|
81
|
-
// We have to compare these values because its possible the final chunk
|
|
82
|
-
// emitted in the incremental result is just `hasNext: false`. This
|
|
83
|
-
// ensures we trigger a cache write when we get `isLastChunk: true`.
|
|
84
|
-
result.extensions?.[streamInfoSymbol] ===
|
|
85
|
-
lastWrite.result.extensions?.[streamInfoSymbol]);
|
|
86
26
|
}
|
|
87
27
|
get hasNext() {
|
|
88
28
|
return this.incremental ? this.incremental.hasNext : false;
|
|
89
29
|
}
|
|
30
|
+
get incrementalHandler() {
|
|
31
|
+
return this.queryManager.incrementalHandler;
|
|
32
|
+
}
|
|
90
33
|
maybeHandleIncrementalResult(cacheData, incoming, query) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.incremental ||= incrementalHandler.startRequest({
|
|
34
|
+
if (this.incrementalHandler.isIncrementalResult(incoming)) {
|
|
35
|
+
this.incremental ||= this.incrementalHandler.startRequest({
|
|
94
36
|
query,
|
|
95
37
|
});
|
|
96
38
|
return this.incremental.handle(cacheData, incoming);
|
|
97
39
|
}
|
|
98
40
|
return incoming;
|
|
99
41
|
}
|
|
100
|
-
markQueryResult(incoming, { document: query, variables, errorPolicy, cacheWriteBehavior, }) {
|
|
42
|
+
markQueryResult(incoming, { document: query, variables, errorPolicy, cacheWriteBehavior, returnPartialData, fetchPolicy, networkStatus, prunePendingDeferFragments: prune, }) {
|
|
101
43
|
const diffOptions = {
|
|
102
44
|
query,
|
|
103
45
|
variables,
|
|
104
|
-
returnPartialData: true,
|
|
105
46
|
optimistic: true,
|
|
106
47
|
};
|
|
107
48
|
// Cancel the pending notify timeout (if it exists) to prevent extraneous network
|
|
108
49
|
// requests. To allow future notify timeouts, diff and dirty are reset as well.
|
|
109
50
|
this.observableQuery?.["resetNotifications"]();
|
|
110
51
|
const skipCache = cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
//
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
// cache write is far from obvious, since any cache write
|
|
151
|
-
// could be the one that puts the cache back into a desired
|
|
152
|
-
// state, fixing corruption or missing data. However, if we
|
|
153
|
-
// always write every network result into the cache, we enable
|
|
154
|
-
// feuds between queries competing to update the same data in
|
|
155
|
-
// incompatible ways, which can lead to an endless cycle of
|
|
156
|
-
// cache broadcasts and useless network requests. As with any
|
|
157
|
-
// feud, eventually one side must step back from the brink,
|
|
158
|
-
// letting the other side(s) have the last word(s). There may
|
|
159
|
-
// be other points where we could break this cycle, such as
|
|
160
|
-
// silencing the broadcast for cache.writeQuery (not a good
|
|
161
|
-
// idea, since it just delays the feud a bit) or somehow
|
|
162
|
-
// avoiding the network request that just happened (also bad,
|
|
163
|
-
// because the server could return useful new data). All
|
|
164
|
-
// options considered, skipping this cache write seems to be
|
|
165
|
-
// the least damaging place to break the cycle, because it
|
|
166
|
-
// reflects the intuition that we recently wrote this exact
|
|
167
|
-
// result into the cache, so the cache *should* already/still
|
|
168
|
-
// contain this data. If some other query has clobbered that
|
|
169
|
-
// data in the meantime, that's too bad, but there will be no
|
|
170
|
-
// winners if every query blindly reverts to its own version
|
|
171
|
-
// of the data. This approach also gives the network a chance
|
|
172
|
-
// to return new data, which will be written into the cache as
|
|
173
|
-
// usual, notifying only those queries that are directly
|
|
174
|
-
// affected by the cache updates, as usual. In the future, an
|
|
175
|
-
// even more sophisticated cache could perhaps prevent or
|
|
176
|
-
// mitigate the clobbering somehow, but that would make this
|
|
177
|
-
// particular cache write even less important, and thus
|
|
178
|
-
// skipping it would be even safer than it is today.
|
|
179
|
-
if (lastDiff && lastDiff.complete) {
|
|
180
|
-
// Reuse data from the last good (complete) diff that we
|
|
181
|
-
// received, when possible.
|
|
182
|
-
result = { ...result, data: lastDiff.result };
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
// If the previous this.diff was incomplete, fall through to
|
|
186
|
-
// re-reading the latest data with cache.diff, below.
|
|
187
|
-
}
|
|
188
|
-
const diff = cache.diff(diffOptions);
|
|
189
|
-
// If we're allowed to write to the cache, and we can read a
|
|
190
|
-
// complete result from the cache, update result.data to be the
|
|
191
|
-
// result from the cache, rather than the raw network result.
|
|
192
|
-
// Set without setDiff to avoid triggering a notify call, since
|
|
193
|
-
// we have other ways of notifying for this result.
|
|
194
|
-
if (diff.complete) {
|
|
195
|
-
result = { ...result, data: diff.result };
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
});
|
|
52
|
+
const diff = skipCache ? undefined : (this.getDiff({
|
|
53
|
+
...diffOptions,
|
|
54
|
+
// We usually request partial data to ensure the network incremental
|
|
55
|
+
// result is merged with all existing data (especially true to
|
|
56
|
+
// maintain @stream arrays with partial list items in the right order
|
|
57
|
+
// or when chunk might otherwise replace a partial non-normalized
|
|
58
|
+
// object), but if we are about to throw away the result anyways due
|
|
59
|
+
// to the error policy (which early returns below), prune any
|
|
60
|
+
// pending boundaries so that CombinedGraphQLErrors contains the
|
|
61
|
+
// right `data` value.
|
|
62
|
+
returnPartialData: errorPolicy !== "none" ||
|
|
63
|
+
!this.incrementalHandler.extractErrors(incoming)?.length,
|
|
64
|
+
}, this.getIncrementalInfo({ prune })));
|
|
65
|
+
const incrementalResult = this.maybeHandleIncrementalResult(diff?.result, incoming, query);
|
|
66
|
+
let result = {
|
|
67
|
+
...incrementalResult,
|
|
68
|
+
dataState: incrementalResult.data == null ? "empty" : "complete",
|
|
69
|
+
};
|
|
70
|
+
const hasPendingDefer = this.incremental
|
|
71
|
+
?.getPendingWithInfo?.()
|
|
72
|
+
.some((pending) => pending.type === "defer" && !pending.delivered);
|
|
73
|
+
if (hasPendingDefer ||
|
|
74
|
+
// The Defer20220824Handler cannot track pending/completed incremental
|
|
75
|
+
// chunks due to its data format so we naively set dataState to
|
|
76
|
+
// streaming if we are still processing chunks. The only case where
|
|
77
|
+
// streaming is incorrect and should actually be complete is when
|
|
78
|
+
// both a @defer and @stream boundary is present and the @defer chunk
|
|
79
|
+
// has completed before the `@stream` array.
|
|
80
|
+
//
|
|
81
|
+
// Assigning the naive "streaming" value avoids a much more expensive
|
|
82
|
+
// pass over `result.data` that would otherwise need to traverse the
|
|
83
|
+
// selection sets and evaluate the data object at each defer boundary
|
|
84
|
+
// to see if it fulfills the selection set. For such a narrow case where
|
|
85
|
+
// its incorrect on a format that is now outdated is not worth the
|
|
86
|
+
// fix so we are ok with reporting a `streaming` here.
|
|
87
|
+
(!this.incremental?.getPendingWithInfo &&
|
|
88
|
+
this.hasNext &&
|
|
89
|
+
hasDirectives(["defer"], query))) {
|
|
90
|
+
result.dataState = "streaming";
|
|
199
91
|
}
|
|
200
|
-
|
|
201
|
-
|
|
92
|
+
if (skipCache || !shouldWriteResult(result, errorPolicy)) {
|
|
93
|
+
return result;
|
|
202
94
|
}
|
|
95
|
+
// Using a transaction here so we have a chance to read the result
|
|
96
|
+
// back from the cache before the watch callback fires as a result
|
|
97
|
+
// of writeQuery, so we can store the new diff quietly and ignore
|
|
98
|
+
// it when we receive it redundantly from the watch callback.
|
|
99
|
+
this.cache.batch({
|
|
100
|
+
onWatchUpdated: (
|
|
101
|
+
// all additional options on ObservableQuery.CacheWatchOptions are
|
|
102
|
+
// optional so we can use the type here
|
|
103
|
+
watch, diff) => {
|
|
104
|
+
if (watch.watcher === this.observableQuery) {
|
|
105
|
+
// see comment on `lastOwnDiff` for explanation
|
|
106
|
+
watch.lastOwnDiff = diff;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
update: (cache) => {
|
|
110
|
+
cache.writeQuery({
|
|
111
|
+
query,
|
|
112
|
+
data: result.data,
|
|
113
|
+
variables,
|
|
114
|
+
overwrite: cacheWriteBehavior === 1 /* CacheWriteBehavior.OVERWRITE */,
|
|
115
|
+
extensions: result.extensions,
|
|
116
|
+
});
|
|
117
|
+
const { dataState, result: diffResult } = this.getDiff({
|
|
118
|
+
...diffOptions,
|
|
119
|
+
returnPartialData: returnPartialData &&
|
|
120
|
+
// Never deliver partial data for network-only requests
|
|
121
|
+
(fetchPolicy !== "network-only" ||
|
|
122
|
+
networkStatus === NetworkStatus.refetch),
|
|
123
|
+
}, this.getIncrementalInfo({ prune }));
|
|
124
|
+
if (dataState === "complete" ||
|
|
125
|
+
dataState === "streaming" ||
|
|
126
|
+
(returnPartialData && dataState === "partial")) {
|
|
127
|
+
result = { ...result, data: diffResult, dataState };
|
|
128
|
+
}
|
|
129
|
+
else if (__DEV__ &&
|
|
130
|
+
// A result that is still streaming is expected to read back
|
|
131
|
+
// incomplete until the remaining chunks arrive.
|
|
132
|
+
!this.hasNext) {
|
|
133
|
+
warnAboutPartialCacheResult(query, result.data,
|
|
134
|
+
// Always show the partial result for debugging, otherwise the user
|
|
135
|
+
// sees `null` when `returnPartialData` is false which isn't helpful
|
|
136
|
+
// for figuring out where the problem is.
|
|
137
|
+
cache.diff({ ...diffOptions, returnPartialData: true }));
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
});
|
|
203
141
|
return result;
|
|
204
142
|
}
|
|
143
|
+
getIncrementalInfo({ prune }) {
|
|
144
|
+
const pending = this.incremental?.getPendingWithInfo?.() ?? [];
|
|
145
|
+
const streamInfo = this.incremental?.streamInfo;
|
|
146
|
+
const incrementalInfo = { streamInfo };
|
|
147
|
+
// We don't want to deliver stream items or complete defer boundaries
|
|
148
|
+
// for a network-only request if they haven't yet streamed from the
|
|
149
|
+
// network. We record all the still-pending paths so that cache.diff
|
|
150
|
+
// can prune complete defer/stream boundaries at those paths.
|
|
151
|
+
if (prune) {
|
|
152
|
+
for (const item of pending) {
|
|
153
|
+
if (item.type === "defer" && !item.delivered) {
|
|
154
|
+
incrementalInfo.deferInfo ||= new Trie(true, () => true);
|
|
155
|
+
incrementalInfo.deferInfo.lookupArray(item.path.concat(item.label || []));
|
|
156
|
+
}
|
|
157
|
+
else if (streamInfo && item.type === "stream") {
|
|
158
|
+
streamInfo.lookupArray(item.path).state.truncate = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return incrementalInfo;
|
|
163
|
+
}
|
|
164
|
+
getDiff(options, incrementalInfo) {
|
|
165
|
+
return toDiffWithDataState(this.cache.diff({
|
|
166
|
+
...options,
|
|
167
|
+
[handleIncrementalSymbol]: incrementalInfo,
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
205
170
|
markMutationResult(incoming, mutation, cache = this.cache) {
|
|
206
171
|
const cacheWrites = [];
|
|
207
172
|
const skipCache = mutation.cacheWriteBehavior === 0 /* CacheWriteBehavior.FORBID */;
|
|
@@ -289,38 +254,34 @@ export class QueryInfo {
|
|
|
289
254
|
const { update } = mutation;
|
|
290
255
|
// Determine whether result is a SingleExecutionResult,
|
|
291
256
|
// or the final ExecutionPatchResult.
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
...result,
|
|
312
|
-
data: diff.result,
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
// If we've received the whole response, call the update function.
|
|
317
|
-
if (!this.hasNext) {
|
|
318
|
-
update(cache, result, {
|
|
319
|
-
context: mutation.context,
|
|
320
|
-
variables: mutation.variables,
|
|
321
|
-
});
|
|
257
|
+
// Re-read from the cache after writing to it to update `result`
|
|
258
|
+
// with any parsed scalar values that might have been written.
|
|
259
|
+
if (!skipCache) {
|
|
260
|
+
const diff = cache.diff({
|
|
261
|
+
id: "ROOT_MUTATION",
|
|
262
|
+
// The cache complains if passed a mutation where it expects a
|
|
263
|
+
// query, so we transform mutations and subscriptions to queries
|
|
264
|
+
// (only once, thanks to this.transformCache).
|
|
265
|
+
query: this.queryManager.getDocumentInfo(mutation.document)
|
|
266
|
+
.asQuery,
|
|
267
|
+
variables: mutation.variables,
|
|
268
|
+
optimistic: false,
|
|
269
|
+
returnPartialData: true,
|
|
270
|
+
});
|
|
271
|
+
if (diff.complete) {
|
|
272
|
+
result = {
|
|
273
|
+
...result,
|
|
274
|
+
data: diff.result,
|
|
275
|
+
};
|
|
322
276
|
}
|
|
323
277
|
}
|
|
278
|
+
// If we've received the whole response, call the update function.
|
|
279
|
+
if (update && !this.hasNext) {
|
|
280
|
+
update(cache, result, {
|
|
281
|
+
context: mutation.context,
|
|
282
|
+
variables: mutation.variables,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
324
285
|
// TODO Do this with cache.evict({ id: 'ROOT_MUTATION' }) but make it
|
|
325
286
|
// shallow to allow rolling back optimistic evictions.
|
|
326
287
|
if (!skipCache && !mutation.keepRootFields && !this.hasNext) {
|
|
@@ -381,11 +342,34 @@ export class QueryInfo {
|
|
|
381
342
|
variables: variables,
|
|
382
343
|
extensions: result.extensions,
|
|
383
344
|
});
|
|
345
|
+
// Re-read from the cache to get parsed scalar values
|
|
346
|
+
const diff = this.cache.diff({
|
|
347
|
+
// The cache complains if passed a mutation where it expects a
|
|
348
|
+
// query, so we transform mutations and subscriptions to queries
|
|
349
|
+
// (only once, thanks to this.transformCache).
|
|
350
|
+
query: this.queryManager.getDocumentInfo(document).asQuery,
|
|
351
|
+
id: "ROOT_SUBSCRIPTION",
|
|
352
|
+
variables,
|
|
353
|
+
optimistic: false,
|
|
354
|
+
returnPartialData: true,
|
|
355
|
+
});
|
|
356
|
+
if (diff.complete) {
|
|
357
|
+
result.data = diff.result;
|
|
358
|
+
}
|
|
384
359
|
}
|
|
385
360
|
this.queryManager.broadcastQueries();
|
|
386
361
|
}
|
|
387
362
|
}
|
|
388
363
|
}
|
|
364
|
+
function warnAboutPartialCacheResult(query, networkResult, diff) {
|
|
365
|
+
__DEV__ && invariant.warn(
|
|
366
|
+
91,
|
|
367
|
+
getOperationName(query, "(anonymous)"),
|
|
368
|
+
diff.missing?.missing,
|
|
369
|
+
networkResult,
|
|
370
|
+
diff.result
|
|
371
|
+
);
|
|
372
|
+
}
|
|
389
373
|
function shouldWriteResult(result, errorPolicy = "none") {
|
|
390
374
|
const ignoreErrors = errorPolicy === "ignore" || errorPolicy === "all";
|
|
391
375
|
let writeWithErrors = !graphQLResultHasError(result);
|