@apollo/client 4.3.0-alpha.1 → 4.3.0-alpha.11
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 +503 -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 +19 -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 +10 -3
- 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/{utilities/internal/types/NoInfer.cjs → incremental/internal/types.cjs} +1 -1
- 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/local-state/LocalState.cjs.map +1 -1
- package/__cjs/local-state/LocalState.d.cts +1 -1
- 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/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +0 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +40 -34
- 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 +7 -3
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +7 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +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 -2
- 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 +19 -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 +10 -3
- 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.d.ts +1 -1
- package/local-state/LocalState.js +11 -11
- package/local-state/LocalState.js.map +1 -1
- 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/useFragment.d.ts +0 -1
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +40 -34
- 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.d.ts +7 -4
- package/react/hooks/useSubscription.js +7 -3
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +1 -1
- package/react/hooks/useSuspenseFragment.js.map +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/useFragment.d.ts +0 -1
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +40 -34
- 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.d.ts +7 -4
- package/react/hooks-compiled/useSubscription.js +107 -93
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js.map +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 -2
- 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/__cjs/utilities/internal/types/NoInfer.cjs.map +0 -1
- package/__cjs/utilities/internal/types/NoInfer.d.cts +0 -35
- package/utilities/internal/types/NoInfer.d.ts +0 -35
- package/utilities/internal/types/NoInfer.js +0 -2
- package/utilities/internal/types/NoInfer.js.map +0 -1
|
@@ -278,12 +278,8 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
278
278
|
readonly options: ObservableQuery.Options<TData, TVariables>;
|
|
279
279
|
readonly queryName?: string;
|
|
280
280
|
private variablesUnknown;
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
*
|
|
284
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
285
|
-
*/
|
|
286
|
-
_lastWrite?: unknown;
|
|
281
|
+
private didWarnOnFeud;
|
|
282
|
+
private lastMissing?;
|
|
287
283
|
get query(): TypedDocumentNode<TData, TVariables>;
|
|
288
284
|
/**
|
|
289
285
|
* An object containing the variables that were provided for the query.
|
|
@@ -349,7 +345,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
349
345
|
*/
|
|
350
346
|
getCacheDiff({ optimistic }?: {
|
|
351
347
|
optimistic?: boolean | undefined;
|
|
352
|
-
}): Cache.
|
|
348
|
+
}): Cache.InternalDiffResultWithDataState<TData>;
|
|
353
349
|
private getInitialResult;
|
|
354
350
|
private resubscribeCache;
|
|
355
351
|
private stableLastResult?;
|
|
@@ -372,7 +368,18 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
372
368
|
/**
|
|
373
369
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
374
370
|
*/
|
|
375
|
-
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables>(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars>
|
|
371
|
+
fetchMore<TFetchData = TData, TFetchVars extends OperationVariables = TVariables, TErrorPolicy extends ErrorPolicy = "none">(options: ObservableQuery.FetchMoreOptions<TData, TVariables, TFetchData, TFetchVars> & {
|
|
372
|
+
/**
|
|
373
|
+
* Specifies how the query handles a response that returns both GraphQL errors and partial results.
|
|
374
|
+
*
|
|
375
|
+
* For details, see [GraphQL error policies](https://www.apollographql.com/docs/react/data/error-handling/#graphql-error-policies).
|
|
376
|
+
*
|
|
377
|
+
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
378
|
+
*
|
|
379
|
+
* @docGroup 1. Operation options
|
|
380
|
+
*/
|
|
381
|
+
errorPolicy?: TErrorPolicy;
|
|
382
|
+
}): Promise<ApolloClient.QueryResult<TFetchData, TErrorPolicy>>;
|
|
376
383
|
/**
|
|
377
384
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
378
385
|
*
|
|
@@ -458,6 +465,7 @@ export declare class ObservableQuery<TData = unknown, TVariables extends Operati
|
|
|
458
465
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
459
466
|
*/
|
|
460
467
|
notify(scheduled?: boolean): void;
|
|
468
|
+
private deliverCacheDiff;
|
|
461
469
|
private activeOperations;
|
|
462
470
|
private pushOperation;
|
|
463
471
|
private calculateNetworkStatus;
|
package/core/ObservableQuery.js
CHANGED
|
@@ -2,8 +2,9 @@ import { equal } from "@wry/equality";
|
|
|
2
2
|
import { BehaviorSubject, filter, Observable, share, Subject, tap } from "rxjs";
|
|
3
3
|
import { isNetworkRequestInFlight, isNetworkRequestSettled, } from "@apollo/client/utilities";
|
|
4
4
|
import { __DEV__ } from "@apollo/client/utilities/environment";
|
|
5
|
-
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, preventUnhandledRejection, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
5
|
+
import { compact, equalByQuery, extensionsSymbol, filterMap, getOperationDefinition, getOperationName, getQueryDefinition, handleIncrementalSymbol, preventUnhandledRejection, toDiffWithDataState, toQueryResult, variablesUnknownSymbol, } from "@apollo/client/utilities/internal";
|
|
6
6
|
import { invariant } from "@apollo/client/utilities/invariant";
|
|
7
|
+
import { dataStateErrorCache } from "./dataStateErrorCache.js";
|
|
7
8
|
import { NetworkStatus } from "./networkStatus.js";
|
|
8
9
|
const { assign, hasOwnProperty } = Object;
|
|
9
10
|
const uninitialized = {
|
|
@@ -20,16 +21,29 @@ const empty = {
|
|
|
20
21
|
dataState: "empty",
|
|
21
22
|
partial: true,
|
|
22
23
|
};
|
|
24
|
+
const destructiveMethodCounts = new WeakMap();
|
|
25
|
+
function wrapDestructiveCacheMethod(cache, methodName) {
|
|
26
|
+
const original = cache[methodName];
|
|
27
|
+
if (typeof original === "function") {
|
|
28
|
+
// @ts-expect-error this is just too generic to be typed correctly
|
|
29
|
+
cache[methodName] = function () {
|
|
30
|
+
destructiveMethodCounts.set(cache,
|
|
31
|
+
// The %1e15 allows the count to wrap around to 0 safely every
|
|
32
|
+
// quadrillion evictions, so there's no risk of overflow. To be
|
|
33
|
+
// clear, this is more of a pedantic principle than something
|
|
34
|
+
// that matters in any conceivable practical scenario.
|
|
35
|
+
(destructiveMethodCounts.get(cache) + 1) % 1e15);
|
|
36
|
+
// @ts-expect-error this is just too generic to be typed correctly
|
|
37
|
+
return original.apply(this, arguments);
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
23
41
|
export class ObservableQuery {
|
|
24
42
|
options;
|
|
25
43
|
queryName;
|
|
26
44
|
variablesUnknown = false;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
*
|
|
30
|
-
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
31
|
-
*/
|
|
32
|
-
_lastWrite;
|
|
45
|
+
didWarnOnFeud = false;
|
|
46
|
+
lastMissing;
|
|
33
47
|
// The `query` computed property will always reflect the document transformed
|
|
34
48
|
// by the last run query. `this.options.query` will always reflect the raw
|
|
35
49
|
// untransformed query to ensure document transforms with runtime conditionals
|
|
@@ -66,6 +80,18 @@ export class ObservableQuery {
|
|
|
66
80
|
}
|
|
67
81
|
constructor({ queryManager, options, transformedQuery = queryManager.transform(options.query), }) {
|
|
68
82
|
this.queryManager = queryManager;
|
|
83
|
+
// Track how often destructive cache methods are called, since we want
|
|
84
|
+
// eviction to override the feud-stopping logic in `shouldAutoRefetch`,
|
|
85
|
+
// by causing it to return true. Wrapping these cache methods is a bit of a
|
|
86
|
+
// hack, but it saves us from having to make eviction counting an official
|
|
87
|
+
// part of the ApolloCache API.
|
|
88
|
+
const { cache } = queryManager;
|
|
89
|
+
if (!destructiveMethodCounts.has(cache)) {
|
|
90
|
+
destructiveMethodCounts.set(cache, 0);
|
|
91
|
+
wrapDestructiveCacheMethod(cache, "evict");
|
|
92
|
+
wrapDestructiveCacheMethod(cache, "modify");
|
|
93
|
+
wrapDestructiveCacheMethod(cache, "reset");
|
|
94
|
+
}
|
|
69
95
|
// active state
|
|
70
96
|
this.waitForNetworkResult = options.fetchPolicy === "network-only";
|
|
71
97
|
this.isTornDown = false;
|
|
@@ -76,7 +102,7 @@ export class ObservableQuery {
|
|
|
76
102
|
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
77
103
|
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
78
104
|
if (options[variablesUnknownSymbol]) {
|
|
79
|
-
invariant(fetchPolicy === "standby",
|
|
105
|
+
invariant(fetchPolicy === "standby", 83);
|
|
80
106
|
this.variablesUnknown = true;
|
|
81
107
|
}
|
|
82
108
|
this.lastQuery = transformedQuery;
|
|
@@ -205,12 +231,13 @@ export class ObservableQuery {
|
|
|
205
231
|
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
206
232
|
*/
|
|
207
233
|
getCacheDiff({ optimistic = true } = {}) {
|
|
208
|
-
return this.cache.diff({
|
|
234
|
+
return toDiffWithDataState(this.cache.diff({
|
|
209
235
|
query: this.query,
|
|
210
236
|
variables: this.variables,
|
|
211
237
|
returnPartialData: true,
|
|
212
238
|
optimistic,
|
|
213
|
-
|
|
239
|
+
[handleIncrementalSymbol]: undefined,
|
|
240
|
+
}));
|
|
214
241
|
}
|
|
215
242
|
getInitialResult(initialFetchPolicy) {
|
|
216
243
|
let fetchPolicy = initialFetchPolicy || this.options.fetchPolicy;
|
|
@@ -220,16 +247,18 @@ export class ObservableQuery {
|
|
|
220
247
|
}
|
|
221
248
|
const cacheResult = () => {
|
|
222
249
|
const diff = this.getCacheDiff();
|
|
250
|
+
let { dataState } = diff;
|
|
223
251
|
// TODO: queryInfo.getDiff should handle this since cache.diff returns a
|
|
224
252
|
// null when returnPartialData is false
|
|
225
253
|
const data = this.options.returnPartialData || diff.complete ?
|
|
226
254
|
diff.result ?? undefined
|
|
227
255
|
: undefined;
|
|
256
|
+
if (data === undefined) {
|
|
257
|
+
dataState = "empty";
|
|
258
|
+
}
|
|
228
259
|
return this.maskResult({
|
|
229
260
|
data,
|
|
230
|
-
dataState
|
|
231
|
-
: data === undefined ? "empty"
|
|
232
|
-
: "partial",
|
|
261
|
+
dataState,
|
|
233
262
|
loading: !diff.complete,
|
|
234
263
|
networkStatus: diff.complete ? NetworkStatus.ready : NetworkStatus.loading,
|
|
235
264
|
partial: !diff.complete,
|
|
@@ -382,7 +411,7 @@ export class ObservableQuery {
|
|
|
382
411
|
const queryDef = getQueryDefinition(this.query);
|
|
383
412
|
const vars = queryDef.variableDefinitions;
|
|
384
413
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
385
|
-
__DEV__ && invariant.warn(
|
|
414
|
+
__DEV__ && invariant.warn(84, variables, queryDef.name?.value || queryDef);
|
|
386
415
|
}
|
|
387
416
|
}
|
|
388
417
|
if (variables && !equal(this.variables, variables)) {
|
|
@@ -390,7 +419,6 @@ export class ObservableQuery {
|
|
|
390
419
|
reobserveOptions.variables = this.options.variables =
|
|
391
420
|
this.getVariablesWithDefaults({ ...this.variables, ...variables });
|
|
392
421
|
}
|
|
393
|
-
this._lastWrite = undefined;
|
|
394
422
|
return this._reobserve(reobserveOptions, {
|
|
395
423
|
newNetworkStatus: NetworkStatus.refetch,
|
|
396
424
|
});
|
|
@@ -398,7 +426,7 @@ export class ObservableQuery {
|
|
|
398
426
|
fetchMore({ query, variables, context, errorPolicy, updateQuery, }) {
|
|
399
427
|
invariant(
|
|
400
428
|
this.options.fetchPolicy !== "cache-only",
|
|
401
|
-
|
|
429
|
+
85,
|
|
402
430
|
getOperationName(this.query, "(anonymous)")
|
|
403
431
|
);
|
|
404
432
|
const combinedOptions = {
|
|
@@ -432,7 +460,7 @@ export class ObservableQuery {
|
|
|
432
460
|
let wasUpdated = false;
|
|
433
461
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
434
462
|
if (!isCached) {
|
|
435
|
-
invariant(updateQuery,
|
|
463
|
+
invariant(updateQuery, 86);
|
|
436
464
|
}
|
|
437
465
|
const { finalize, pushNotification } = this.pushOperation(NetworkStatus.fetchMore);
|
|
438
466
|
pushNotification({
|
|
@@ -509,9 +537,7 @@ export class ObservableQuery {
|
|
|
509
537
|
// will be overwritten anyways, just here for types sake
|
|
510
538
|
loading: false,
|
|
511
539
|
data: diff.result,
|
|
512
|
-
dataState:
|
|
513
|
-
"streaming"
|
|
514
|
-
: "complete",
|
|
540
|
+
dataState: diff.complete ? "complete" : "streaming",
|
|
515
541
|
},
|
|
516
542
|
});
|
|
517
543
|
}
|
|
@@ -608,7 +634,7 @@ export class ObservableQuery {
|
|
|
608
634
|
onError(error);
|
|
609
635
|
}
|
|
610
636
|
else {
|
|
611
|
-
invariant.error(
|
|
637
|
+
invariant.error(87, error);
|
|
612
638
|
}
|
|
613
639
|
return;
|
|
614
640
|
}
|
|
@@ -859,7 +885,7 @@ export class ObservableQuery {
|
|
|
859
885
|
if (!this.didWarnCacheOnlyPolling &&
|
|
860
886
|
pollInterval &&
|
|
861
887
|
fetchPolicy === "cache-only") {
|
|
862
|
-
__DEV__ && invariant.warn(
|
|
888
|
+
__DEV__ && invariant.warn(88, getOperationName(this.query, "(anonymous)"));
|
|
863
889
|
this.didWarnCacheOnlyPolling = true;
|
|
864
890
|
}
|
|
865
891
|
}
|
|
@@ -925,7 +951,10 @@ export class ObservableQuery {
|
|
|
925
951
|
}
|
|
926
952
|
_reobserve(newOptions, internalOptions) {
|
|
927
953
|
this.isTornDown = false;
|
|
928
|
-
let { newNetworkStatus } = internalOptions || {};
|
|
954
|
+
let { newNetworkStatus, keepLastMissing } = internalOptions || {};
|
|
955
|
+
if (!keepLastMissing) {
|
|
956
|
+
this.lastMissing = undefined;
|
|
957
|
+
}
|
|
929
958
|
this.queryManager.obsQueries.add(this);
|
|
930
959
|
const useDisposableObservable =
|
|
931
960
|
// Refetching uses a disposable Observable to allow refetches using different
|
|
@@ -1066,7 +1095,7 @@ export class ObservableQuery {
|
|
|
1066
1095
|
this.queryManager.obsQueries.delete(this);
|
|
1067
1096
|
this.isTornDown = true;
|
|
1068
1097
|
this.abortActiveOperations();
|
|
1069
|
-
this.
|
|
1098
|
+
this.lastMissing = undefined;
|
|
1070
1099
|
}
|
|
1071
1100
|
transformDocument(document) {
|
|
1072
1101
|
return this.queryManager.transform(document);
|
|
@@ -1124,53 +1153,126 @@ export class ObservableQuery {
|
|
|
1124
1153
|
return;
|
|
1125
1154
|
}
|
|
1126
1155
|
}
|
|
1127
|
-
const { dirty } = this;
|
|
1156
|
+
const { dirty, lastMissing } = this;
|
|
1157
|
+
const { fetchPolicy } = this.options;
|
|
1128
1158
|
this.resetNotifications();
|
|
1129
|
-
if (dirty
|
|
1130
|
-
(
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1159
|
+
if (!dirty ||
|
|
1160
|
+
(fetchPolicy !== "cache-only" &&
|
|
1161
|
+
fetchPolicy !== "cache-and-network" &&
|
|
1162
|
+
this.activeOperations.size)) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
const diff = this.getCacheDiff();
|
|
1166
|
+
const current = this.getCurrentResult();
|
|
1167
|
+
// `fromOptimisticTransaction` is not available through the `cache.diff`
|
|
1168
|
+
// code path, so we need to check whether the cache result is an optimistic
|
|
1169
|
+
// result this way.
|
|
1170
|
+
const isOptimistic = !equal(diff.result, this.getCacheDiff({ optimistic: false }).result);
|
|
1171
|
+
if (
|
|
1172
|
+
// When this diff came from an optimistic transaction, deliver the
|
|
1173
|
+
// current cache data to the ObservableQuery, but don't perform a
|
|
1174
|
+
// reobservation, since oq.reobserveCacheFirst might make a network
|
|
1175
|
+
// request, and we never want to trigger network requests in the
|
|
1176
|
+
// middle of optimistic updates.
|
|
1177
|
+
isOptimistic ||
|
|
1178
|
+
// If we get a cache update in the middle of streaming (possible with
|
|
1179
|
+
// cache-and-network fetch policy), just deliver the cache value without
|
|
1180
|
+
// going through the full reobserve which would otherwise trigger another
|
|
1181
|
+
// request (deduplication should kick in, but doing so replays any
|
|
1182
|
+
// previous emits from the link chain, which get rewritten into the cache
|
|
1183
|
+
// and might clobber this cache update)
|
|
1184
|
+
(!diff.complete && current.networkStatus === NetworkStatus.streaming)) {
|
|
1185
|
+
this.deliverCacheDiff(diff);
|
|
1186
|
+
return;
|
|
1187
|
+
}
|
|
1188
|
+
if (diff.complete) {
|
|
1189
|
+
this.lastMissing = undefined;
|
|
1190
|
+
}
|
|
1191
|
+
else if (!lastMissing ||
|
|
1192
|
+
// If a destructive cache method has been called since the last recorded
|
|
1193
|
+
// incomplete result, there's a chance fetching this data again will
|
|
1194
|
+
// restore what was evicted, even though the cache result looks the same
|
|
1195
|
+
// as before.
|
|
1196
|
+
lastMissing.dmCount !== destructiveMethodCounts.get(this.cache) ||
|
|
1197
|
+
!equal(lastMissing.variables, this.variables) ||
|
|
1198
|
+
!equal(lastMissing.missing, diff.missing?.missing)) {
|
|
1199
|
+
this.didWarnOnFeud = false;
|
|
1200
|
+
this.lastMissing = {
|
|
1201
|
+
variables: this.variables,
|
|
1202
|
+
missing: diff.missing?.missing,
|
|
1203
|
+
dmCount: destructiveMethodCounts.get(this.cache),
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
else if (
|
|
1207
|
+
// reobserveCacheFirst with cache-only fetch policy only calls
|
|
1208
|
+
// reobserve which never fetches from the network so we are ok
|
|
1209
|
+
// allowing cache-only queries to fallthrough to reobserveCacheFirst.
|
|
1210
|
+
// This also prevents the feud warning which would be confusing for a
|
|
1211
|
+
// cache-only query anyways.
|
|
1212
|
+
fetchPolicy !== "cache-only") {
|
|
1213
|
+
// If we've fallen through to this case, a cache emit has returned the
|
|
1214
|
+
// same missing fields which means at least one value on the fields we've
|
|
1215
|
+
// already delivered have changed. We are ok delivering the updated
|
|
1216
|
+
// partial result in this case to keep the result as fresh as possible. We
|
|
1217
|
+
// NEVER want to downgrade this query from a complete query to a partial
|
|
1218
|
+
// query though, so we also make sure we only deliver if the previous
|
|
1219
|
+
// result was also partial.
|
|
1220
|
+
if (current.dataState === "partial") {
|
|
1221
|
+
this.deliverCacheDiff(diff);
|
|
1148
1222
|
}
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
});
|
|
1223
|
+
// If the (partial) result is the same as the last partial result
|
|
1224
|
+
// we recorded from a previous broadcast (and the variables match
|
|
1225
|
+
// too), avoid calling reobserveCacheFirst to refetch this query
|
|
1226
|
+
// again. If we allow refetching anytime this result becomes partial,
|
|
1227
|
+
// we risk feuds between queries competing to update the same data in
|
|
1228
|
+
// incompatible ways, which can lead to an endless cycle of cache
|
|
1229
|
+
// broadcasts and useless network requests. As with any
|
|
1230
|
+
// feud, eventually one side must step back from the brink,
|
|
1231
|
+
// letting the other side(s) have the last word(s). There may
|
|
1232
|
+
// be other points where we could break this cycle, such as
|
|
1233
|
+
// silencing the broadcast for cache.writeQuery (not a good
|
|
1234
|
+
// idea, since it just delays the feud a bit) or somehow
|
|
1235
|
+
// avoiding the network request that just happened (also bad,
|
|
1236
|
+
// because the server could return useful new data). All
|
|
1237
|
+
// options considered, returning early and stopping the
|
|
1238
|
+
// reobserveCacheFirst cycle seems to be the least damaging place to
|
|
1239
|
+
// break the cycle because it allows read functions/custom scalars to
|
|
1240
|
+
// be applied to the feuding query while avoiding the endless cycle of
|
|
1241
|
+
// requests.
|
|
1242
|
+
if (__DEV__ && !this.didWarnOnFeud) {
|
|
1243
|
+
this.didWarnOnFeud = true;
|
|
1244
|
+
warnOnFeud(this.query, diff);
|
|
1172
1245
|
}
|
|
1246
|
+
return;
|
|
1173
1247
|
}
|
|
1248
|
+
//If this diff did not come from an optimistic transaction
|
|
1249
|
+
// make the ObservableQuery "reobserve" the latest data
|
|
1250
|
+
// using a temporary fetch policy of "cache-first", so complete cache
|
|
1251
|
+
// results have a chance to be delivered without triggering additional
|
|
1252
|
+
// network requests, even when options.fetchPolicy is "network-only"
|
|
1253
|
+
// or "cache-and-network". All other fetch policies are preserved by
|
|
1254
|
+
// this method, and are handled by calling oq.reobserve(). If this
|
|
1255
|
+
// reobservation is spurious, distinctUntilChanged still has a
|
|
1256
|
+
// chance to catch it before delivery to ObservableQuery subscribers.
|
|
1257
|
+
this.reobserveCacheFirst();
|
|
1258
|
+
}
|
|
1259
|
+
deliverCacheDiff(diff) {
|
|
1260
|
+
const current = this.getCurrentResult();
|
|
1261
|
+
this.input.next({
|
|
1262
|
+
kind: "N",
|
|
1263
|
+
value: {
|
|
1264
|
+
data: diff.result,
|
|
1265
|
+
dataState: diff.dataState,
|
|
1266
|
+
networkStatus: current.networkStatus,
|
|
1267
|
+
loading: current.loading,
|
|
1268
|
+
error: undefined,
|
|
1269
|
+
partial: !diff.complete,
|
|
1270
|
+
},
|
|
1271
|
+
source: "cache",
|
|
1272
|
+
query: this.query,
|
|
1273
|
+
variables: this.variables,
|
|
1274
|
+
meta: {},
|
|
1275
|
+
});
|
|
1174
1276
|
}
|
|
1175
1277
|
activeOperations = new Set();
|
|
1176
1278
|
pushOperation(networkStatus) {
|
|
@@ -1233,6 +1335,7 @@ export class ObservableQuery {
|
|
|
1233
1335
|
// exception for cache-only queries - we reset them into a "ready" state
|
|
1234
1336
|
// as we won't trigger a refetch for them
|
|
1235
1337
|
const resetToEmpty = this.options.fetchPolicy === "cache-only";
|
|
1338
|
+
this.lastMissing = undefined;
|
|
1236
1339
|
this.setResult(resetToEmpty ? empty : uninitialized, {
|
|
1237
1340
|
shouldEmit: resetToEmpty ? 1 /* EmitBehavior.force */ : 2 /* EmitBehavior.never */,
|
|
1238
1341
|
});
|
|
@@ -1254,19 +1357,55 @@ export class ObservableQuery {
|
|
|
1254
1357
|
});
|
|
1255
1358
|
}
|
|
1256
1359
|
operator = filterMap((notification) => {
|
|
1257
|
-
const { query,
|
|
1360
|
+
const { query, meta } = notification;
|
|
1258
1361
|
if (notification.source === "setResult") {
|
|
1259
|
-
return {
|
|
1362
|
+
return {
|
|
1363
|
+
query,
|
|
1364
|
+
variables: this.variables,
|
|
1365
|
+
result: notification.value,
|
|
1366
|
+
meta,
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
if (notification.kind === "C") {
|
|
1370
|
+
return;
|
|
1260
1371
|
}
|
|
1261
|
-
|
|
1372
|
+
const resolvedVariables = "resolvedVariables" in notification ?
|
|
1373
|
+
notification.resolvedVariables
|
|
1374
|
+
: undefined;
|
|
1375
|
+
// Usually we prefer to drop notifications that don't match this query
|
|
1376
|
+
// but this breaks when used with `@export` queries that resolve variables
|
|
1377
|
+
// after the request is initiated. `notification.resolvedVariables` gives us
|
|
1378
|
+
// the variables the query actually resolved with during evaluation in
|
|
1379
|
+
// QueryManager (which is the variables value after `@export` variables have
|
|
1380
|
+
// been applied), but we need to update this query with those resolved
|
|
1381
|
+
// variables maybe in the middle of a request (updating is handled below).
|
|
1382
|
+
// When we update this.variables to the resolved variables, this causes
|
|
1383
|
+
// isEqualQuery(notification, this) to fail for future notifications since
|
|
1384
|
+
// the notification.variables holds the stale variables value. In this case,
|
|
1385
|
+
// we want to allow the notification through only if the current variables
|
|
1386
|
+
// value matches the resolved variables.
|
|
1387
|
+
//
|
|
1388
|
+
// Note: the check for matching resolved variables typically kicks in for
|
|
1389
|
+
// multi-emission fetches (such as defer, or cache-and-network, etc).
|
|
1390
|
+
if (notification.query !== this.query) {
|
|
1262
1391
|
return;
|
|
1263
1392
|
}
|
|
1393
|
+
if (!equal(resolvedVariables, this.variables)) {
|
|
1394
|
+
if (!equal(notification.variables, this.variables)) {
|
|
1395
|
+
return;
|
|
1396
|
+
}
|
|
1397
|
+
if (resolvedVariables) {
|
|
1398
|
+
this.options.variables = resolvedVariables;
|
|
1399
|
+
this.resubscribeCache();
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
const variables = this.variables;
|
|
1264
1403
|
let result;
|
|
1265
1404
|
const previous = this.subject.getValue();
|
|
1266
1405
|
if (notification.source === "cache") {
|
|
1267
1406
|
result = notification.value;
|
|
1268
1407
|
if (result.networkStatus === NetworkStatus.ready &&
|
|
1269
|
-
result.partial &&
|
|
1408
|
+
result.dataState === "partial" &&
|
|
1270
1409
|
(!this.options.returnPartialData ||
|
|
1271
1410
|
previous.result.networkStatus === NetworkStatus.error) &&
|
|
1272
1411
|
this.options.fetchPolicy !== "cache-only") {
|
|
@@ -1281,7 +1420,9 @@ export class ObservableQuery {
|
|
|
1281
1420
|
result =
|
|
1282
1421
|
notification.kind === "E" ?
|
|
1283
1422
|
{
|
|
1284
|
-
...(isEqualQuery(previous, notification)
|
|
1423
|
+
...((isEqualQuery(previous, notification) ||
|
|
1424
|
+
(resolvedVariables &&
|
|
1425
|
+
equal(resolvedVariables, previous.variables))) ?
|
|
1285
1426
|
previous.result
|
|
1286
1427
|
: { data: undefined, dataState: "empty", partial: true }),
|
|
1287
1428
|
error: notification.error,
|
|
@@ -1290,7 +1431,8 @@ export class ObservableQuery {
|
|
|
1290
1431
|
}
|
|
1291
1432
|
: notification.value;
|
|
1292
1433
|
if (notification.kind === "E" && result.dataState === "streaming") {
|
|
1293
|
-
result.dataState =
|
|
1434
|
+
result.dataState =
|
|
1435
|
+
dataStateErrorCache.get(notification.error) ?? "complete";
|
|
1294
1436
|
}
|
|
1295
1437
|
if (result.error) {
|
|
1296
1438
|
meta.shouldEmit = 1 /* EmitBehavior.force */;
|
|
@@ -1338,7 +1480,10 @@ export class ObservableQuery {
|
|
|
1338
1480
|
reobserveCacheFirst() {
|
|
1339
1481
|
const { fetchPolicy, nextFetchPolicy } = this.options;
|
|
1340
1482
|
if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
|
|
1341
|
-
this.
|
|
1483
|
+
// Preserve this.lastMissing so a cache update that triggers this
|
|
1484
|
+
// reobserve doesn't reset feud detection. All user-initiated calls to
|
|
1485
|
+
// reobserve (refetch/poll/reobserve, etc) should clear it.
|
|
1486
|
+
this._reobserve({
|
|
1342
1487
|
fetchPolicy: "cache-first",
|
|
1343
1488
|
// Use a temporary nextFetchPolicy function that replaces itself with the
|
|
1344
1489
|
// previous nextFetchPolicy value and returns the original fetchPolicy.
|
|
@@ -1354,10 +1499,10 @@ export class ObservableQuery {
|
|
|
1354
1499
|
// Otherwise go back to the original this.options.fetchPolicy.
|
|
1355
1500
|
return fetchPolicy;
|
|
1356
1501
|
},
|
|
1357
|
-
});
|
|
1502
|
+
}, { keepLastMissing: true });
|
|
1358
1503
|
}
|
|
1359
1504
|
else {
|
|
1360
|
-
this.
|
|
1505
|
+
this._reobserve(undefined, { keepLastMissing: true });
|
|
1361
1506
|
}
|
|
1362
1507
|
}
|
|
1363
1508
|
getVariablesWithDefaults(variables) {
|
|
@@ -1366,7 +1511,7 @@ export class ObservableQuery {
|
|
|
1366
1511
|
}
|
|
1367
1512
|
export function logMissingFieldErrors(missing) {
|
|
1368
1513
|
if (__DEV__ && missing) {
|
|
1369
|
-
__DEV__ && invariant.debug(
|
|
1514
|
+
__DEV__ && invariant.debug(89, missing);
|
|
1370
1515
|
}
|
|
1371
1516
|
}
|
|
1372
1517
|
function isEqualQuery(a, b) {
|
|
@@ -1409,4 +1554,7 @@ function getTrackingOperatorPromise(defaultValue) {
|
|
|
1409
1554
|
});
|
|
1410
1555
|
return { promise, operator };
|
|
1411
1556
|
}
|
|
1557
|
+
function warnOnFeud(query, diff) {
|
|
1558
|
+
__DEV__ && invariant.warn(90, getOperationName(query, "(anonymous)"), diff.missing?.missing);
|
|
1559
|
+
}
|
|
1412
1560
|
//# sourceMappingURL=ObservableQuery.js.map
|