@apollo/client 4.0.0-alpha.13 → 4.0.0-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/beige-spiders-hope.md +5 -0
- package/.changeset/curvy-flies-accept.md +5 -0
- package/.changeset/few-crabs-move.md +6 -0
- package/.changeset/funny-boats-wink.md +35 -0
- package/.changeset/gold-oranges-double.md +5 -0
- package/.changeset/little-parrots-bow.md +14 -0
- package/.changeset/olive-cougars-ring.md +9 -0
- package/.changeset/poor-spiders-hunt.md +23 -0
- package/.changeset/pre.json +20 -0
- package/.changeset/selfish-spoons-approve.md +44 -0
- package/.changeset/serious-items-develop.md +17 -0
- package/.changeset/sixty-bats-cry.md +6 -0
- package/.changeset/slimy-ants-bake.md +5 -0
- package/.changeset/sour-colts-tell.md +5 -0
- package/.changeset/sour-guests-poke.md +5 -0
- package/.changeset/spotty-mugs-poke.md +5 -0
- package/.changeset/strange-walls-march.md +5 -0
- package/.changeset/strong-rivers-fry.md +34 -0
- package/.changeset/stupid-pumpkins-travel.md +13 -0
- package/.changeset/thirty-pens-jump.md +5 -0
- package/.changeset/wicked-kiwis-buy.md +5 -0
- package/CHANGELOG.md +213 -0
- package/__cjs/cache/core/cache.cjs +9 -7
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +9 -7
- package/__cjs/cache/inmemory/entityStore.cjs +3 -3
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/cache/inmemory/inMemoryCache.d.cts +9 -7
- package/__cjs/cache/inmemory/key-extractor.cjs +1 -1
- package/__cjs/cache/inmemory/policies.cjs +4 -4
- package/__cjs/cache/inmemory/policies.cjs.map +1 -1
- package/__cjs/cache/inmemory/readFromStore.cjs +2 -2
- package/__cjs/cache/inmemory/readFromStore.cjs.map +1 -1
- package/__cjs/cache/inmemory/writeToStore.cjs +4 -4
- package/__cjs/cache/inmemory/writeToStore.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +23 -45
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +9 -21
- package/__cjs/core/ObservableQuery.cjs +564 -340
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +95 -33
- package/__cjs/core/QueryInfo.cjs +109 -179
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +9 -14
- package/__cjs/core/QueryManager.cjs +168 -108
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +12 -8
- package/__cjs/core/index.cjs +2 -1
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -3
- package/__cjs/core/types.d.cts +18 -6
- package/__cjs/errors/LinkError.cjs +5 -1
- package/__cjs/errors/LinkError.cjs.map +1 -1
- package/__cjs/errors/LinkError.d.cts +5 -1
- package/__cjs/errors/LocalStateError.cjs +27 -0
- package/__cjs/errors/LocalStateError.cjs.map +1 -0
- package/__cjs/errors/LocalStateError.d.cts +20 -0
- package/__cjs/errors/index.cjs +5 -1
- package/__cjs/errors/index.cjs.map +1 -1
- package/__cjs/errors/index.d.cts +2 -0
- package/__cjs/invariantErrorCodes.cjs +130 -57
- package/__cjs/link/core/ApolloLink.cjs +17 -11
- package/__cjs/link/core/ApolloLink.cjs.map +1 -1
- package/__cjs/link/core/ApolloLink.d.cts +15 -9
- package/__cjs/link/http/checkFetcher.cjs +1 -1
- package/__cjs/link/http/createHttpLink.cjs +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +1 -1
- package/__cjs/link/persisted-queries/index.cjs +2 -2
- package/__cjs/link/utils/transformOperation.cjs +1 -1
- package/__cjs/link/utils/transformOperation.cjs.map +1 -1
- package/__cjs/link/utils/validateOperation.cjs +1 -1
- package/__cjs/local-state/LocalState.cjs +535 -0
- package/__cjs/local-state/LocalState.cjs.map +1 -0
- package/__cjs/local-state/LocalState.d.cts +89 -0
- package/__cjs/local-state/index.cjs +6 -0
- package/__cjs/local-state/index.cjs.map +1 -0
- package/__cjs/local-state/index.d.cts +2 -0
- package/__cjs/masking/maskFragment.cjs +5 -1
- package/__cjs/masking/maskFragment.cjs.map +1 -1
- package/__cjs/masking/maskFragment.d.cts +5 -1
- package/__cjs/masking/maskOperation.cjs +5 -1
- package/__cjs/masking/maskOperation.cjs.map +1 -1
- package/__cjs/masking/maskOperation.d.cts +5 -1
- package/__cjs/masking/utils.cjs +5 -1
- package/__cjs/masking/utils.cjs.map +1 -1
- package/__cjs/masking/utils.d.cts +5 -1
- package/__cjs/react/hooks/internal/wrapHook.cjs +36 -34
- package/__cjs/react/hooks/internal/wrapHook.cjs.map +1 -1
- package/__cjs/react/hooks/internal/wrapHook.d.cts +42 -38
- package/__cjs/react/hooks/useQuery.cjs +10 -25
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +0 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +6 -9
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +25 -7
- package/__cjs/react/ssr/prerenderStatic.cjs +7 -0
- package/__cjs/react/ssr/prerenderStatic.cjs.map +1 -1
- package/__cjs/react/ssr/useSSRQuery.cjs +11 -2
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.cjs +7 -9
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +29 -22
- package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs +0 -4
- package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +7 -6
- package/__cjs/testing/core/types/deprecated.cjs +3 -0
- package/__cjs/testing/core/types/deprecated.cjs.map +1 -0
- package/__cjs/testing/core/types/deprecated.d.cts +10 -0
- package/__cjs/testing/index.cjs +6 -13
- package/__cjs/testing/index.cjs.map +1 -1
- package/__cjs/testing/index.d.cts +3 -2
- package/__cjs/testing/internal/ObservableStream.cjs +13 -1
- package/__cjs/testing/internal/ObservableStream.cjs.map +1 -1
- package/__cjs/testing/internal/ObservableStream.d.cts +12 -1
- package/__cjs/testing/internal/disposables/withCleanup.cjs +5 -1
- package/__cjs/testing/internal/disposables/withCleanup.cjs.map +1 -1
- package/__cjs/testing/internal/disposables/withCleanup.d.cts +5 -1
- package/__cjs/testing/internal/index.cjs +3 -1
- package/__cjs/testing/internal/index.cjs.map +1 -1
- package/__cjs/testing/internal/index.d.cts +1 -0
- package/__cjs/testing/internal/scenarios/index.cjs +4 -4
- package/__cjs/testing/internal/scenarios/index.cjs.map +1 -1
- package/__cjs/testing/internal/scenarios/index.d.cts +8 -8
- package/__cjs/testing/{core → internal}/wait.cjs +0 -4
- package/__cjs/testing/internal/wait.cjs.map +1 -0
- package/__cjs/testing/{core → internal}/wait.d.cts +0 -1
- package/__cjs/testing/matchers/index.cjs +2 -2
- package/__cjs/testing/matchers/index.cjs.map +1 -1
- package/__cjs/testing/matchers/toEmitTypedValue.cjs +1 -1
- package/__cjs/testing/matchers/toEmitTypedValue.cjs.map +1 -1
- package/__cjs/testing/matchers/toEmitTypedValue.d.cts +6 -1
- package/__cjs/testing/matchers/toRerenderWithSimilarSnapshot.cjs +31 -18
- package/__cjs/testing/matchers/toRerenderWithSimilarSnapshot.cjs.map +1 -1
- package/__cjs/testing/matchers/toRerenderWithSimilarSnapshot.d.cts +13 -6
- package/__cjs/testing/matchers/toStrictEqualTyped.cjs +1 -1
- package/__cjs/testing/matchers/toStrictEqualTyped.cjs.map +1 -1
- package/__cjs/testing/matchers/toStrictEqualTyped.d.cts +4 -0
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs +14 -2
- package/__cjs/testing/matchers/utils/getSerializableProperties.cjs.map +1 -1
- package/__cjs/testing/react/MockedProvider.cjs +4 -4
- package/__cjs/testing/react/MockedProvider.cjs.map +1 -1
- package/__cjs/testing/react/MockedProvider.d.cts +4 -5
- package/__cjs/utilities/graphql/DocumentTransform.cjs +10 -6
- package/__cjs/utilities/graphql/DocumentTransform.cjs.map +1 -1
- package/__cjs/utilities/graphql/DocumentTransform.d.cts +10 -6
- package/__cjs/utilities/internal/DeepMerger.cjs +5 -1
- package/__cjs/utilities/internal/DeepMerger.cjs.map +1 -1
- package/__cjs/utilities/internal/DeepMerger.d.cts +5 -1
- package/__cjs/utilities/internal/argumentsObjectFromField.cjs +5 -1
- package/__cjs/utilities/internal/argumentsObjectFromField.cjs.map +1 -1
- package/__cjs/utilities/internal/argumentsObjectFromField.d.cts +5 -1
- package/__cjs/utilities/internal/caches.cjs +24 -20
- package/__cjs/utilities/internal/caches.cjs.map +1 -1
- package/__cjs/utilities/internal/caches.d.cts +32 -24
- package/__cjs/utilities/internal/canUseDOM.cjs +5 -1
- package/__cjs/utilities/internal/canUseDOM.cjs.map +1 -1
- package/__cjs/utilities/internal/canUseDOM.d.cts +5 -1
- package/__cjs/utilities/internal/checkDocument.cjs +6 -3
- package/__cjs/utilities/internal/checkDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/checkDocument.d.cts +6 -3
- package/__cjs/utilities/internal/cloneDeep.cjs +6 -4
- package/__cjs/utilities/internal/cloneDeep.cjs.map +1 -1
- package/__cjs/utilities/internal/cloneDeep.d.cts +6 -4
- package/__cjs/utilities/internal/compact.cjs +7 -5
- package/__cjs/utilities/internal/compact.cjs.map +1 -1
- package/__cjs/utilities/internal/compact.d.cts +7 -5
- package/__cjs/utilities/internal/createFragmentMap.cjs +7 -4
- package/__cjs/utilities/internal/createFragmentMap.cjs.map +1 -1
- package/__cjs/utilities/internal/createFragmentMap.d.cts +7 -4
- package/__cjs/utilities/internal/createFulfilledPromise.cjs +5 -1
- package/__cjs/utilities/internal/createFulfilledPromise.cjs.map +1 -1
- package/__cjs/utilities/internal/createFulfilledPromise.d.cts +5 -1
- package/__cjs/utilities/internal/createRejectedPromise.cjs +5 -1
- package/__cjs/utilities/internal/createRejectedPromise.cjs.map +1 -1
- package/__cjs/utilities/internal/createRejectedPromise.d.cts +5 -1
- package/__cjs/utilities/internal/dealias.cjs +21 -0
- package/__cjs/utilities/internal/dealias.cjs.map +1 -0
- package/__cjs/utilities/internal/dealias.d.cts +5 -0
- package/__cjs/utilities/internal/decoratePromise.cjs +5 -1
- package/__cjs/utilities/internal/decoratePromise.cjs.map +1 -1
- package/__cjs/utilities/internal/decoratePromise.d.cts +5 -1
- package/__cjs/utilities/internal/deepFreeze.cjs +5 -1
- package/__cjs/utilities/internal/deepFreeze.cjs.map +1 -1
- package/__cjs/utilities/internal/deepFreeze.d.cts +5 -1
- package/__cjs/utilities/internal/filterMap.cjs +31 -0
- package/__cjs/utilities/internal/filterMap.cjs.map +1 -0
- package/__cjs/utilities/internal/filterMap.d.cts +4 -0
- package/__cjs/utilities/internal/getDefaultValues.cjs +5 -1
- package/__cjs/utilities/internal/getDefaultValues.cjs.map +1 -1
- package/__cjs/utilities/internal/getDefaultValues.d.cts +5 -1
- package/__cjs/utilities/internal/getFragmentDefinition.cjs +5 -1
- package/__cjs/utilities/internal/getFragmentDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentDefinition.d.cts +5 -1
- package/__cjs/utilities/internal/getFragmentDefinitions.cjs +5 -1
- package/__cjs/utilities/internal/getFragmentDefinitions.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentDefinitions.d.cts +5 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs +5 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentFromSelection.d.cts +5 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs +25 -23
- package/__cjs/utilities/internal/getFragmentQueryDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/getFragmentQueryDocument.d.cts +25 -23
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs +5 -1
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.cjs.map +1 -1
- package/__cjs/utilities/internal/getGraphQLErrorsFromResult.d.cts +5 -1
- package/__cjs/utilities/internal/getMainDefinition.cjs +8 -6
- package/__cjs/utilities/internal/getMainDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getMainDefinition.d.cts +8 -6
- package/__cjs/utilities/internal/getMemoryInternals.cjs +15 -9
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/getMemoryInternals.d.cts +15 -9
- package/__cjs/utilities/internal/getOperationDefinition.cjs +5 -1
- package/__cjs/utilities/internal/getOperationDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getOperationDefinition.d.cts +5 -1
- package/__cjs/utilities/internal/getOperationName.cjs +7 -5
- package/__cjs/utilities/internal/getOperationName.cjs.map +1 -1
- package/__cjs/utilities/internal/getOperationName.d.cts +6 -2
- package/__cjs/utilities/internal/getQueryDefinition.cjs +5 -1
- package/__cjs/utilities/internal/getQueryDefinition.cjs.map +1 -1
- package/__cjs/utilities/internal/getQueryDefinition.d.cts +5 -1
- package/__cjs/utilities/internal/getStoreKeyName.cjs +5 -1
- package/__cjs/utilities/internal/getStoreKeyName.cjs.map +1 -1
- package/__cjs/utilities/internal/getStoreKeyName.d.cts +5 -1
- package/__cjs/utilities/internal/graphQLResultHasError.cjs +5 -1
- package/__cjs/utilities/internal/graphQLResultHasError.cjs.map +1 -1
- package/__cjs/utilities/internal/graphQLResultHasError.d.cts +5 -1
- package/__cjs/utilities/internal/hasDirectives.cjs +5 -1
- package/__cjs/utilities/internal/hasDirectives.cjs.map +1 -1
- package/__cjs/utilities/internal/hasDirectives.d.cts +5 -1
- package/__cjs/utilities/internal/hasForcedResolvers.cjs +23 -0
- package/__cjs/utilities/internal/hasForcedResolvers.cjs.map +1 -0
- package/__cjs/utilities/internal/hasForcedResolvers.d.cts +3 -0
- package/__cjs/utilities/internal/index.cjs +8 -4
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -1
- package/__cjs/utilities/internal/isArray.cjs +6 -4
- package/__cjs/utilities/internal/isArray.cjs.map +1 -1
- package/__cjs/utilities/internal/isArray.d.cts +6 -4
- package/__cjs/utilities/internal/isDocumentNode.cjs +5 -1
- package/__cjs/utilities/internal/isDocumentNode.cjs.map +1 -1
- package/__cjs/utilities/internal/isDocumentNode.d.cts +5 -1
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs +5 -1
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.cjs.map +1 -1
- package/__cjs/utilities/internal/isExecutionPatchIncrementalResult.d.cts +5 -1
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs +5 -1
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.cjs.map +1 -1
- package/__cjs/utilities/internal/isExecutionPatchIninitialResult.d.cts +5 -1
- package/__cjs/utilities/internal/isExecutionPatchResult.cjs +5 -1
- package/__cjs/utilities/internal/isExecutionPatchResult.cjs.map +1 -1
- package/__cjs/utilities/internal/isExecutionPatchResult.d.cts +5 -1
- package/__cjs/utilities/internal/isField.cjs +5 -1
- package/__cjs/utilities/internal/isField.cjs.map +1 -1
- package/__cjs/utilities/internal/isField.d.cts +5 -1
- package/__cjs/utilities/internal/isNonEmptyArray.cjs +5 -1
- package/__cjs/utilities/internal/isNonEmptyArray.cjs.map +1 -1
- package/__cjs/utilities/internal/isNonEmptyArray.d.cts +5 -1
- package/__cjs/utilities/internal/isNonNullObject.cjs +5 -1
- package/__cjs/utilities/internal/isNonNullObject.cjs.map +1 -1
- package/__cjs/utilities/internal/isNonNullObject.d.cts +5 -1
- package/__cjs/utilities/internal/isPlainObject.cjs +5 -1
- package/__cjs/utilities/internal/isPlainObject.cjs.map +1 -1
- package/__cjs/utilities/internal/isPlainObject.d.cts +5 -1
- package/__cjs/utilities/internal/makeReference.cjs +5 -1
- package/__cjs/utilities/internal/makeReference.cjs.map +1 -1
- package/__cjs/utilities/internal/makeReference.d.cts +5 -1
- package/__cjs/utilities/internal/makeUniqueId.cjs +7 -5
- package/__cjs/utilities/internal/makeUniqueId.cjs.map +1 -1
- package/__cjs/utilities/internal/makeUniqueId.d.cts +7 -5
- package/__cjs/utilities/internal/maybeDeepFreeze.cjs +5 -1
- package/__cjs/utilities/internal/maybeDeepFreeze.cjs.map +1 -1
- package/__cjs/utilities/internal/maybeDeepFreeze.d.cts +5 -1
- package/__cjs/utilities/internal/mergeDeep.cjs +5 -1
- package/__cjs/utilities/internal/mergeDeep.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeDeep.d.cts +5 -1
- package/__cjs/utilities/internal/mergeDeepArray.cjs +5 -1
- package/__cjs/utilities/internal/mergeDeepArray.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeDeepArray.d.cts +5 -1
- package/__cjs/utilities/internal/mergeIncrementalData.cjs +5 -1
- package/__cjs/utilities/internal/mergeIncrementalData.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeIncrementalData.d.cts +5 -1
- package/__cjs/utilities/internal/mergeOptions.cjs +5 -1
- package/__cjs/utilities/internal/mergeOptions.cjs.map +1 -1
- package/__cjs/utilities/internal/mergeOptions.d.cts +5 -1
- package/__cjs/utilities/internal/omitDeep.cjs +5 -1
- package/__cjs/utilities/internal/omitDeep.cjs.map +1 -1
- package/__cjs/utilities/internal/omitDeep.d.cts +5 -1
- package/__cjs/utilities/internal/onAnyEvent.cjs +5 -1
- package/__cjs/utilities/internal/onAnyEvent.cjs.map +1 -1
- package/__cjs/utilities/internal/onAnyEvent.d.cts +5 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs +5 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.cjs.map +1 -1
- package/__cjs/utilities/internal/removeDirectivesFromDocument.d.cts +5 -1
- package/__cjs/utilities/internal/resultKeyNameFromField.cjs +5 -1
- package/__cjs/utilities/internal/resultKeyNameFromField.cjs.map +1 -1
- package/__cjs/utilities/internal/resultKeyNameFromField.d.cts +5 -1
- package/__cjs/utilities/internal/shouldInclude.cjs +5 -1
- package/__cjs/utilities/internal/shouldInclude.cjs.map +1 -1
- package/__cjs/utilities/internal/shouldInclude.d.cts +5 -1
- package/__cjs/utilities/internal/storeKeyNameFromField.cjs +5 -1
- package/__cjs/utilities/internal/storeKeyNameFromField.cjs.map +1 -1
- package/__cjs/utilities/internal/storeKeyNameFromField.d.cts +5 -1
- package/__cjs/utilities/internal/stringifyForDisplay.cjs +5 -1
- package/__cjs/utilities/internal/stringifyForDisplay.cjs.map +1 -1
- package/__cjs/utilities/internal/stringifyForDisplay.d.cts +5 -1
- package/__cjs/utilities/internal/toQueryResult.cjs +5 -1
- package/__cjs/utilities/internal/toQueryResult.cjs.map +1 -1
- package/__cjs/utilities/internal/toQueryResult.d.cts +5 -1
- package/__cjs/utilities/internal/types/DecoratedPromise.d.cts +5 -1
- package/__cjs/utilities/internal/types/DeepOmit.d.cts +5 -1
- package/__cjs/utilities/internal/types/DeepPartial.d.cts +5 -1
- package/__cjs/utilities/internal/types/FragmentMap.d.cts +6 -4
- package/__cjs/utilities/internal/types/FragmentMapFunction.d.cts +5 -1
- package/__cjs/utilities/internal/types/FulfilledPromise.d.cts +5 -1
- package/__cjs/utilities/internal/types/IsAny.d.cts +5 -1
- package/__cjs/utilities/internal/types/PendingPromise.d.cts +5 -1
- package/__cjs/utilities/internal/types/Prettify.d.cts +5 -1
- package/__cjs/utilities/internal/types/Primitive.d.cts +5 -1
- package/__cjs/utilities/internal/types/RejectedPromise.d.cts +5 -1
- package/__cjs/utilities/internal/types/RemoveIndexSignature.d.cts +5 -1
- package/__cjs/utilities/internal/types/VariablesOption.d.cts +5 -1
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs +5 -1
- package/__cjs/utilities/internal/valueToObjectRepresentation.cjs.map +1 -1
- package/__cjs/utilities/internal/valueToObjectRepresentation.d.cts +5 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +9 -7
- package/cache/core/cache.js +9 -7
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/entityStore.js +3 -3
- package/cache/inmemory/inMemoryCache.d.ts +9 -7
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +1 -1
- package/cache/inmemory/policies.js +4 -4
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/readFromStore.js +2 -2
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/writeToStore.js +4 -4
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/core/ApolloClient.d.ts +9 -21
- package/core/ApolloClient.js +23 -45
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +95 -33
- package/core/ObservableQuery.js +569 -345
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +9 -14
- package/core/QueryInfo.js +109 -179
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +12 -8
- package/core/QueryManager.js +151 -110
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +2 -3
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +18 -6
- package/errors/LinkError.d.ts +5 -1
- package/errors/LinkError.js +5 -1
- package/errors/LinkError.js.map +1 -1
- package/errors/LocalStateError.d.ts +20 -0
- package/errors/LocalStateError.js +23 -0
- package/errors/LocalStateError.js.map +1 -0
- package/errors/index.d.ts +2 -0
- package/errors/index.js +2 -0
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +130 -57
- package/legacyEntryPoints/local-state/index.d.ts +1 -0
- package/legacyEntryPoints/local-state/index.js +1 -0
- package/legacyEntryPoints/local-state/local-state.cjs +1 -0
- package/legacyEntryPoints/local-state/local-state.d.cts +1 -0
- package/link/core/ApolloLink.d.ts +15 -9
- package/link/core/ApolloLink.js +17 -11
- package/link/core/ApolloLink.js.map +1 -1
- package/link/http/checkFetcher.js +1 -1
- package/link/http/createHttpLink.js +1 -1
- package/link/http/parseAndCheckHttpResponse.js +1 -1
- package/link/http/serializeFetchParameter.js +1 -1
- package/link/persisted-queries/index.js +2 -2
- package/link/utils/transformOperation.js +1 -1
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/validateOperation.js +1 -1
- package/local-state/LocalState.d.ts +89 -0
- package/local-state/LocalState.js +527 -0
- package/local-state/LocalState.js.map +1 -0
- package/local-state/index.d.ts +2 -0
- package/local-state/index.js +2 -0
- package/local-state/index.js.map +1 -0
- package/masking/maskFragment.d.ts +5 -1
- package/masking/maskFragment.js +5 -1
- package/masking/maskFragment.js.map +1 -1
- package/masking/maskOperation.d.ts +5 -1
- package/masking/maskOperation.js +5 -1
- package/masking/maskOperation.js.map +1 -1
- package/masking/utils.d.ts +5 -1
- package/masking/utils.js +5 -1
- package/masking/utils.js.map +1 -1
- package/package.json +7 -155
- package/react/hooks/internal/wrapHook.d.ts +42 -38
- package/react/hooks/internal/wrapHook.js +36 -34
- package/react/hooks/internal/wrapHook.js.map +1 -1
- package/react/hooks/useQuery.d.ts +0 -1
- package/react/hooks/useQuery.js +10 -25
- package/react/hooks/useQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +25 -7
- package/react/internal/cache/QueryReference.js +6 -9
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/ssr/prerenderStatic.js +7 -0
- package/react/ssr/prerenderStatic.js.map +1 -1
- package/react/ssr/useSSRQuery.js +11 -2
- package/react/ssr/useSSRQuery.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +29 -22
- package/testing/core/mocking/mockLink.js +9 -10
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +7 -6
- package/testing/core/mocking/mockSubscriptionLink.js +0 -3
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/testing/core/types/deprecated.d.ts +10 -0
- package/testing/core/types/deprecated.js +2 -0
- package/testing/core/types/deprecated.js.map +1 -0
- package/testing/index.d.ts +3 -2
- package/testing/index.js +2 -1
- package/testing/index.js.map +1 -1
- package/testing/internal/ObservableStream.d.ts +12 -1
- package/testing/internal/ObservableStream.js +13 -1
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/disposables/withCleanup.d.ts +5 -1
- package/testing/internal/disposables/withCleanup.js +5 -1
- package/testing/internal/disposables/withCleanup.js.map +1 -1
- package/testing/internal/index.d.ts +1 -0
- package/testing/internal/index.js +2 -1
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/scenarios/index.d.ts +8 -8
- package/testing/internal/scenarios/index.js +4 -4
- package/testing/internal/scenarios/index.js.map +1 -1
- package/testing/{core → internal}/wait.d.ts +0 -1
- package/testing/{core → internal}/wait.js +0 -3
- package/testing/internal/wait.js.map +1 -0
- package/testing/matchers/index.js +2 -2
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEmitTypedValue.d.ts +6 -1
- package/testing/matchers/toEmitTypedValue.js +1 -1
- package/testing/matchers/toEmitTypedValue.js.map +1 -1
- package/testing/matchers/toRerenderWithSimilarSnapshot.d.ts +13 -6
- package/testing/matchers/toRerenderWithSimilarSnapshot.js +30 -15
- package/testing/matchers/toRerenderWithSimilarSnapshot.js.map +1 -1
- package/testing/matchers/toStrictEqualTyped.d.ts +4 -0
- package/testing/matchers/toStrictEqualTyped.js +1 -1
- package/testing/matchers/toStrictEqualTyped.js.map +1 -1
- package/testing/matchers/utils/getSerializableProperties.js +14 -2
- package/testing/matchers/utils/getSerializableProperties.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +4 -5
- package/testing/react/MockedProvider.js +3 -3
- package/testing/react/MockedProvider.js.map +1 -1
- package/utilities/graphql/DocumentTransform.d.ts +10 -6
- package/utilities/graphql/DocumentTransform.js +10 -6
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/internal/DeepMerger.d.ts +5 -1
- package/utilities/internal/DeepMerger.js +5 -1
- package/utilities/internal/DeepMerger.js.map +1 -1
- package/utilities/internal/argumentsObjectFromField.d.ts +5 -1
- package/utilities/internal/argumentsObjectFromField.js +5 -1
- package/utilities/internal/argumentsObjectFromField.js.map +1 -1
- package/utilities/internal/caches.d.ts +32 -24
- package/utilities/internal/caches.js +24 -20
- package/utilities/internal/caches.js.map +1 -1
- package/utilities/internal/canUseDOM.d.ts +5 -1
- package/utilities/internal/canUseDOM.js +5 -1
- package/utilities/internal/canUseDOM.js.map +1 -1
- package/utilities/internal/checkDocument.d.ts +6 -3
- package/utilities/internal/checkDocument.js +6 -3
- package/utilities/internal/checkDocument.js.map +1 -1
- package/utilities/internal/cloneDeep.d.ts +6 -4
- package/utilities/internal/cloneDeep.js +6 -4
- package/utilities/internal/cloneDeep.js.map +1 -1
- package/utilities/internal/compact.d.ts +7 -5
- package/utilities/internal/compact.js +7 -5
- package/utilities/internal/compact.js.map +1 -1
- package/utilities/internal/createFragmentMap.d.ts +7 -4
- package/utilities/internal/createFragmentMap.js +7 -4
- package/utilities/internal/createFragmentMap.js.map +1 -1
- package/utilities/internal/createFulfilledPromise.d.ts +5 -1
- package/utilities/internal/createFulfilledPromise.js +5 -1
- package/utilities/internal/createFulfilledPromise.js.map +1 -1
- package/utilities/internal/createRejectedPromise.d.ts +5 -1
- package/utilities/internal/createRejectedPromise.js +5 -1
- package/utilities/internal/createRejectedPromise.js.map +1 -1
- package/utilities/internal/dealias.d.ts +5 -0
- package/utilities/internal/dealias.js +18 -0
- package/utilities/internal/dealias.js.map +1 -0
- package/utilities/internal/decoratePromise.d.ts +5 -1
- package/utilities/internal/decoratePromise.js +5 -1
- package/utilities/internal/decoratePromise.js.map +1 -1
- package/utilities/internal/deepFreeze.d.ts +5 -1
- package/utilities/internal/deepFreeze.js +5 -1
- package/utilities/internal/deepFreeze.js.map +1 -1
- package/utilities/internal/filterMap.d.ts +4 -0
- package/utilities/internal/filterMap.js +28 -0
- package/utilities/internal/filterMap.js.map +1 -0
- package/utilities/internal/getDefaultValues.d.ts +5 -1
- package/utilities/internal/getDefaultValues.js +5 -1
- package/utilities/internal/getDefaultValues.js.map +1 -1
- package/utilities/internal/getFragmentDefinition.d.ts +5 -1
- package/utilities/internal/getFragmentDefinition.js +5 -1
- package/utilities/internal/getFragmentDefinition.js.map +1 -1
- package/utilities/internal/getFragmentDefinitions.d.ts +5 -1
- package/utilities/internal/getFragmentDefinitions.js +5 -1
- package/utilities/internal/getFragmentDefinitions.js.map +1 -1
- package/utilities/internal/getFragmentFromSelection.d.ts +5 -1
- package/utilities/internal/getFragmentFromSelection.js +5 -1
- package/utilities/internal/getFragmentFromSelection.js.map +1 -1
- package/utilities/internal/getFragmentQueryDocument.d.ts +25 -23
- package/utilities/internal/getFragmentQueryDocument.js +25 -23
- package/utilities/internal/getFragmentQueryDocument.js.map +1 -1
- package/utilities/internal/getGraphQLErrorsFromResult.d.ts +5 -1
- package/utilities/internal/getGraphQLErrorsFromResult.js +5 -1
- package/utilities/internal/getGraphQLErrorsFromResult.js.map +1 -1
- package/utilities/internal/getMainDefinition.d.ts +8 -6
- package/utilities/internal/getMainDefinition.js +8 -6
- package/utilities/internal/getMainDefinition.js.map +1 -1
- package/utilities/internal/getMemoryInternals.d.ts +15 -9
- package/utilities/internal/getMemoryInternals.js +15 -9
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/getOperationDefinition.d.ts +5 -1
- package/utilities/internal/getOperationDefinition.js +5 -1
- package/utilities/internal/getOperationDefinition.js.map +1 -1
- package/utilities/internal/getOperationName.d.ts +6 -2
- package/utilities/internal/getOperationName.js +7 -5
- package/utilities/internal/getOperationName.js.map +1 -1
- package/utilities/internal/getQueryDefinition.d.ts +5 -1
- package/utilities/internal/getQueryDefinition.js +5 -1
- package/utilities/internal/getQueryDefinition.js.map +1 -1
- package/utilities/internal/getStoreKeyName.d.ts +5 -1
- package/utilities/internal/getStoreKeyName.js +5 -1
- package/utilities/internal/getStoreKeyName.js.map +1 -1
- package/utilities/internal/globals/global.js +2 -2
- package/utilities/internal/globals/global.js.map +1 -1
- package/utilities/internal/graphQLResultHasError.d.ts +5 -1
- package/utilities/internal/graphQLResultHasError.js +5 -1
- package/utilities/internal/graphQLResultHasError.js.map +1 -1
- package/utilities/internal/hasDirectives.d.ts +5 -1
- package/utilities/internal/hasDirectives.js +5 -1
- package/utilities/internal/hasDirectives.js.map +1 -1
- package/utilities/internal/hasForcedResolvers.d.ts +3 -0
- package/utilities/internal/hasForcedResolvers.js +20 -0
- package/utilities/internal/hasForcedResolvers.js.map +1 -0
- package/utilities/internal/index.d.ts +3 -1
- package/utilities/internal/index.js +3 -1
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/isArray.d.ts +6 -4
- package/utilities/internal/isArray.js +6 -4
- package/utilities/internal/isArray.js.map +1 -1
- package/utilities/internal/isDocumentNode.d.ts +5 -1
- package/utilities/internal/isDocumentNode.js +5 -1
- package/utilities/internal/isDocumentNode.js.map +1 -1
- package/utilities/internal/isExecutionPatchIncrementalResult.d.ts +5 -1
- package/utilities/internal/isExecutionPatchIncrementalResult.js +5 -1
- package/utilities/internal/isExecutionPatchIncrementalResult.js.map +1 -1
- package/utilities/internal/isExecutionPatchIninitialResult.d.ts +5 -1
- package/utilities/internal/isExecutionPatchIninitialResult.js +5 -1
- package/utilities/internal/isExecutionPatchIninitialResult.js.map +1 -1
- package/utilities/internal/isExecutionPatchResult.d.ts +5 -1
- package/utilities/internal/isExecutionPatchResult.js +5 -1
- package/utilities/internal/isExecutionPatchResult.js.map +1 -1
- package/utilities/internal/isField.d.ts +5 -1
- package/utilities/internal/isField.js +5 -1
- package/utilities/internal/isField.js.map +1 -1
- package/utilities/internal/isNonEmptyArray.d.ts +5 -1
- package/utilities/internal/isNonEmptyArray.js +5 -1
- package/utilities/internal/isNonEmptyArray.js.map +1 -1
- package/utilities/internal/isNonNullObject.d.ts +5 -1
- package/utilities/internal/isNonNullObject.js +5 -1
- package/utilities/internal/isNonNullObject.js.map +1 -1
- package/utilities/internal/isPlainObject.d.ts +5 -1
- package/utilities/internal/isPlainObject.js +5 -1
- package/utilities/internal/isPlainObject.js.map +1 -1
- package/utilities/internal/makeReference.d.ts +5 -1
- package/utilities/internal/makeReference.js +5 -1
- package/utilities/internal/makeReference.js.map +1 -1
- package/utilities/internal/makeUniqueId.d.ts +7 -5
- package/utilities/internal/makeUniqueId.js +7 -5
- package/utilities/internal/makeUniqueId.js.map +1 -1
- package/utilities/internal/maybeDeepFreeze.d.ts +5 -1
- package/utilities/internal/maybeDeepFreeze.js +5 -1
- package/utilities/internal/maybeDeepFreeze.js.map +1 -1
- package/utilities/internal/mergeDeep.d.ts +5 -1
- package/utilities/internal/mergeDeep.js +5 -1
- package/utilities/internal/mergeDeep.js.map +1 -1
- package/utilities/internal/mergeDeepArray.d.ts +5 -1
- package/utilities/internal/mergeDeepArray.js +5 -1
- package/utilities/internal/mergeDeepArray.js.map +1 -1
- package/utilities/internal/mergeIncrementalData.d.ts +5 -1
- package/utilities/internal/mergeIncrementalData.js +5 -1
- package/utilities/internal/mergeIncrementalData.js.map +1 -1
- package/utilities/internal/mergeOptions.d.ts +5 -1
- package/utilities/internal/mergeOptions.js +5 -1
- package/utilities/internal/mergeOptions.js.map +1 -1
- package/utilities/internal/omitDeep.d.ts +5 -1
- package/utilities/internal/omitDeep.js +5 -1
- package/utilities/internal/omitDeep.js.map +1 -1
- package/utilities/internal/onAnyEvent.d.ts +5 -1
- package/utilities/internal/onAnyEvent.js +5 -1
- package/utilities/internal/onAnyEvent.js.map +1 -1
- package/utilities/internal/removeDirectivesFromDocument.d.ts +5 -1
- package/utilities/internal/removeDirectivesFromDocument.js +5 -1
- package/utilities/internal/removeDirectivesFromDocument.js.map +1 -1
- package/utilities/internal/resultKeyNameFromField.d.ts +5 -1
- package/utilities/internal/resultKeyNameFromField.js +5 -1
- package/utilities/internal/resultKeyNameFromField.js.map +1 -1
- package/utilities/internal/shouldInclude.d.ts +5 -1
- package/utilities/internal/shouldInclude.js +5 -1
- package/utilities/internal/shouldInclude.js.map +1 -1
- package/utilities/internal/storeKeyNameFromField.d.ts +5 -1
- package/utilities/internal/storeKeyNameFromField.js +5 -1
- package/utilities/internal/storeKeyNameFromField.js.map +1 -1
- package/utilities/internal/stringifyForDisplay.d.ts +5 -1
- package/utilities/internal/stringifyForDisplay.js +5 -1
- package/utilities/internal/stringifyForDisplay.js.map +1 -1
- package/utilities/internal/toQueryResult.d.ts +5 -1
- package/utilities/internal/toQueryResult.js +5 -1
- package/utilities/internal/toQueryResult.js.map +1 -1
- package/utilities/internal/types/DecoratedPromise.d.ts +5 -1
- package/utilities/internal/types/DeepOmit.d.ts +5 -1
- package/utilities/internal/types/DeepPartial.d.ts +5 -1
- package/utilities/internal/types/FragmentMap.d.ts +6 -4
- package/utilities/internal/types/FragmentMapFunction.d.ts +5 -1
- package/utilities/internal/types/FulfilledPromise.d.ts +5 -1
- package/utilities/internal/types/IsAny.d.ts +5 -1
- package/utilities/internal/types/PendingPromise.d.ts +5 -1
- package/utilities/internal/types/Prettify.d.ts +5 -1
- package/utilities/internal/types/Primitive.d.ts +5 -1
- package/utilities/internal/types/RejectedPromise.d.ts +5 -1
- package/utilities/internal/types/RemoveIndexSignature.d.ts +5 -1
- package/utilities/internal/types/VariablesOption.d.ts +5 -1
- package/utilities/internal/valueToObjectRepresentation.d.ts +5 -1
- package/utilities/internal/valueToObjectRepresentation.js +5 -1
- package/utilities/internal/valueToObjectRepresentation.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/core/LocalState.cjs +0 -355
- package/__cjs/core/LocalState.cjs.map +0 -1
- package/__cjs/core/LocalState.d.cts +0 -53
- package/__cjs/testing/core/index.cjs +0 -20
- package/__cjs/testing/core/index.cjs.map +0 -1
- package/__cjs/testing/core/index.d.cts +0 -7
- package/__cjs/testing/core/mocking/mockClient.cjs +0 -17
- package/__cjs/testing/core/mocking/mockClient.cjs.map +0 -1
- package/__cjs/testing/core/mocking/mockClient.d.cts +0 -4
- package/__cjs/testing/core/wait.cjs.map +0 -1
- package/__cjs/testing/core/withConsoleSpy.cjs +0 -33
- package/__cjs/testing/core/withConsoleSpy.cjs.map +0 -1
- package/__cjs/testing/core/withConsoleSpy.d.cts +0 -7
- package/__cjs/utilities/internal/removeClientSetsFromDocument.cjs +0 -21
- package/__cjs/utilities/internal/removeClientSetsFromDocument.cjs.map +0 -1
- package/__cjs/utilities/internal/removeClientSetsFromDocument.d.cts +0 -8
- package/core/LocalState.d.ts +0 -53
- package/core/LocalState.js +0 -351
- package/core/LocalState.js.map +0 -1
- package/legacyEntryPoints/testing/core/core.cjs +0 -1
- package/legacyEntryPoints/testing/core/core.d.cts +0 -1
- package/legacyEntryPoints/testing/core/index.d.ts +0 -1
- package/legacyEntryPoints/testing/core/index.js +0 -1
- package/testing/core/index.d.ts +0 -7
- package/testing/core/index.js +0 -6
- package/testing/core/index.js.map +0 -1
- package/testing/core/mocking/mockClient.d.ts +0 -4
- package/testing/core/mocking/mockClient.js +0 -14
- package/testing/core/mocking/mockClient.js.map +0 -1
- package/testing/core/wait.js.map +0 -1
- package/testing/core/withConsoleSpy.d.ts +0 -7
- package/testing/core/withConsoleSpy.js +0 -28
- package/testing/core/withConsoleSpy.js.map +0 -1
- package/utilities/internal/removeClientSetsFromDocument.d.ts +0 -8
- package/utilities/internal/removeClientSetsFromDocument.js +0 -18
- package/utilities/internal/removeClientSetsFromDocument.js.map +0 -1
|
@@ -16,15 +16,28 @@ const equalByQuery_js_1 = require("./equalByQuery.cjs");
|
|
|
16
16
|
const networkStatus_js_1 = require("./networkStatus.cjs");
|
|
17
17
|
const { assign, hasOwnProperty } = Object;
|
|
18
18
|
const newNetworkStatusSymbol = Symbol();
|
|
19
|
-
const uninitialized = {
|
|
19
|
+
const uninitialized = {
|
|
20
|
+
loading: true,
|
|
21
|
+
networkStatus: networkStatus_js_1.NetworkStatus.loading,
|
|
22
|
+
data: undefined,
|
|
23
|
+
partial: true,
|
|
24
|
+
};
|
|
25
|
+
const empty = {
|
|
26
|
+
loading: false,
|
|
27
|
+
networkStatus: networkStatus_js_1.NetworkStatus.ready,
|
|
28
|
+
data: undefined,
|
|
29
|
+
partial: true,
|
|
30
|
+
};
|
|
20
31
|
class ObservableQuery {
|
|
21
32
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
33
|
+
* @internal
|
|
34
|
+
* A slot used by the `useQuery` hook to indicate that `client.watchQuery`
|
|
35
|
+
* should not register the query immediately, but instead wait for the query to
|
|
36
|
+
* be started registered with the `QueryManager` when `useSyncExternalStore`
|
|
37
|
+
* actively subscribes to it.
|
|
38
|
+
*
|
|
39
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
40
|
+
*/
|
|
28
41
|
static inactiveOnCreation = new optimism_1.Slot();
|
|
29
42
|
options;
|
|
30
43
|
queryId;
|
|
@@ -42,23 +55,58 @@ class ObservableQuery {
|
|
|
42
55
|
get variables() {
|
|
43
56
|
return this.options.variables;
|
|
44
57
|
}
|
|
58
|
+
unsubscribeFromCache;
|
|
59
|
+
input;
|
|
45
60
|
subject;
|
|
46
61
|
observable;
|
|
47
62
|
isTornDown;
|
|
48
63
|
queryManager;
|
|
49
64
|
subscriptions = new Set();
|
|
50
|
-
|
|
51
|
-
|
|
65
|
+
/**
|
|
66
|
+
* If an `ObservableQuery` is created with a `network-only` fetch policy,
|
|
67
|
+
* it should actually start receiving cache updates, but not before it has
|
|
68
|
+
* received the first result from the network.
|
|
69
|
+
*/
|
|
70
|
+
waitForNetworkResult;
|
|
52
71
|
lastQuery;
|
|
53
72
|
queryInfo;
|
|
54
73
|
linkSubscription;
|
|
55
|
-
linkObservable;
|
|
56
74
|
pollingInfo;
|
|
57
|
-
networkStatus
|
|
75
|
+
get networkStatus() {
|
|
76
|
+
return this.subject.getValue().result.networkStatus;
|
|
77
|
+
}
|
|
58
78
|
constructor({ queryManager, queryInfo, options, }) {
|
|
59
|
-
this.networkStatus = networkStatus_js_1.NetworkStatus.loading;
|
|
60
79
|
let startedInactive = ObservableQuery.inactiveOnCreation.getValue();
|
|
61
|
-
|
|
80
|
+
// related classes
|
|
81
|
+
this.queryInfo = queryInfo;
|
|
82
|
+
this.queryManager = queryManager;
|
|
83
|
+
// active state
|
|
84
|
+
this.waitForNetworkResult = options.fetchPolicy === "network-only";
|
|
85
|
+
this.isTornDown = false;
|
|
86
|
+
this.subscribeToMore = this.subscribeToMore.bind(this);
|
|
87
|
+
this.maskResult = this.maskResult.bind(this);
|
|
88
|
+
const { watchQuery: { fetchPolicy: defaultFetchPolicy = "cache-first" } = {}, } = queryManager.defaultOptions;
|
|
89
|
+
const { fetchPolicy = defaultFetchPolicy,
|
|
90
|
+
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
91
|
+
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
92
|
+
this.lastQuery = options.query;
|
|
93
|
+
this.options = {
|
|
94
|
+
...options,
|
|
95
|
+
// Remember the initial options.fetchPolicy so we can revert back to this
|
|
96
|
+
// policy when variables change. This information can also be specified
|
|
97
|
+
// (or overridden) by providing options.initialFetchPolicy explicitly.
|
|
98
|
+
initialFetchPolicy,
|
|
99
|
+
// This ensures this.options.fetchPolicy always has a string value, in
|
|
100
|
+
// case options.fetchPolicy was not provided.
|
|
101
|
+
fetchPolicy,
|
|
102
|
+
variables: this.getVariablesWithDefaults(options.variables),
|
|
103
|
+
};
|
|
104
|
+
this.subject = new rxjs_1.BehaviorSubject({
|
|
105
|
+
query: this.query,
|
|
106
|
+
variables: this.variables,
|
|
107
|
+
result: uninitialized,
|
|
108
|
+
meta: {},
|
|
109
|
+
});
|
|
62
110
|
this.observable = this.subject.pipe((0, rxjs_1.tap)({
|
|
63
111
|
subscribe: () => {
|
|
64
112
|
if (startedInactive) {
|
|
@@ -66,22 +114,6 @@ class ObservableQuery {
|
|
|
66
114
|
startedInactive = false;
|
|
67
115
|
}
|
|
68
116
|
if (!this.subject.observed) {
|
|
69
|
-
if (this.subject.value === uninitialized) {
|
|
70
|
-
// Emitting a value in the `subscribe` callback of `tap` gives
|
|
71
|
-
// the subject a chance to save this initial result without
|
|
72
|
-
// emitting the placeholder value since this callback is executed
|
|
73
|
-
// before `tap` subscribes to the source observable (the subject).
|
|
74
|
-
// `reobserve` also has the chance to update this value if it
|
|
75
|
-
// synchronously emits one (usually due to reporting a cache
|
|
76
|
-
// value).
|
|
77
|
-
//
|
|
78
|
-
// We don't initialize the `BehaviorSubject` with
|
|
79
|
-
// `getInitialResult` because its possible the cache might have
|
|
80
|
-
// updated between when the `ObservableQuery` was instantiated and
|
|
81
|
-
// when it is subscribed to. Updating the value here ensures we
|
|
82
|
-
// report the most up-to-date result from the cache.
|
|
83
|
-
this.subject.next(this.getInitialResult());
|
|
84
|
-
}
|
|
85
117
|
this.reobserve();
|
|
86
118
|
// TODO: See if we can rework updatePolling to better handle this.
|
|
87
119
|
// reobserve calls updatePolling but this `subscribe` callback is
|
|
@@ -96,45 +128,53 @@ class ObservableQuery {
|
|
|
96
128
|
this.tearDownQuery();
|
|
97
129
|
}
|
|
98
130
|
},
|
|
99
|
-
}), (0,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
131
|
+
}), (0, internal_1.filterMap)(({ query, variables, result: current, meta }, context) => {
|
|
132
|
+
const { shouldEmit } = meta;
|
|
133
|
+
if (current === uninitialized) {
|
|
134
|
+
// reset internal state after `ObservableQuery.reset()`
|
|
135
|
+
context.previous = undefined;
|
|
136
|
+
context.previousVariables = undefined;
|
|
137
|
+
}
|
|
138
|
+
if (this.options.fetchPolicy === "standby" ||
|
|
139
|
+
shouldEmit === 2 /* EmitBehavior.never */)
|
|
140
|
+
return;
|
|
141
|
+
if (shouldEmit === 1 /* EmitBehavior.force */)
|
|
142
|
+
return emit();
|
|
143
|
+
const { previous, previousVariables } = context;
|
|
144
|
+
if (previous) {
|
|
145
|
+
const documentInfo = this.queryManager.getDocumentInfo(query);
|
|
146
|
+
const dataMasking = this.queryManager.dataMasking;
|
|
147
|
+
const maskedQuery = dataMasking ? documentInfo.nonReactiveQuery : query;
|
|
148
|
+
const resultIsEqual = dataMasking || documentInfo.hasNonreactiveDirective ?
|
|
149
|
+
(0, equalByQuery_js_1.equalByQuery)(maskedQuery, previous, current, variables)
|
|
150
|
+
: (0, equality_1.equal)(previous, current);
|
|
151
|
+
if (resultIsEqual && (0, equality_1.equal)(previousVariables, variables)) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (shouldEmit === 3 /* EmitBehavior.networkStatusChange */ &&
|
|
156
|
+
(!this.options.notifyOnNetworkStatusChange ||
|
|
157
|
+
(0, equality_1.equal)(previous, current))) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
return emit();
|
|
161
|
+
function emit() {
|
|
162
|
+
context.previous = current;
|
|
163
|
+
context.previousVariables = variables;
|
|
164
|
+
return current;
|
|
165
|
+
}
|
|
166
|
+
}, () => ({})));
|
|
107
167
|
this["@@observable"] = () => this;
|
|
108
168
|
if (Symbol.observable) {
|
|
109
169
|
this[Symbol.observable] = () => this;
|
|
110
170
|
}
|
|
111
171
|
this.pipe = this.observable.pipe.bind(this.observable);
|
|
112
172
|
this.subscribe = this.observable.subscribe.bind(this.observable);
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
this.
|
|
116
|
-
|
|
117
|
-
this.
|
|
118
|
-
this.isTornDown = false;
|
|
119
|
-
this.subscribe = this.subscribe.bind(this);
|
|
120
|
-
this.subscribeToMore = this.subscribeToMore.bind(this);
|
|
121
|
-
this.maskResult = this.maskResult.bind(this);
|
|
122
|
-
const { watchQuery: { fetchPolicy: defaultFetchPolicy = "cache-first" } = {}, } = queryManager.defaultOptions;
|
|
123
|
-
const { fetchPolicy = defaultFetchPolicy,
|
|
124
|
-
// Make sure we don't store "standby" as the initialFetchPolicy.
|
|
125
|
-
initialFetchPolicy = fetchPolicy === "standby" ? defaultFetchPolicy : (fetchPolicy), } = options;
|
|
126
|
-
this.lastQuery = options.query;
|
|
127
|
-
this.options = {
|
|
128
|
-
...options,
|
|
129
|
-
// Remember the initial options.fetchPolicy so we can revert back to this
|
|
130
|
-
// policy when variables change. This information can also be specified
|
|
131
|
-
// (or overridden) by providing options.initialFetchPolicy explicitly.
|
|
132
|
-
initialFetchPolicy,
|
|
133
|
-
// This ensures this.options.fetchPolicy always has a string value, in
|
|
134
|
-
// case options.fetchPolicy was not provided.
|
|
135
|
-
fetchPolicy,
|
|
136
|
-
variables: this.getVariablesWithDefaults(options.variables),
|
|
137
|
-
};
|
|
173
|
+
this.input = new rxjs_1.Subject();
|
|
174
|
+
// we want to feed many streams into `this.subject`, but none of them should
|
|
175
|
+
// be able to close `this.input`
|
|
176
|
+
this.input.complete = () => { };
|
|
177
|
+
this.input.pipe(this.operator).subscribe(this.subject);
|
|
138
178
|
this.queryId = queryInfo.queryId || queryManager.generateQueryId();
|
|
139
179
|
const opDef = (0, internal_1.getOperationDefinition)(this.query);
|
|
140
180
|
this.queryName = opDef && opDef.name && opDef.name.value;
|
|
@@ -146,14 +186,26 @@ class ObservableQuery {
|
|
|
146
186
|
pipe;
|
|
147
187
|
[Symbol.observable];
|
|
148
188
|
["@@observable"];
|
|
149
|
-
/**
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*
|
|
192
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
193
|
+
*/
|
|
150
194
|
resetDiff() {
|
|
151
195
|
this.queryInfo.resetDiff();
|
|
152
196
|
}
|
|
153
|
-
|
|
197
|
+
getCacheDiff({ optimistic = true } = {}) {
|
|
198
|
+
return this.queryManager.cache.diff({
|
|
199
|
+
query: this.query,
|
|
200
|
+
variables: this.variables,
|
|
201
|
+
returnPartialData: true,
|
|
202
|
+
optimistic,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
getInitialResult(initialFetchPolicy) {
|
|
154
206
|
const fetchPolicy = this.queryManager.prioritizeCacheValues ?
|
|
155
207
|
"cache-first"
|
|
156
|
-
: this.options.fetchPolicy;
|
|
208
|
+
: initialFetchPolicy || this.options.fetchPolicy;
|
|
157
209
|
const defaultResult = {
|
|
158
210
|
data: undefined,
|
|
159
211
|
loading: true,
|
|
@@ -161,7 +213,7 @@ class ObservableQuery {
|
|
|
161
213
|
partial: true,
|
|
162
214
|
};
|
|
163
215
|
const cacheResult = () => {
|
|
164
|
-
const diff = this.
|
|
216
|
+
const diff = this.getCacheDiff();
|
|
165
217
|
return this.maskResult({
|
|
166
218
|
data:
|
|
167
219
|
// TODO: queryInfo.getDiff should handle this since cache.diff returns a
|
|
@@ -194,118 +246,97 @@ class ObservableQuery {
|
|
|
194
246
|
return defaultResult;
|
|
195
247
|
}
|
|
196
248
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
};
|
|
208
|
-
let { fetchPolicy = "cache-first" } = this.options;
|
|
209
|
-
const { prioritizeCacheValues } = this.queryManager;
|
|
210
|
-
if (prioritizeCacheValues) {
|
|
211
|
-
fetchPolicy = "cache-first";
|
|
249
|
+
resubscribeCache() {
|
|
250
|
+
const { variables, fetchPolicy } = this.options;
|
|
251
|
+
const query = this.query;
|
|
252
|
+
const shouldUnsubscribe = fetchPolicy === "standby" ||
|
|
253
|
+
fetchPolicy === "no-cache" ||
|
|
254
|
+
this.waitForNetworkResult;
|
|
255
|
+
const shouldResubscribe = !isEqualQuery({ query, variables }, this.unsubscribeFromCache) &&
|
|
256
|
+
!this.waitForNetworkResult;
|
|
257
|
+
if (shouldUnsubscribe || shouldResubscribe) {
|
|
258
|
+
this.unsubscribeFromCache?.();
|
|
212
259
|
}
|
|
213
|
-
if (
|
|
214
|
-
|
|
215
|
-
// redelivering a previously delivered result.
|
|
216
|
-
skipCacheDataFor(fetchPolicy) ||
|
|
217
|
-
// If this.options.query has @client(always: true) fields, we cannot
|
|
218
|
-
// trust diff.result, since it was read from the cache without running
|
|
219
|
-
// local resolvers (and it's too late to run resolvers now, since we must
|
|
220
|
-
// return a result synchronously).
|
|
221
|
-
this.queryManager.getDocumentInfo(this.query).hasForcedResolvers) {
|
|
222
|
-
// Fall through.
|
|
223
|
-
}
|
|
224
|
-
else if (this.waitForOwnResult && !prioritizeCacheValues) {
|
|
225
|
-
// This would usually be a part of `QueryInfo.getDiff()`.
|
|
226
|
-
// which we skip in the waitForOwnResult case since we are not
|
|
227
|
-
// interested in the diff.
|
|
228
|
-
this.queryInfo["updateWatch"]();
|
|
260
|
+
if (shouldUnsubscribe || !shouldResubscribe) {
|
|
261
|
+
return;
|
|
229
262
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
263
|
+
const watch = {
|
|
264
|
+
query,
|
|
265
|
+
variables,
|
|
266
|
+
optimistic: true,
|
|
267
|
+
watcher: this,
|
|
268
|
+
callback: (diff) => {
|
|
269
|
+
const info = this.queryManager.getDocumentInfo(query);
|
|
270
|
+
if (info.hasClientExports || info.hasForcedResolvers) {
|
|
271
|
+
// If this is not set to something different than `diff`, we will
|
|
272
|
+
// not be notified about future cache changes with an equal `diff`.
|
|
273
|
+
// That would be the case if we are working with client-only fields
|
|
274
|
+
// that are forced or with `exports` fields that might change, causing
|
|
275
|
+
// local resovlers to return a new result.
|
|
276
|
+
// This is based on an implementation detail of `InMemoryCache`, which
|
|
277
|
+
// is not optimal - but the only alternative to this would be to
|
|
278
|
+
// resubscribe to the cache asynchonouly, which would bear the risk of
|
|
279
|
+
// missing further synchronous updates.
|
|
280
|
+
watch.lastDiff = undefined;
|
|
248
281
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
282
|
+
if (watch.lastOwnDiff === diff) {
|
|
283
|
+
// skip cache updates that were caused by our own writes
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const { result: previousResult } = this.subject.getValue();
|
|
287
|
+
if (!diff.complete &&
|
|
288
|
+
// If we are trying to deliver an incomplete cache result, we avoid
|
|
289
|
+
// reporting it if the query has errored, otherwise we let the broadcast try
|
|
290
|
+
// and repair the partial result by refetching the query. This check avoids
|
|
291
|
+
// a situation where a query that errors and another succeeds with
|
|
292
|
+
// overlapping data does not report the partial data result to the errored
|
|
293
|
+
// query.
|
|
294
|
+
//
|
|
295
|
+
// See https://github.com/apollographql/apollo-client/issues/11400 for more
|
|
296
|
+
// information on this issue.
|
|
297
|
+
(previousResult.error ||
|
|
298
|
+
// Prevent to schedule a notify directly after the `ObservableQuery`
|
|
299
|
+
// has been `reset` (which will set the `previousResult` to `uninitialized` or `empty`)
|
|
300
|
+
// as in those cases, `resetCache` will manually call `refetch` with more intentional timing.
|
|
301
|
+
previousResult === uninitialized ||
|
|
302
|
+
previousResult === empty)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (!(0, equality_1.equal)(previousResult.data, diff.result)) {
|
|
306
|
+
this.scheduleNotify();
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
};
|
|
310
|
+
const cancelWatch = this.queryManager.cache.watch(watch);
|
|
311
|
+
this.unsubscribeFromCache = Object.assign(() => {
|
|
312
|
+
this.unsubscribeFromCache = undefined;
|
|
313
|
+
cancelWatch();
|
|
314
|
+
}, { query, variables });
|
|
272
315
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
316
|
+
stableLastResult;
|
|
317
|
+
getCurrentResult() {
|
|
318
|
+
const { result: current } = this.subject.getValue();
|
|
319
|
+
let value = (
|
|
320
|
+
// if the `current` result is in an error state, we will always return that
|
|
321
|
+
// error state, even if we have no observers
|
|
322
|
+
(current.networkStatus === networkStatus_js_1.NetworkStatus.error ||
|
|
323
|
+
// if we have observers, we are watching the cache and
|
|
324
|
+
// this.subject.getValue() will always be up to date
|
|
325
|
+
this.hasObservers() || // if we are using a `no-cache` fetch policy in which case this
|
|
326
|
+
// `ObservableQuery` cannot have been updated from the outside - in
|
|
327
|
+
// that case, we prefer to keep the current value
|
|
328
|
+
this.options.fetchPolicy === "no-cache")) ?
|
|
329
|
+
current
|
|
330
|
+
// otherwise, the `current` value might be outdated due to missed
|
|
331
|
+
// external updates - calculate it again
|
|
332
|
+
: this.getInitialResult();
|
|
333
|
+
if (value === uninitialized) {
|
|
334
|
+
value = this.getInitialResult();
|
|
278
335
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const query = dataMasking ? documentInfo.nonReactiveQuery : this.query;
|
|
282
|
-
const resultIsDifferent = dataMasking || documentInfo.hasNonreactiveDirective ?
|
|
283
|
-
!(0, equalByQuery_js_1.equalByQuery)(query, this.last.result, newResult, this.variables)
|
|
284
|
-
: !(0, equality_1.equal)(this.last.result, newResult);
|
|
285
|
-
return (resultIsDifferent || (variables && !(0, equality_1.equal)(this.last.variables, variables)));
|
|
286
|
-
}
|
|
287
|
-
getLast(key, variablesMustMatch) {
|
|
288
|
-
const last = this.last;
|
|
289
|
-
if (last &&
|
|
290
|
-
last[key] &&
|
|
291
|
-
(!variablesMustMatch || (0, equality_1.equal)(last.variables, this.variables))) {
|
|
292
|
-
return last[key];
|
|
336
|
+
if (!(0, equality_1.equal)(this.stableLastResult, value)) {
|
|
337
|
+
this.stableLastResult = value;
|
|
293
338
|
}
|
|
294
|
-
|
|
295
|
-
// TODO: Consider deprecating this function
|
|
296
|
-
getLastResult(variablesMustMatch) {
|
|
297
|
-
return this.getLast("result", variablesMustMatch);
|
|
298
|
-
}
|
|
299
|
-
// TODO: Consider deprecating this function
|
|
300
|
-
getLastError(variablesMustMatch) {
|
|
301
|
-
return this.getLast("error", variablesMustMatch);
|
|
302
|
-
}
|
|
303
|
-
// TODO: Consider deprecating this function
|
|
304
|
-
resetLastResults() {
|
|
305
|
-
delete this.last;
|
|
306
|
-
// TODO: This will need to be removed when tearing down an ObservableQuery
|
|
307
|
-
// since the observable will terminate.
|
|
308
|
-
this.isTornDown = false;
|
|
339
|
+
return this.stableLastResult;
|
|
309
340
|
}
|
|
310
341
|
/**
|
|
311
342
|
* Update the variables of this observable query, and fetch the new results.
|
|
@@ -333,7 +364,7 @@ class ObservableQuery {
|
|
|
333
364
|
const queryDef = (0, internal_1.getQueryDefinition)(this.query);
|
|
334
365
|
const vars = queryDef.variableDefinitions;
|
|
335
366
|
if (!vars || !vars.some((v) => v.variable.name.value === "variables")) {
|
|
336
|
-
__DEV__ && invariant_1.invariant.warn(
|
|
367
|
+
__DEV__ && invariant_1.invariant.warn(77, variables, queryDef.name?.value || queryDef);
|
|
337
368
|
}
|
|
338
369
|
}
|
|
339
370
|
if (variables && !(0, equality_1.equal)(this.variables, variables)) {
|
|
@@ -380,26 +411,27 @@ class ObservableQuery {
|
|
|
380
411
|
fetchMoreOptions.query ?
|
|
381
412
|
this.transformDocument(this.options.query)
|
|
382
413
|
: combinedOptions.query;
|
|
383
|
-
|
|
384
|
-
// result.networkStatus === NetworkStatus.fetchMore.
|
|
385
|
-
const originalNetworkStatus = this.networkStatus;
|
|
386
|
-
this.networkStatus = networkStatus_js_1.NetworkStatus.fetchMore;
|
|
387
|
-
if (combinedOptions.notifyOnNetworkStatusChange) {
|
|
388
|
-
this.observe();
|
|
389
|
-
}
|
|
390
|
-
const updatedQuerySet = new Set();
|
|
414
|
+
let wasUpdated = false;
|
|
391
415
|
const updateQuery = fetchMoreOptions?.updateQuery;
|
|
392
416
|
const isCached = this.options.fetchPolicy !== "no-cache";
|
|
393
417
|
if (!isCached) {
|
|
394
|
-
(0, invariant_1.invariant)(updateQuery,
|
|
418
|
+
(0, invariant_1.invariant)(updateQuery, 78);
|
|
395
419
|
}
|
|
420
|
+
const { finalize, pushNotification } = this.pushOperation(networkStatus_js_1.NetworkStatus.fetchMore);
|
|
421
|
+
pushNotification({
|
|
422
|
+
source: "newNetworkStatus",
|
|
423
|
+
kind: "N",
|
|
424
|
+
value: {},
|
|
425
|
+
}, { shouldEmit: 3 /* EmitBehavior.networkStatusChange */ });
|
|
396
426
|
return this.queryManager
|
|
397
427
|
.fetchQuery(qid, combinedOptions, networkStatus_js_1.NetworkStatus.fetchMore)
|
|
398
428
|
.then((fetchMoreResult) => {
|
|
399
429
|
this.queryManager.removeQuery(qid);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
430
|
+
// disable the `fetchMore` override that is currently active
|
|
431
|
+
// the next updates caused by this should not be `fetchMore` anymore,
|
|
432
|
+
// but `ready` or whatever other calculated loading state is currently
|
|
433
|
+
// appropriate
|
|
434
|
+
finalize();
|
|
403
435
|
if (isCached) {
|
|
404
436
|
// Performing this cache update inside a cache.batch transaction ensures
|
|
405
437
|
// any affected cache.watch watchers are notified at most once about any
|
|
@@ -434,9 +466,9 @@ class ObservableQuery {
|
|
|
434
466
|
}
|
|
435
467
|
},
|
|
436
468
|
onWatchUpdated: (watch) => {
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
469
|
+
if (watch.watcher === this) {
|
|
470
|
+
wasUpdated = true;
|
|
471
|
+
}
|
|
440
472
|
},
|
|
441
473
|
});
|
|
442
474
|
}
|
|
@@ -455,28 +487,40 @@ class ObservableQuery {
|
|
|
455
487
|
// adjustment to the types on `updateQuery` since that function
|
|
456
488
|
// expects that the first argument always contains previous result
|
|
457
489
|
// data, but not `undefined`.
|
|
458
|
-
const lastResult = this.
|
|
490
|
+
const lastResult = this.getCurrentResult();
|
|
459
491
|
const data = updateQuery(lastResult.data, {
|
|
460
492
|
fetchMoreResult: fetchMoreResult.data,
|
|
461
493
|
variables: combinedOptions.variables,
|
|
462
494
|
});
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
495
|
+
// was reportResult
|
|
496
|
+
pushNotification({
|
|
497
|
+
kind: "N",
|
|
498
|
+
value: {
|
|
499
|
+
...lastResult,
|
|
500
|
+
networkStatus: networkStatus_js_1.NetworkStatus.ready,
|
|
501
|
+
// will be overwritten anyways, just here for types sake
|
|
502
|
+
loading: false,
|
|
503
|
+
data: data,
|
|
504
|
+
},
|
|
505
|
+
source: "network",
|
|
506
|
+
});
|
|
469
507
|
}
|
|
470
508
|
return this.maskResult(fetchMoreResult);
|
|
471
509
|
})
|
|
472
510
|
.finally(() => {
|
|
511
|
+
// call `finalize` a second time in case the `.then` case above was not reached
|
|
512
|
+
finalize();
|
|
473
513
|
// In case the cache writes above did not generate a broadcast
|
|
474
514
|
// notification (which would have been intercepted by onWatchUpdated),
|
|
475
515
|
// likely because the written data were the same as what was already in
|
|
476
516
|
// the cache, we still want fetchMore to deliver its final loading:false
|
|
477
517
|
// result with the unchanged data.
|
|
478
|
-
if (isCached && !
|
|
479
|
-
|
|
518
|
+
if (isCached && !wasUpdated) {
|
|
519
|
+
pushNotification({
|
|
520
|
+
kind: "N",
|
|
521
|
+
source: "newNetworkStatus",
|
|
522
|
+
value: {},
|
|
523
|
+
}, { shouldEmit: 1 /* EmitBehavior.force */ });
|
|
480
524
|
}
|
|
481
525
|
});
|
|
482
526
|
}
|
|
@@ -504,7 +548,7 @@ class ObservableQuery {
|
|
|
504
548
|
onError(error);
|
|
505
549
|
}
|
|
506
550
|
else {
|
|
507
|
-
__DEV__ && invariant_1.invariant.error(
|
|
551
|
+
__DEV__ && invariant_1.invariant.error(79, error);
|
|
508
552
|
}
|
|
509
553
|
return;
|
|
510
554
|
}
|
|
@@ -523,7 +567,11 @@ class ObservableQuery {
|
|
|
523
567
|
}
|
|
524
568
|
};
|
|
525
569
|
}
|
|
526
|
-
/**
|
|
570
|
+
/**
|
|
571
|
+
* @internal
|
|
572
|
+
*
|
|
573
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
574
|
+
*/
|
|
527
575
|
silentSetOptions(newOptions) {
|
|
528
576
|
const mergedOptions = (0, internal_1.compact)(this.options, newOptions || {});
|
|
529
577
|
assign(this.options, mergedOptions);
|
|
@@ -552,12 +600,12 @@ class ObservableQuery {
|
|
|
552
600
|
// If we have no observers, then we don't actually want to make a network
|
|
553
601
|
// request. As soon as someone observes the query, the request will kick
|
|
554
602
|
// off. For now, we just store any changes. (See #1077)
|
|
555
|
-
return (0, internal_1.toQueryResult)(this.
|
|
603
|
+
return (0, internal_1.toQueryResult)(this.getCurrentResult());
|
|
556
604
|
}
|
|
557
605
|
this.options.variables = variables;
|
|
558
606
|
// See comment above
|
|
559
607
|
if (!this.hasObservers()) {
|
|
560
|
-
return (0, internal_1.toQueryResult)(this.
|
|
608
|
+
return (0, internal_1.toQueryResult)(this.getCurrentResult());
|
|
561
609
|
}
|
|
562
610
|
return this.reobserve({
|
|
563
611
|
// Reset options.fetchPolicy to its original value.
|
|
@@ -573,12 +621,7 @@ class ObservableQuery {
|
|
|
573
621
|
*/
|
|
574
622
|
updateQuery(mapFn) {
|
|
575
623
|
const { queryManager } = this;
|
|
576
|
-
const { result, complete } =
|
|
577
|
-
query: this.options.query,
|
|
578
|
-
variables: this.variables,
|
|
579
|
-
returnPartialData: true,
|
|
580
|
-
optimistic: false,
|
|
581
|
-
});
|
|
624
|
+
const { result, complete } = this.getCacheDiff({ optimistic: false });
|
|
582
625
|
const newResult = mapFn(result, {
|
|
583
626
|
variables: this.variables,
|
|
584
627
|
complete: !!complete,
|
|
@@ -641,12 +684,95 @@ class ObservableQuery {
|
|
|
641
684
|
}
|
|
642
685
|
return options.fetchPolicy;
|
|
643
686
|
}
|
|
644
|
-
fetch(options,
|
|
687
|
+
fetch(options, networkStatus, fetchQuery) {
|
|
645
688
|
// TODO Make sure we update the networkStatus (and infer fetchVariables)
|
|
646
689
|
// before actually committing to the fetch.
|
|
690
|
+
const initialFetchPolicy = this.options.fetchPolicy;
|
|
647
691
|
const queryInfo = this.queryManager.getOrCreateQuery(this.queryId);
|
|
648
692
|
queryInfo.setObservableQuery(this);
|
|
649
|
-
|
|
693
|
+
options.context ??= {};
|
|
694
|
+
let synchronouslyEmitted = false;
|
|
695
|
+
const onCacheHit = () => {
|
|
696
|
+
synchronouslyEmitted = true;
|
|
697
|
+
};
|
|
698
|
+
const fetchQueryOperator = // we cannot use `tap` here, since it allows only for a "before subscription"
|
|
699
|
+
|
|
700
|
+
// hook with `subscribe` and we care for "directly before and after subscription"
|
|
701
|
+
(source) => new rxjs_1.Observable((subscriber) => {
|
|
702
|
+
try {
|
|
703
|
+
return source.subscribe({
|
|
704
|
+
next(value) {
|
|
705
|
+
synchronouslyEmitted = true;
|
|
706
|
+
subscriber.next(value);
|
|
707
|
+
},
|
|
708
|
+
error: (error) => subscriber.error(error),
|
|
709
|
+
complete: () => subscriber.complete(),
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
finally {
|
|
713
|
+
if (!synchronouslyEmitted && this.activeOperations.has(operation)) {
|
|
714
|
+
operation.override = networkStatus;
|
|
715
|
+
this.input.next({
|
|
716
|
+
kind: "N",
|
|
717
|
+
source: "newNetworkStatus",
|
|
718
|
+
value: {
|
|
719
|
+
resetError: true,
|
|
720
|
+
},
|
|
721
|
+
query,
|
|
722
|
+
variables,
|
|
723
|
+
meta: {
|
|
724
|
+
shouldEmit: 3 /* EmitBehavior.networkStatusChange */,
|
|
725
|
+
/*
|
|
726
|
+
* The moment this notification is emitted, `nextFetchPolicy`
|
|
727
|
+
* might already have switched from a `network-only` to a
|
|
728
|
+
* `cache-something` policy, so we want to ensure that the
|
|
729
|
+
* loading state emit doesn't accidentally read from the cache
|
|
730
|
+
* in those cases.
|
|
731
|
+
*/
|
|
732
|
+
fetchPolicy: initialFetchPolicy,
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
});
|
|
738
|
+
const { observable, fromLink } = this.queryManager.fetchObservableWithInfo(queryInfo, options, { networkStatus, query: fetchQuery, onCacheHit, fetchQueryOperator });
|
|
739
|
+
// track query and variables from the start of the operation
|
|
740
|
+
const { query, variables } = this;
|
|
741
|
+
const operation = {
|
|
742
|
+
abort: () => subscription.unsubscribe(),
|
|
743
|
+
query,
|
|
744
|
+
variables,
|
|
745
|
+
};
|
|
746
|
+
this.activeOperations.add(operation);
|
|
747
|
+
let forceFirstValueEmit = networkStatus == networkStatus_js_1.NetworkStatus.refetch ||
|
|
748
|
+
networkStatus == networkStatus_js_1.NetworkStatus.setVariables;
|
|
749
|
+
const subscription = observable
|
|
750
|
+
.pipe((0, rxjs_1.tap)({
|
|
751
|
+
next: (notification) => {
|
|
752
|
+
if (notification.source === "newNetworkStatus" ||
|
|
753
|
+
(notification.kind === "N" && notification.value.loading)) {
|
|
754
|
+
operation.override = networkStatus;
|
|
755
|
+
}
|
|
756
|
+
else {
|
|
757
|
+
delete operation.override;
|
|
758
|
+
}
|
|
759
|
+
},
|
|
760
|
+
finalize: () => this.activeOperations.delete(operation),
|
|
761
|
+
}))
|
|
762
|
+
.subscribe({
|
|
763
|
+
next: (value) => {
|
|
764
|
+
const meta = {};
|
|
765
|
+
if (forceFirstValueEmit &&
|
|
766
|
+
value.kind === "N" &&
|
|
767
|
+
"loading" in value.value &&
|
|
768
|
+
!value.value.loading) {
|
|
769
|
+
forceFirstValueEmit = false;
|
|
770
|
+
meta.shouldEmit = 1 /* EmitBehavior.force */;
|
|
771
|
+
}
|
|
772
|
+
this.input.next({ ...value, query, variables, meta });
|
|
773
|
+
},
|
|
774
|
+
});
|
|
775
|
+
return { fromLink, subscription, observable };
|
|
650
776
|
}
|
|
651
777
|
// Turns polling on or off based on this.options.pollInterval.
|
|
652
778
|
updatePolling() {
|
|
@@ -662,7 +788,7 @@ class ObservableQuery {
|
|
|
662
788
|
if (pollingInfo && pollingInfo.interval === pollInterval) {
|
|
663
789
|
return;
|
|
664
790
|
}
|
|
665
|
-
(0, invariant_1.invariant)(pollInterval,
|
|
791
|
+
(0, invariant_1.invariant)(pollInterval, 80);
|
|
666
792
|
const info = pollingInfo || (this.pollingInfo = {});
|
|
667
793
|
info.interval = pollInterval;
|
|
668
794
|
const maybeFetch = () => {
|
|
@@ -701,20 +827,6 @@ class ObservableQuery {
|
|
|
701
827
|
delete this.pollingInfo;
|
|
702
828
|
}
|
|
703
829
|
}
|
|
704
|
-
updateLastResult(newResult, variables = this.variables) {
|
|
705
|
-
let error = this.getLastError();
|
|
706
|
-
// Preserve this.last.error unless the variables have changed.
|
|
707
|
-
if (error && this.last && !(0, equality_1.equal)(variables, this.last.variables)) {
|
|
708
|
-
error = void 0;
|
|
709
|
-
}
|
|
710
|
-
return (this.last = {
|
|
711
|
-
result: this.queryManager.assumeImmutableResults ?
|
|
712
|
-
newResult
|
|
713
|
-
: (0, internal_1.cloneDeep)(newResult),
|
|
714
|
-
variables,
|
|
715
|
-
...(error ? { error } : null),
|
|
716
|
-
});
|
|
717
|
-
}
|
|
718
830
|
/**
|
|
719
831
|
* Reevaluate the query, optionally against new options. New options will be
|
|
720
832
|
* merged with the current options when given.
|
|
@@ -729,12 +841,9 @@ class ObservableQuery {
|
|
|
729
841
|
}
|
|
730
842
|
const useDisposableObservable =
|
|
731
843
|
// Refetching uses a disposable Observable to allow refetches using different
|
|
732
|
-
// options
|
|
844
|
+
// options, without permanently altering the options of the
|
|
733
845
|
// original ObservableQuery.
|
|
734
846
|
newNetworkStatus === networkStatus_js_1.NetworkStatus.refetch ||
|
|
735
|
-
// The fetchMore method does not actually call the reobserve method, but,
|
|
736
|
-
// if it did, it would definitely use a disposable Observable.
|
|
737
|
-
newNetworkStatus === networkStatus_js_1.NetworkStatus.fetchMore ||
|
|
738
847
|
// Polling uses a disposable Observable so the polling options (which force
|
|
739
848
|
// fetchPolicy to be "network-only" or "no-cache") won't override the original options.
|
|
740
849
|
newNetworkStatus === networkStatus_js_1.NetworkStatus.poll;
|
|
@@ -803,47 +912,27 @@ class ObservableQuery {
|
|
|
803
912
|
if (options.fetchPolicy === "standby") {
|
|
804
913
|
this.cancelPolling();
|
|
805
914
|
}
|
|
806
|
-
this.
|
|
807
|
-
this.
|
|
808
|
-
const finishWaitingForOwnResult = () => {
|
|
809
|
-
if (this.linkObservable === observable) {
|
|
810
|
-
this.waitForOwnResult = false;
|
|
811
|
-
}
|
|
812
|
-
};
|
|
813
|
-
const variables = { ...options.variables };
|
|
814
|
-
const { notifyOnNetworkStatusChange = true } = options;
|
|
815
|
-
const { observable, fromLink } = this.fetch(options, newNetworkStatus, notifyOnNetworkStatusChange &&
|
|
816
|
-
oldNetworkStatus !== newNetworkStatus &&
|
|
817
|
-
(0, networkStatus_js_1.isNetworkRequestInFlight)(newNetworkStatus), query);
|
|
818
|
-
const observer = {
|
|
819
|
-
next: (result) => {
|
|
820
|
-
if ((0, equality_1.equal)(this.variables, variables)) {
|
|
821
|
-
finishWaitingForOwnResult();
|
|
822
|
-
this.reportResult(result, variables);
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
error: (error) => {
|
|
826
|
-
if ((0, equality_1.equal)(this.variables, variables)) {
|
|
827
|
-
finishWaitingForOwnResult();
|
|
828
|
-
this.reportError(error, variables);
|
|
829
|
-
}
|
|
830
|
-
},
|
|
831
|
-
};
|
|
915
|
+
this.resubscribeCache();
|
|
916
|
+
const { subscription, observable, fromLink } = this.fetch(options, newNetworkStatus, query);
|
|
832
917
|
if (!useDisposableObservable && (fromLink || !this.linkSubscription)) {
|
|
833
918
|
if (this.linkSubscription) {
|
|
834
919
|
this.linkSubscription.unsubscribe();
|
|
835
920
|
}
|
|
836
|
-
this.
|
|
837
|
-
this.linkSubscription = observable.subscribe(observer);
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
observable.subscribe(observer);
|
|
921
|
+
this.linkSubscription = subscription;
|
|
841
922
|
}
|
|
842
923
|
return (0, internal_1.preventUnhandledRejection)(
|
|
843
924
|
// Note: lastValueFrom will create a separate subscription to the
|
|
844
925
|
// observable which means that terminating this ObservableQuery will not
|
|
845
926
|
// cancel the request from the link chain.
|
|
846
|
-
(0, rxjs_1.lastValueFrom)(observable, {
|
|
927
|
+
(0, rxjs_1.lastValueFrom)(observable.pipe((0, internal_1.filterMap)((value) => {
|
|
928
|
+
switch (value.kind) {
|
|
929
|
+
case "E":
|
|
930
|
+
throw value.error;
|
|
931
|
+
case "N":
|
|
932
|
+
if (value.source !== "newNetworkStatus")
|
|
933
|
+
return value.value;
|
|
934
|
+
}
|
|
935
|
+
})), {
|
|
847
936
|
// This default value should only be used when using a `fetchPolicy` of
|
|
848
937
|
// `standby` since that fetch policy completes without emitting a
|
|
849
938
|
// result. Since we are converting this to a QueryResult type, we
|
|
@@ -851,54 +940,16 @@ class ObservableQuery {
|
|
|
851
940
|
defaultValue: { data: undefined },
|
|
852
941
|
}).then((result) => (0, internal_1.toQueryResult)(this.maskResult(result))));
|
|
853
942
|
}
|
|
854
|
-
// (Re)deliver the current result to this.observers without applying fetch
|
|
855
|
-
// policies or making network requests.
|
|
856
|
-
observe() {
|
|
857
|
-
this.reportResult(
|
|
858
|
-
// Passing false is important so that this.getCurrentResult doesn't
|
|
859
|
-
// save the fetchMore result as this.lastResult, causing it to be
|
|
860
|
-
// ignored due to the this.isDifferentFromLastResult check in
|
|
861
|
-
// this.reportResult.
|
|
862
|
-
this.getCurrentFullResult(false), this.variables);
|
|
863
|
-
}
|
|
864
|
-
reportResult(result, variables) {
|
|
865
|
-
const lastError = this.getLastError();
|
|
866
|
-
const isDifferent = this.isDifferentFromLastResult(result, variables);
|
|
867
|
-
// Update the last result even when isDifferentFromLastResult returns false,
|
|
868
|
-
// because the query may be using the @nonreactive directive, and we want to
|
|
869
|
-
// save the the latest version of any nonreactive subtrees (in case
|
|
870
|
-
// getCurrentResult is called), even though we skip broadcasting changes.
|
|
871
|
-
this.updateLastResult(result, variables);
|
|
872
|
-
this.networkStatus = result.networkStatus;
|
|
873
|
-
if (lastError || isDifferent) {
|
|
874
|
-
this.subject.next(this.maskResult(result));
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
reportError(error, variables) {
|
|
878
|
-
// Since we don't get the current result on errors, only the error, we
|
|
879
|
-
// must mirror the updates that occur in QueryStore.markQueryError here
|
|
880
|
-
const errorResult = {
|
|
881
|
-
data: undefined,
|
|
882
|
-
partial: true,
|
|
883
|
-
...this.getLastResult(),
|
|
884
|
-
error,
|
|
885
|
-
networkStatus: networkStatus_js_1.NetworkStatus.error,
|
|
886
|
-
loading: false,
|
|
887
|
-
};
|
|
888
|
-
this.updateLastResult(errorResult, variables);
|
|
889
|
-
this.networkStatus = networkStatus_js_1.NetworkStatus.error;
|
|
890
|
-
this.last.error = error;
|
|
891
|
-
this.subject.next(errorResult);
|
|
892
|
-
}
|
|
893
943
|
hasObservers() {
|
|
894
944
|
return this.subject.observed;
|
|
895
945
|
}
|
|
896
946
|
tearDownQuery() {
|
|
897
947
|
if (this.isTornDown)
|
|
898
948
|
return;
|
|
899
|
-
|
|
949
|
+
this.resetNotifications();
|
|
950
|
+
this.unsubscribeFromCache?.();
|
|
951
|
+
if (this.linkSubscription) {
|
|
900
952
|
this.linkSubscription.unsubscribe();
|
|
901
|
-
delete this.linkObservable;
|
|
902
953
|
delete this.linkSubscription;
|
|
903
954
|
}
|
|
904
955
|
this.stopPolling();
|
|
@@ -907,6 +958,7 @@ class ObservableQuery {
|
|
|
907
958
|
this.subscriptions.clear();
|
|
908
959
|
this.queryManager.removeQuery(this.queryId);
|
|
909
960
|
this.isTornDown = true;
|
|
961
|
+
this.abortActiveOperations();
|
|
910
962
|
}
|
|
911
963
|
transformDocument(document) {
|
|
912
964
|
return this.queryManager.transform(document);
|
|
@@ -926,57 +978,231 @@ class ObservableQuery {
|
|
|
926
978
|
}
|
|
927
979
|
dirty = false;
|
|
928
980
|
notifyTimeout;
|
|
929
|
-
/**
|
|
981
|
+
/**
|
|
982
|
+
* @internal
|
|
983
|
+
*
|
|
984
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
985
|
+
*/
|
|
930
986
|
resetNotifications() {
|
|
931
|
-
this.cancelNotifyTimeout();
|
|
932
|
-
this.dirty = false;
|
|
933
|
-
}
|
|
934
|
-
cancelNotifyTimeout() {
|
|
935
987
|
if (this.notifyTimeout) {
|
|
936
988
|
clearTimeout(this.notifyTimeout);
|
|
937
989
|
this.notifyTimeout = void 0;
|
|
938
990
|
}
|
|
991
|
+
this.dirty = false;
|
|
939
992
|
}
|
|
940
|
-
/**
|
|
993
|
+
/**
|
|
994
|
+
* @internal
|
|
995
|
+
*
|
|
996
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
997
|
+
*/
|
|
941
998
|
scheduleNotify() {
|
|
942
999
|
if (this.dirty)
|
|
943
1000
|
return;
|
|
944
1001
|
this.dirty = true;
|
|
945
1002
|
if (!this.notifyTimeout) {
|
|
946
|
-
this.notifyTimeout = setTimeout(() => this.notify(), 0);
|
|
1003
|
+
this.notifyTimeout = setTimeout(() => this.notify(true), 0);
|
|
947
1004
|
}
|
|
948
1005
|
}
|
|
949
|
-
/**
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
1006
|
+
/**
|
|
1007
|
+
* @internal
|
|
1008
|
+
*
|
|
1009
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
1010
|
+
*/
|
|
1011
|
+
notify(scheduled = false) {
|
|
1012
|
+
if (!scheduled) {
|
|
1013
|
+
// For queries with client exports or forced resolvers, we don't want to
|
|
1014
|
+
// synchronously reobserve the cache on broadcast,
|
|
1015
|
+
// but actually wait for the `scheduleNotify` timeout triggered by the
|
|
1016
|
+
// `cache.watch` callback from `resubscribeCache`.
|
|
1017
|
+
const info = this.queryManager.getDocumentInfo(this.query);
|
|
1018
|
+
if (info.hasClientExports || info.hasForcedResolvers) {
|
|
1019
|
+
return;
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
const { dirty } = this;
|
|
1023
|
+
this.resetNotifications();
|
|
1024
|
+
if (dirty &&
|
|
1025
|
+
(this.options.fetchPolicy == "cache-only" ||
|
|
954
1026
|
this.options.fetchPolicy == "cache-and-network" ||
|
|
955
|
-
!
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
1027
|
+
!this.activeOperations.size)) {
|
|
1028
|
+
const diff = this.getCacheDiff();
|
|
1029
|
+
if (
|
|
1030
|
+
// `fromOptimisticTransaction` is not avaiable through the `cache.diff`
|
|
1031
|
+
// code path, so we need to check it this way
|
|
1032
|
+
(0, equality_1.equal)(diff.result, this.getCacheDiff({ optimistic: false }).result)) {
|
|
1033
|
+
//If this diff did not come from an optimistic transaction
|
|
1034
|
+
// make the ObservableQuery "reobserve" the latest data
|
|
1035
|
+
// using a temporary fetch policy of "cache-first", so complete cache
|
|
1036
|
+
// results have a chance to be delivered without triggering additional
|
|
1037
|
+
// network requests, even when options.fetchPolicy is "network-only"
|
|
1038
|
+
// or "cache-and-network". All other fetch policies are preserved by
|
|
1039
|
+
// this method, and are handled by calling oq.reobserve(). If this
|
|
1040
|
+
// reobservation is spurious, distinctUntilChanged still has a
|
|
1041
|
+
// chance to catch it before delivery to ObservableQuery subscribers.
|
|
1042
|
+
this.reobserveCacheFirst();
|
|
1043
|
+
}
|
|
1044
|
+
else {
|
|
1045
|
+
// If this diff came from an optimistic transaction, deliver the
|
|
1046
|
+
// current cache data to the ObservableQuery, but don't perform a
|
|
1047
|
+
// reobservation, since oq.reobserveCacheFirst might make a network
|
|
1048
|
+
// request, and we never want to trigger network requests in the
|
|
1049
|
+
// middle of optimistic updates.
|
|
1050
|
+
this.input.next({
|
|
1051
|
+
kind: "N",
|
|
1052
|
+
value: {
|
|
1053
|
+
data: diff.result,
|
|
1054
|
+
networkStatus: networkStatus_js_1.NetworkStatus.ready,
|
|
1055
|
+
loading: false,
|
|
1056
|
+
error: undefined,
|
|
1057
|
+
partial: !diff.complete,
|
|
1058
|
+
},
|
|
1059
|
+
source: "cache",
|
|
1060
|
+
query: this.query,
|
|
1061
|
+
variables: this.variables,
|
|
1062
|
+
meta: {},
|
|
1063
|
+
});
|
|
976
1064
|
}
|
|
977
1065
|
}
|
|
978
|
-
this.dirty = false;
|
|
979
1066
|
}
|
|
1067
|
+
activeOperations = new Set();
|
|
1068
|
+
pushOperation(networkStatus) {
|
|
1069
|
+
let aborted = false;
|
|
1070
|
+
// track query and variables from the start of the operation
|
|
1071
|
+
const { query, variables } = this;
|
|
1072
|
+
const finalize = () => {
|
|
1073
|
+
this.activeOperations.delete(operation);
|
|
1074
|
+
};
|
|
1075
|
+
const operation = {
|
|
1076
|
+
override: networkStatus,
|
|
1077
|
+
abort: () => {
|
|
1078
|
+
aborted = true;
|
|
1079
|
+
finalize();
|
|
1080
|
+
},
|
|
1081
|
+
query,
|
|
1082
|
+
variables,
|
|
1083
|
+
};
|
|
1084
|
+
this.activeOperations.add(operation);
|
|
1085
|
+
return {
|
|
1086
|
+
finalize,
|
|
1087
|
+
pushNotification: (notification, additionalMeta) => {
|
|
1088
|
+
if (!aborted) {
|
|
1089
|
+
this.input.next({
|
|
1090
|
+
...notification,
|
|
1091
|
+
query,
|
|
1092
|
+
variables,
|
|
1093
|
+
meta: { ...additionalMeta },
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
},
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
calculateNetworkStatus(baseNetworkStatus) {
|
|
1100
|
+
// in the future, this could be more complex logic, e.g. "refetch" and
|
|
1101
|
+
// "fetchMore" having priority over "polling" or "loading" network statuses
|
|
1102
|
+
// as for now we just take the "latest" operation that is still active,
|
|
1103
|
+
// as that lines up best with previous behavior[]
|
|
1104
|
+
const operation = Array.from(this.activeOperations.values()).findLast((operation) => isEqualQuery(operation, this) && operation.override !== undefined);
|
|
1105
|
+
return operation?.override ?? baseNetworkStatus;
|
|
1106
|
+
}
|
|
1107
|
+
abortActiveOperations() {
|
|
1108
|
+
this.activeOperations.forEach((operation) => operation.abort());
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* @internal
|
|
1112
|
+
* Called from `clearStore`.
|
|
1113
|
+
* * resets the query to its initial state
|
|
1114
|
+
* * cancels all active operations and their subscriptions
|
|
1115
|
+
*
|
|
1116
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
1117
|
+
*/
|
|
1118
|
+
reset() {
|
|
1119
|
+
// exception for cache-only queries - we reset them into a "ready" state
|
|
1120
|
+
// as we won't trigger a refetch for them
|
|
1121
|
+
const resetToEmpty = this.options.fetchPolicy === "cache-only";
|
|
1122
|
+
this.setResult(resetToEmpty ? empty : uninitialized, {
|
|
1123
|
+
shouldEmit: resetToEmpty ? 1 /* EmitBehavior.force */ : 2 /* EmitBehavior.never */,
|
|
1124
|
+
});
|
|
1125
|
+
this.abortActiveOperations();
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* @internal
|
|
1129
|
+
*
|
|
1130
|
+
* @deprecated This is an internal API and should not be used directly. This can be removed or changed at any time.
|
|
1131
|
+
*/
|
|
1132
|
+
setResult(result, additionalMeta) {
|
|
1133
|
+
this.input.next({
|
|
1134
|
+
source: "setResult",
|
|
1135
|
+
kind: "N",
|
|
1136
|
+
value: result,
|
|
1137
|
+
query: this.query,
|
|
1138
|
+
variables: this.variables,
|
|
1139
|
+
meta: { ...additionalMeta },
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
operator = (0, internal_1.filterMap)((notification) => {
|
|
1143
|
+
const { query, variables, meta } = notification;
|
|
1144
|
+
if (notification.source === "setResult") {
|
|
1145
|
+
return { query, variables, result: notification.value, meta };
|
|
1146
|
+
}
|
|
1147
|
+
if (notification.kind === "C" || !isEqualQuery(notification, this)) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
let result;
|
|
1151
|
+
const previous = this.subject.getValue();
|
|
1152
|
+
if (notification.source === "cache") {
|
|
1153
|
+
result = notification.value;
|
|
1154
|
+
if (result.networkStatus === networkStatus_js_1.NetworkStatus.ready &&
|
|
1155
|
+
result.partial &&
|
|
1156
|
+
(!this.options.returnPartialData ||
|
|
1157
|
+
previous.result.networkStatus === networkStatus_js_1.NetworkStatus.error) &&
|
|
1158
|
+
this.options.fetchPolicy !== "cache-only") {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
else if (notification.source === "network") {
|
|
1163
|
+
if (this.waitForNetworkResult) {
|
|
1164
|
+
this.waitForNetworkResult = false;
|
|
1165
|
+
this.resubscribeCache();
|
|
1166
|
+
}
|
|
1167
|
+
result =
|
|
1168
|
+
notification.kind === "E" ?
|
|
1169
|
+
{
|
|
1170
|
+
data: undefined,
|
|
1171
|
+
partial: true,
|
|
1172
|
+
...(isEqualQuery(previous, notification) ? previous.result : {}),
|
|
1173
|
+
error: notification.error,
|
|
1174
|
+
networkStatus: networkStatus_js_1.NetworkStatus.error,
|
|
1175
|
+
loading: false,
|
|
1176
|
+
}
|
|
1177
|
+
: notification.value;
|
|
1178
|
+
if (result.error) {
|
|
1179
|
+
meta.shouldEmit = 1 /* EmitBehavior.force */;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
else if (notification.source === "newNetworkStatus") {
|
|
1183
|
+
const baseResult = isEqualQuery(previous, notification) ?
|
|
1184
|
+
previous.result
|
|
1185
|
+
: this.getInitialResult(meta.fetchPolicy);
|
|
1186
|
+
const { resetError } = notification.value;
|
|
1187
|
+
const error = resetError ? undefined : baseResult.error;
|
|
1188
|
+
const networkStatus = error ? networkStatus_js_1.NetworkStatus.error : networkStatus_js_1.NetworkStatus.ready;
|
|
1189
|
+
result = {
|
|
1190
|
+
...baseResult,
|
|
1191
|
+
error,
|
|
1192
|
+
networkStatus,
|
|
1193
|
+
};
|
|
1194
|
+
}
|
|
1195
|
+
// every code path until here should have either returned or set a result,
|
|
1196
|
+
// but typescript needs a little help
|
|
1197
|
+
(0, invariant_1.invariant)(result);
|
|
1198
|
+
// normalize result shape
|
|
1199
|
+
if (!result.error)
|
|
1200
|
+
delete result.error;
|
|
1201
|
+
result.networkStatus = this.calculateNetworkStatus(result.networkStatus);
|
|
1202
|
+
result.loading = (0, networkStatus_js_1.isNetworkRequestInFlight)(result.networkStatus);
|
|
1203
|
+
result = this.maskResult(result);
|
|
1204
|
+
return { query, variables, result, meta };
|
|
1205
|
+
});
|
|
980
1206
|
// Reobserve with fetchPolicy effectively set to "cache-first", triggering
|
|
981
1207
|
// delivery of any new data from the cache, possibly falling back to the network
|
|
982
1208
|
// if any cache data are missing. This allows _complete_ cache results to be
|
|
@@ -1014,12 +1240,10 @@ class ObservableQuery {
|
|
|
1014
1240
|
exports.ObservableQuery = ObservableQuery;
|
|
1015
1241
|
function logMissingFieldErrors(missing) {
|
|
1016
1242
|
if (environment_1.__DEV__ && missing) {
|
|
1017
|
-
__DEV__ && invariant_1.invariant.debug(
|
|
1243
|
+
__DEV__ && invariant_1.invariant.debug(81, missing);
|
|
1018
1244
|
}
|
|
1019
1245
|
}
|
|
1020
|
-
function
|
|
1021
|
-
return (
|
|
1022
|
-
fetchPolicy === "no-cache" ||
|
|
1023
|
-
fetchPolicy === "standby");
|
|
1246
|
+
function isEqualQuery(a, b) {
|
|
1247
|
+
return !!(a && b && a.query === b.query && (0, equality_1.equal)(a.variables, b.variables));
|
|
1024
1248
|
}
|
|
1025
1249
|
//# sourceMappingURL=ObservableQuery.cjs.map
|