@apollo/client 3.8.7 → 3.8.8
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/README.md +8 -0
- package/.changeset/config.json +14 -0
- package/CHANGELOG.md +3357 -0
- package/apollo-client.cjs +314 -316
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/cache.cjs +133 -152
- package/cache/cache.cjs.map +1 -1
- package/cache/cache.cjs.native.js +133 -152
- package/cache/core/cache.d.ts +10 -0
- package/cache/core/cache.js +17 -5
- package/cache/core/cache.js.map +1 -1
- package/cache/core/types/Cache.d.ts +1 -1
- package/cache/core/types/Cache.js.map +1 -1
- package/cache/core/types/DataProxy.d.ts +92 -0
- package/cache/core/types/common.js +4 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/entityStore.d.ts +1 -1
- package/cache/inmemory/entityStore.js +190 -29
- package/cache/inmemory/entityStore.js.map +1 -1
- package/cache/inmemory/fixPolyfills.js +9 -0
- package/cache/inmemory/fixPolyfills.js.map +1 -1
- package/cache/inmemory/fixPolyfills.native.js +12 -0
- package/cache/inmemory/fixPolyfills.native.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +23 -12
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/cache/inmemory/helpers.js +20 -11
- package/cache/inmemory/helpers.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +161 -8
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/cache/inmemory/key-extractor.js +72 -4
- package/cache/inmemory/key-extractor.js.map +1 -1
- package/cache/inmemory/object-canon.js +91 -3
- package/cache/inmemory/object-canon.js.map +1 -1
- package/cache/inmemory/policies.js +193 -43
- package/cache/inmemory/policies.js.map +1 -1
- package/cache/inmemory/reactiveVars.js +20 -2
- package/cache/inmemory/reactiveVars.js.map +1 -1
- package/cache/inmemory/readFromStore.d.ts +4 -0
- package/cache/inmemory/readFromStore.js +54 -9
- package/cache/inmemory/readFromStore.js.map +1 -1
- package/cache/inmemory/types.d.ts +28 -0
- package/cache/inmemory/types.js.map +1 -1
- package/cache/inmemory/writeToStore.js +152 -25
- package/cache/inmemory/writeToStore.js.map +1 -1
- package/config/jest/setup.js +2 -0
- package/config/jest/setup.js.map +1 -1
- package/core/ApolloClient.d.ts +264 -3
- package/core/ApolloClient.js +235 -7
- package/core/ApolloClient.js.map +1 -1
- package/core/LocalState.d.ts +4 -6
- package/core/LocalState.js +56 -18
- package/core/LocalState.js.map +1 -1
- package/core/ObservableQuery.d.ts +25 -0
- package/core/ObservableQuery.js +239 -30
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryInfo.d.ts +3 -3
- package/core/QueryInfo.js +116 -13
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +4 -0
- package/core/QueryManager.js +229 -33
- package/core/QueryManager.js.map +1 -1
- package/core/core.cjs +112 -103
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +112 -103
- package/core/equalByQuery.js +20 -1
- package/core/equalByQuery.js.map +1 -1
- package/core/index.d.ts +1 -1
- package/core/index.js +19 -0
- package/core/index.js.map +1 -1
- package/core/networkStatus.d.ts +39 -0
- package/core/networkStatus.js +39 -0
- package/core/networkStatus.js.map +1 -1
- package/core/types.d.ts +9 -0
- package/core/types.js.map +1 -1
- package/core/watchQueryOptions.d.ts +225 -1
- package/core/watchQueryOptions.js.map +1 -1
- package/dev/dev.cjs +5 -111
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +5 -111
- package/dev/loadErrorMessageHandler.js.map +1 -1
- package/errors/errors.cjs +1 -1
- package/errors/errors.cjs.map +1 -1
- package/errors/errors.cjs.native.js +1 -1
- package/errors/index.js +14 -1
- package/errors/index.js.map +1 -1
- package/invariantErrorCodes.js +1 -0
- package/link/batch/batch.cjs +2 -2
- package/link/batch/batch.cjs.map +1 -1
- package/link/batch/batch.cjs.native.js +2 -2
- package/link/batch/batchLink.d.ts +21 -0
- package/link/batch/batchLink.js +2 -1
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.js +24 -1
- package/link/batch/batching.js.map +1 -1
- package/link/batch-http/batch-http.cjs +3 -2
- package/link/batch-http/batch-http.cjs.map +1 -1
- package/link/batch-http/batch-http.cjs.native.js +3 -2
- package/link/batch-http/batchHttpLink.d.ts +4 -0
- package/link/batch-http/batchHttpLink.js +53 -2
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/context/context.cjs.map +1 -1
- package/link/context/index.js +1 -0
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.js +12 -5
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/core.cjs +5 -5
- package/link/core/core.cjs.map +1 -1
- package/link/core/core.cjs.native.js +5 -5
- package/link/error/error.cjs +1 -1
- package/link/error/error.cjs.map +1 -1
- package/link/error/error.cjs.native.js +1 -1
- package/link/error/index.d.ts +3 -0
- package/link/error/index.js +4 -1
- package/link/error/index.js.map +1 -1
- package/link/http/HttpLink.d.ts +0 -2
- package/link/http/HttpLink.js +1 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/checkFetcher.js.map +1 -1
- package/link/http/createHttpLink.js +23 -1
- package/link/http/createHttpLink.js.map +1 -1
- package/link/http/createSignalIfSupported.d.ts +5 -0
- package/link/http/createSignalIfSupported.js +5 -0
- package/link/http/createSignalIfSupported.js.map +1 -1
- package/link/http/http.cjs +14 -12
- package/link/http/http.cjs.map +1 -1
- package/link/http/http.cjs.native.js +14 -12
- package/link/http/index.js +2 -1
- package/link/http/index.js.map +1 -1
- package/link/http/iterators/async.d.ts +4 -0
- package/link/http/iterators/async.js +4 -0
- package/link/http/iterators/async.js.map +1 -1
- package/link/http/iterators/nodeStream.d.ts +4 -0
- package/link/http/iterators/nodeStream.js +4 -0
- package/link/http/iterators/nodeStream.js.map +1 -1
- package/link/http/iterators/promise.d.ts +4 -0
- package/link/http/iterators/promise.js +4 -0
- package/link/http/iterators/promise.js.map +1 -1
- package/link/http/iterators/reader.d.ts +4 -0
- package/link/http/iterators/reader.js +4 -0
- package/link/http/iterators/reader.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.js +51 -10
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/responseIterator.d.ts +4 -0
- package/link/http/responseIterator.js +6 -0
- package/link/http/responseIterator.js.map +1 -1
- package/link/http/rewriteURIForGET.d.ts +1 -1
- package/link/http/rewriteURIForGET.js +10 -0
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +45 -0
- package/link/http/selectHttpOptionsAndBody.js +23 -0
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.js.map +1 -1
- package/link/http/serializeFetchParameter.js.map +1 -1
- package/link/persisted-queries/index.js +34 -4
- package/link/persisted-queries/index.js.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs +4 -4
- package/link/persisted-queries/persisted-queries.cjs.map +1 -1
- package/link/persisted-queries/persisted-queries.cjs.native.js +4 -4
- package/link/remove-typename/remove-typename.cjs +12 -9
- package/link/remove-typename/remove-typename.cjs.map +1 -1
- package/link/remove-typename/remove-typename.cjs.native.js +12 -9
- package/link/remove-typename/removeTypenameFromVariables.js +12 -9
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/delayFunction.d.ts +29 -0
- package/link/retry/delayFunction.js +6 -0
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retry.cjs +5 -5
- package/link/retry/retry.cjs.map +1 -1
- package/link/retry/retry.cjs.native.js +5 -5
- package/link/retry/retryFunction.d.ts +20 -0
- package/link/retry/retryLink.d.ts +6 -0
- package/link/retry/retryLink.js +31 -6
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +13 -0
- package/link/schema/index.js +3 -3
- package/link/schema/index.js.map +1 -1
- package/link/schema/schema.cjs +3 -3
- package/link/schema/schema.cjs.map +1 -1
- package/link/schema/schema.cjs.native.js +3 -3
- package/link/subscriptions/index.js +35 -2
- package/link/subscriptions/index.js.map +1 -1
- package/link/subscriptions/subscriptions.cjs +3 -2
- package/link/subscriptions/subscriptions.cjs.map +1 -1
- package/link/subscriptions/subscriptions.cjs.native.js +3 -2
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/filterOperationVariables.js +4 -0
- package/link/utils/filterOperationVariables.js.map +1 -1
- package/link/utils/toPromise.js.map +1 -1
- package/link/utils/transformOperation.js +3 -2
- package/link/utils/transformOperation.js.map +1 -1
- package/link/utils/utils.cjs +2 -2
- package/link/utils/utils.cjs.map +1 -1
- package/link/utils/utils.cjs.native.js +2 -2
- package/link/utils/validateOperation.js.map +1 -1
- package/link/ws/index.d.ts +12 -0
- package/link/ws/index.js +1 -1
- package/link/ws/index.js.map +1 -1
- package/link/ws/ws.cjs +1 -1
- package/link/ws/ws.cjs.map +1 -1
- package/link/ws/ws.cjs.native.js +1 -1
- package/package.json +49 -38
- package/react/cache/QueryReference.d.ts +6 -1
- package/react/cache/QueryReference.js +26 -1
- package/react/cache/QueryReference.js.map +1 -1
- package/react/cache/SuspenseCache.d.ts +10 -0
- package/react/cache/SuspenseCache.js +1 -1
- package/react/cache/SuspenseCache.js.map +1 -1
- package/react/cache/getSuspenseCache.js.map +1 -1
- package/react/context/ApolloContext.d.ts +5 -0
- package/react/context/ApolloContext.js +10 -3
- package/react/context/ApolloContext.js.map +1 -1
- package/react/context/context.cjs +1 -3
- package/react/context/context.cjs.map +1 -1
- package/react/context/context.cjs.native.js +1 -3
- package/react/hoc/graphql.js.map +1 -1
- package/react/hoc/hoc-utils.js +3 -1
- package/react/hoc/hoc-utils.js.map +1 -1
- package/react/hoc/hoc.cjs +9 -17
- package/react/hoc/hoc.cjs.map +1 -1
- package/react/hoc/hoc.cjs.native.js +9 -17
- package/react/hoc/mutation-hoc.js +9 -4
- package/react/hoc/mutation-hoc.js.map +1 -1
- package/react/hoc/query-hoc.js +10 -4
- package/react/hoc/query-hoc.js.map +1 -1
- package/react/hoc/subscription-hoc.js +10 -4
- package/react/hoc/subscription-hoc.js.map +1 -1
- package/react/hoc/withApollo.js +3 -4
- package/react/hoc/withApollo.js.map +1 -1
- package/react/hooks/hooks.cjs +30 -22
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +30 -22
- package/react/hooks/internal/__use.js +5 -0
- package/react/hooks/internal/__use.js.map +1 -1
- package/react/hooks/internal/index.js +1 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.js +6 -3
- package/react/hooks/internal/useIsomorphicLayoutEffect.js.map +1 -1
- package/react/hooks/useBackgroundQuery.js +6 -0
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +4 -3
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.js +13 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.js +8 -3
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +11 -0
- package/react/hooks/useQuery.js +137 -5
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useReactiveVar.js +5 -0
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +19 -0
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +5 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +11 -5
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +53 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/parser/index.js +4 -5
- package/react/parser/index.js.map +1 -1
- package/react/parser/parser.cjs +2 -4
- package/react/parser/parser.cjs.map +1 -1
- package/react/parser/parser.cjs.native.js +2 -4
- package/react/ssr/RenderPromises.js +21 -1
- package/react/ssr/RenderPromises.js.map +1 -1
- package/react/ssr/getDataFromTree.js +18 -3
- package/react/ssr/getDataFromTree.js.map +1 -1
- package/react/ssr/ssr.cjs +6 -4
- package/react/ssr/ssr.cjs.map +1 -1
- package/react/ssr/ssr.cjs.native.js +6 -4
- package/react/types/types.d.ts +66 -0
- package/testing/core/core.cjs +14 -11
- package/testing/core/core.cjs.map +1 -1
- package/testing/core/core.cjs.native.js +14 -11
- package/testing/core/itAsync.d.ts +1 -1
- package/testing/core/itAsync.js.map +1 -1
- package/testing/core/mocking/mockFetch.d.ts +2 -2
- package/testing/core/mocking/mockFetch.js +8 -4
- package/testing/core/mocking/mockFetch.js.map +1 -1
- package/testing/core/mocking/mockLink.js +17 -7
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockQueryManager.js +2 -0
- package/testing/core/mocking/mockQueryManager.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js +1 -1
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/testing/core/mocking/mockWatchQuery.js +1 -1
- package/testing/core/mocking/mockWatchQuery.js.map +1 -1
- package/testing/core/observableToPromise.d.ts +17 -3
- package/testing/core/observableToPromise.js +5 -0
- package/testing/core/observableToPromise.js.map +1 -1
- package/testing/core/subscribeAndCount.js +3 -0
- package/testing/core/subscribeAndCount.js.map +1 -1
- package/testing/core/wait.js +2 -2
- package/testing/core/wait.js.map +1 -1
- package/testing/core/withConsoleSpy.d.ts +3 -0
- package/testing/core/withConsoleSpy.js +7 -1
- package/testing/core/withConsoleSpy.js.map +1 -1
- package/testing/core/wrap.js +2 -0
- package/testing/core/wrap.js.map +1 -1
- package/testing/internal/ObservableStream.js +14 -14
- package/testing/internal/ObservableStream.js.map +1 -1
- package/testing/internal/disposables/spyOnConsole.d.ts +1 -0
- package/testing/internal/disposables/spyOnConsole.js +2 -0
- package/testing/internal/disposables/spyOnConsole.js.map +1 -1
- package/testing/internal/disposables/withCleanup.d.ts +1 -0
- package/testing/internal/disposables/withCleanup.js +3 -0
- package/testing/internal/disposables/withCleanup.js.map +1 -1
- package/testing/internal/profile/Render.d.ts +28 -0
- package/testing/internal/profile/Render.js +12 -1
- package/testing/internal/profile/Render.js.map +1 -1
- package/testing/internal/profile/profile.d.ts +44 -7
- package/testing/internal/profile/profile.js +63 -51
- package/testing/internal/profile/profile.js.map +1 -1
- package/testing/internal/profile/traces.d.ts +4 -0
- package/testing/internal/profile/traces.js +9 -5
- package/testing/internal/profile/traces.js.map +1 -1
- package/testing/matchers/ProfiledComponent.js +27 -22
- package/testing/matchers/ProfiledComponent.js.map +1 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.js.map +1 -1
- package/testing/matchers/toMatchDocument.js.map +1 -1
- package/testing/react/MockedProvider.d.ts +4 -0
- package/testing/react/MockedProvider.js +6 -2
- package/testing/react/MockedProvider.js.map +1 -1
- package/testing/testing.cjs +4 -2
- package/testing/testing.cjs.map +1 -1
- package/testing/testing.cjs.native.js +4 -2
- package/utilities/common/arrays.js +1 -0
- package/utilities/common/arrays.js.map +1 -1
- package/utilities/common/canUse.js +16 -1
- package/utilities/common/canUse.js.map +1 -1
- package/utilities/common/cloneDeep.d.ts +3 -0
- package/utilities/common/cloneDeep.js +5 -0
- package/utilities/common/cloneDeep.js.map +1 -1
- package/utilities/common/compact.d.ts +4 -0
- package/utilities/common/compact.js +4 -0
- package/utilities/common/compact.js.map +1 -1
- package/utilities/common/errorHandling.js +1 -3
- package/utilities/common/errorHandling.js.map +1 -1
- package/utilities/common/incrementalResult.js +3 -0
- package/utilities/common/incrementalResult.js.map +1 -1
- package/utilities/common/makeUniqueId.js +2 -0
- package/utilities/common/makeUniqueId.js.map +1 -1
- package/utilities/common/maybeDeepFreeze.js +3 -0
- package/utilities/common/maybeDeepFreeze.js.map +1 -1
- package/utilities/common/mergeDeep.js +12 -1
- package/utilities/common/mergeDeep.js.map +1 -1
- package/utilities/common/mergeOptions.d.ts +1 -1
- package/utilities/common/mergeOptions.js.map +1 -1
- package/utilities/common/omitDeep.js.map +1 -1
- package/utilities/globals/global.js +7 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +4 -5
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +4 -5
- package/utilities/globals/index.d.ts +4 -0
- package/utilities/globals/index.js +7 -0
- package/utilities/globals/index.js.map +1 -1
- package/utilities/globals/invariantWrappers.d.ts +40 -0
- package/utilities/globals/invariantWrappers.js +11 -3
- package/utilities/globals/invariantWrappers.js.map +1 -1
- package/utilities/globals/maybe.js.map +1 -1
- package/utilities/graphql/DocumentTransform.js +19 -6
- package/utilities/graphql/DocumentTransform.js.map +1 -1
- package/utilities/graphql/directives.js +3 -0
- package/utilities/graphql/directives.js.map +1 -1
- package/utilities/graphql/fragments.d.ts +25 -0
- package/utilities/graphql/fragments.js +36 -0
- package/utilities/graphql/fragments.js.map +1 -1
- package/utilities/graphql/getFromAST.d.ts +5 -0
- package/utilities/graphql/getFromAST.js +9 -0
- package/utilities/graphql/getFromAST.js.map +1 -1
- package/utilities/graphql/print.js.map +1 -1
- package/utilities/graphql/storeUtils.d.ts +14 -0
- package/utilities/graphql/storeUtils.js +7 -2
- package/utilities/graphql/storeUtils.js.map +1 -1
- package/utilities/graphql/transform.js +106 -7
- package/utilities/graphql/transform.js.map +1 -1
- package/utilities/observables/Concast.d.ts +1 -1
- package/utilities/observables/Concast.js +84 -1
- package/utilities/observables/Concast.js.map +1 -1
- package/utilities/observables/Observable.js +6 -0
- package/utilities/observables/Observable.js.map +1 -1
- package/utilities/observables/asyncMap.js +12 -3
- package/utilities/observables/asyncMap.js.map +1 -1
- package/utilities/observables/iteration.js +3 -0
- package/utilities/observables/iteration.js.map +1 -1
- package/utilities/observables/subclassing.js +14 -0
- package/utilities/observables/subclassing.js.map +1 -1
- package/utilities/policies/pagination.js +47 -3
- package/utilities/policies/pagination.js.map +1 -1
- package/utilities/promises/decoration.js +1 -0
- package/utilities/promises/decoration.js.map +1 -1
- package/utilities/types/DeepOmit.js.map +1 -1
- package/utilities/types/DeepPartial.d.ts +1 -1
- package/utilities/types/DeepPartial.js +4 -0
- package/utilities/types/DeepPartial.js.map +1 -1
- package/utilities/types/IsStrictlyAny.js.map +1 -1
- package/utilities/types/TODO.d.ts +3 -0
- package/utilities/types/TODO.js +2 -0
- package/utilities/types/TODO.js.map +1 -0
- package/utilities/utilities.cjs +31 -27
- package/utilities/utilities.cjs.map +1 -1
- package/utilities/utilities.cjs.native.js +31 -27
- package/version.js +1 -1
- package/cache/core/cache.d.ts.map +0 -1
- package/cache/core/types/Cache.d.ts.map +0 -1
- package/cache/core/types/DataProxy.d.ts.map +0 -1
- package/cache/core/types/common.d.ts.map +0 -1
- package/cache/index.d.ts.map +0 -1
- package/cache/inmemory/entityStore.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.d.ts.map +0 -1
- package/cache/inmemory/fixPolyfills.native.d.ts.map +0 -1
- package/cache/inmemory/fragmentRegistry.d.ts.map +0 -1
- package/cache/inmemory/helpers.d.ts.map +0 -1
- package/cache/inmemory/inMemoryCache.d.ts.map +0 -1
- package/cache/inmemory/key-extractor.d.ts.map +0 -1
- package/cache/inmemory/object-canon.d.ts.map +0 -1
- package/cache/inmemory/policies.d.ts.map +0 -1
- package/cache/inmemory/reactiveVars.d.ts.map +0 -1
- package/cache/inmemory/readFromStore.d.ts.map +0 -1
- package/cache/inmemory/types.d.ts.map +0 -1
- package/cache/inmemory/writeToStore.d.ts.map +0 -1
- package/config/jest/setup.d.ts.map +0 -1
- package/core/ApolloClient.d.ts.map +0 -1
- package/core/LocalState.d.ts.map +0 -1
- package/core/ObservableQuery.d.ts.map +0 -1
- package/core/QueryInfo.d.ts.map +0 -1
- package/core/QueryManager.d.ts.map +0 -1
- package/core/equalByQuery.d.ts.map +0 -1
- package/core/index.d.ts.map +0 -1
- package/core/networkStatus.d.ts.map +0 -1
- package/core/types.d.ts.map +0 -1
- package/core/watchQueryOptions.d.ts.map +0 -1
- package/dev/index.d.ts.map +0 -1
- package/dev/loadDevMessages.d.ts.map +0 -1
- package/dev/loadErrorMessageHandler.d.ts.map +0 -1
- package/dev/loadErrorMessages.d.ts.map +0 -1
- package/errors/index.d.ts.map +0 -1
- package/index.d.ts.map +0 -1
- package/invariantErrorCodes.d.ts.map +0 -1
- package/link/batch/batchLink.d.ts.map +0 -1
- package/link/batch/batching.d.ts.map +0 -1
- package/link/batch/index.d.ts.map +0 -1
- package/link/batch-http/batchHttpLink.d.ts.map +0 -1
- package/link/batch-http/index.d.ts.map +0 -1
- package/link/context/index.d.ts.map +0 -1
- package/link/core/ApolloLink.d.ts.map +0 -1
- package/link/core/concat.d.ts.map +0 -1
- package/link/core/empty.d.ts.map +0 -1
- package/link/core/execute.d.ts.map +0 -1
- package/link/core/from.d.ts.map +0 -1
- package/link/core/index.d.ts.map +0 -1
- package/link/core/split.d.ts.map +0 -1
- package/link/core/types.d.ts.map +0 -1
- package/link/error/index.d.ts.map +0 -1
- package/link/http/HttpLink.d.ts.map +0 -1
- package/link/http/checkFetcher.d.ts.map +0 -1
- package/link/http/createHttpLink.d.ts.map +0 -1
- package/link/http/createSignalIfSupported.d.ts.map +0 -1
- package/link/http/index.d.ts.map +0 -1
- package/link/http/iterators/async.d.ts.map +0 -1
- package/link/http/iterators/nodeStream.d.ts.map +0 -1
- package/link/http/iterators/promise.d.ts.map +0 -1
- package/link/http/iterators/reader.d.ts.map +0 -1
- package/link/http/parseAndCheckHttpResponse.d.ts.map +0 -1
- package/link/http/responseIterator.d.ts.map +0 -1
- package/link/http/rewriteURIForGET.d.ts.map +0 -1
- package/link/http/selectHttpOptionsAndBody.d.ts.map +0 -1
- package/link/http/selectURI.d.ts.map +0 -1
- package/link/http/serializeFetchParameter.d.ts.map +0 -1
- package/link/persisted-queries/index.d.ts.map +0 -1
- package/link/remove-typename/index.d.ts.map +0 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts.map +0 -1
- package/link/retry/delayFunction.d.ts.map +0 -1
- package/link/retry/index.d.ts.map +0 -1
- package/link/retry/retryFunction.d.ts.map +0 -1
- package/link/retry/retryLink.d.ts.map +0 -1
- package/link/schema/index.d.ts.map +0 -1
- package/link/subscriptions/index.d.ts.map +0 -1
- package/link/utils/createOperation.d.ts.map +0 -1
- package/link/utils/filterOperationVariables.d.ts.map +0 -1
- package/link/utils/fromError.d.ts.map +0 -1
- package/link/utils/fromPromise.d.ts.map +0 -1
- package/link/utils/index.d.ts.map +0 -1
- package/link/utils/throwServerError.d.ts.map +0 -1
- package/link/utils/toPromise.d.ts.map +0 -1
- package/link/utils/transformOperation.d.ts.map +0 -1
- package/link/utils/validateOperation.d.ts.map +0 -1
- package/link/ws/index.d.ts.map +0 -1
- package/react/cache/QueryReference.d.ts.map +0 -1
- package/react/cache/SuspenseCache.d.ts.map +0 -1
- package/react/cache/getSuspenseCache.d.ts.map +0 -1
- package/react/cache/index.d.ts.map +0 -1
- package/react/cache/types.d.ts.map +0 -1
- package/react/components/Mutation.d.ts.map +0 -1
- package/react/components/Query.d.ts.map +0 -1
- package/react/components/Subscription.d.ts.map +0 -1
- package/react/components/index.d.ts.map +0 -1
- package/react/components/types.d.ts.map +0 -1
- package/react/context/ApolloConsumer.d.ts.map +0 -1
- package/react/context/ApolloContext.d.ts.map +0 -1
- package/react/context/ApolloProvider.d.ts.map +0 -1
- package/react/context/index.d.ts.map +0 -1
- package/react/hoc/graphql.d.ts.map +0 -1
- package/react/hoc/hoc-utils.d.ts.map +0 -1
- package/react/hoc/index.d.ts.map +0 -1
- package/react/hoc/mutation-hoc.d.ts.map +0 -1
- package/react/hoc/query-hoc.d.ts.map +0 -1
- package/react/hoc/subscription-hoc.d.ts.map +0 -1
- package/react/hoc/types.d.ts.map +0 -1
- package/react/hoc/withApollo.d.ts.map +0 -1
- package/react/hooks/constants.d.ts.map +0 -1
- package/react/hooks/index.d.ts.map +0 -1
- package/react/hooks/internal/__use.d.ts.map +0 -1
- package/react/hooks/internal/index.d.ts.map +0 -1
- package/react/hooks/internal/useDeepMemo.d.ts.map +0 -1
- package/react/hooks/internal/useIsomorphicLayoutEffect.d.ts.map +0 -1
- package/react/hooks/useApolloClient.d.ts.map +0 -1
- package/react/hooks/useBackgroundQuery.d.ts.map +0 -1
- package/react/hooks/useFragment.d.ts.map +0 -1
- package/react/hooks/useLazyQuery.d.ts.map +0 -1
- package/react/hooks/useMutation.d.ts.map +0 -1
- package/react/hooks/useQuery.d.ts.map +0 -1
- package/react/hooks/useReactiveVar.d.ts.map +0 -1
- package/react/hooks/useReadQuery.d.ts.map +0 -1
- package/react/hooks/useSubscription.d.ts.map +0 -1
- package/react/hooks/useSuspenseQuery.d.ts.map +0 -1
- package/react/hooks/useSyncExternalStore.d.ts.map +0 -1
- package/react/index.d.ts.map +0 -1
- package/react/parser/index.d.ts.map +0 -1
- package/react/ssr/RenderPromises.d.ts.map +0 -1
- package/react/ssr/getDataFromTree.d.ts.map +0 -1
- package/react/ssr/index.d.ts.map +0 -1
- package/react/ssr/renderToStringWithData.d.ts.map +0 -1
- package/react/types/types.d.ts.map +0 -1
- package/testing/core/index.d.ts.map +0 -1
- package/testing/core/itAsync.d.ts.map +0 -1
- package/testing/core/mocking/mockClient.d.ts.map +0 -1
- package/testing/core/mocking/mockFetch.d.ts.map +0 -1
- package/testing/core/mocking/mockLink.d.ts.map +0 -1
- package/testing/core/mocking/mockQueryManager.d.ts.map +0 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts.map +0 -1
- package/testing/core/mocking/mockWatchQuery.d.ts.map +0 -1
- package/testing/core/observableToPromise.d.ts.map +0 -1
- package/testing/core/subscribeAndCount.d.ts.map +0 -1
- package/testing/core/wait.d.ts.map +0 -1
- package/testing/core/withConsoleSpy.d.ts.map +0 -1
- package/testing/core/wrap.d.ts.map +0 -1
- package/testing/index.d.ts.map +0 -1
- package/testing/internal/ObservableStream.d.ts.map +0 -1
- package/testing/internal/disposables/index.d.ts.map +0 -1
- package/testing/internal/disposables/spyOnConsole.d.ts.map +0 -1
- package/testing/internal/disposables/withCleanup.d.ts.map +0 -1
- package/testing/internal/index.d.ts.map +0 -1
- package/testing/internal/profile/Render.d.ts.map +0 -1
- package/testing/internal/profile/index.d.ts.map +0 -1
- package/testing/internal/profile/profile.d.ts.map +0 -1
- package/testing/internal/profile/traces.d.ts.map +0 -1
- package/testing/matchers/ProfiledComponent.d.ts.map +0 -1
- package/testing/matchers/index.d.ts.map +0 -1
- package/testing/matchers/toHaveSuspenseCacheEntryUsing.d.ts.map +0 -1
- package/testing/matchers/toMatchDocument.d.ts.map +0 -1
- package/testing/react/MockedProvider.d.ts.map +0 -1
- package/utilities/common/arrays.d.ts.map +0 -1
- package/utilities/common/canUse.d.ts.map +0 -1
- package/utilities/common/cloneDeep.d.ts.map +0 -1
- package/utilities/common/compact.d.ts.map +0 -1
- package/utilities/common/errorHandling.d.ts.map +0 -1
- package/utilities/common/filterInPlace.d.ts +0 -2
- package/utilities/common/filterInPlace.d.ts.map +0 -1
- package/utilities/common/filterInPlace.js +0 -11
- package/utilities/common/filterInPlace.js.map +0 -1
- package/utilities/common/incrementalResult.d.ts.map +0 -1
- package/utilities/common/makeUniqueId.d.ts.map +0 -1
- package/utilities/common/maybeDeepFreeze.d.ts.map +0 -1
- package/utilities/common/mergeDeep.d.ts.map +0 -1
- package/utilities/common/mergeOptions.d.ts.map +0 -1
- package/utilities/common/objects.d.ts.map +0 -1
- package/utilities/common/omitDeep.d.ts.map +0 -1
- package/utilities/common/stringifyForDisplay.d.ts.map +0 -1
- package/utilities/common/stripTypename.d.ts.map +0 -1
- package/utilities/globals/global.d.ts.map +0 -1
- package/utilities/globals/index.d.ts.map +0 -1
- package/utilities/globals/invariantWrappers.d.ts.map +0 -1
- package/utilities/globals/maybe.d.ts.map +0 -1
- package/utilities/graphql/DocumentTransform.d.ts.map +0 -1
- package/utilities/graphql/directives.d.ts.map +0 -1
- package/utilities/graphql/fragments.d.ts.map +0 -1
- package/utilities/graphql/getFromAST.d.ts.map +0 -1
- package/utilities/graphql/operations.d.ts.map +0 -1
- package/utilities/graphql/print.d.ts.map +0 -1
- package/utilities/graphql/storeUtils.d.ts.map +0 -1
- package/utilities/graphql/transform.d.ts.map +0 -1
- package/utilities/index.d.ts.map +0 -1
- package/utilities/observables/Concast.d.ts.map +0 -1
- package/utilities/observables/Observable.d.ts.map +0 -1
- package/utilities/observables/asyncMap.d.ts.map +0 -1
- package/utilities/observables/iteration.d.ts.map +0 -1
- package/utilities/observables/subclassing.d.ts.map +0 -1
- package/utilities/policies/pagination.d.ts.map +0 -1
- package/utilities/promises/decoration.d.ts.map +0 -1
- package/utilities/types/DeepOmit.d.ts.map +0 -1
- package/utilities/types/DeepPartial.d.ts.map +0 -1
- package/utilities/types/IsStrictlyAny.d.ts.map +0 -1
- package/utilities/types/Primitive.d.ts.map +0 -1
- package/version.d.ts.map +0 -1
package/react/hooks/useQuery.js
CHANGED
|
@@ -23,14 +23,24 @@ export function useInternalState(client, query) {
|
|
|
23
23
|
stateRef.current = new InternalState(client, query, stateRef.current);
|
|
24
24
|
}
|
|
25
25
|
var state = stateRef.current;
|
|
26
|
+
// By default, InternalState.prototype.forceUpdate is an empty function, but
|
|
27
|
+
// we replace it here (before anyone has had a chance to see this state yet)
|
|
28
|
+
// with a function that unconditionally forces an update, using the latest
|
|
29
|
+
// setTick function. Updating this state by calling state.forceUpdate is the
|
|
30
|
+
// only way we trigger React component updates (no other useState calls within
|
|
31
|
+
// the InternalState class).
|
|
26
32
|
state.forceUpdateState = React.useReducer(function (tick) { return tick + 1; }, 0)[1];
|
|
27
33
|
return state;
|
|
28
34
|
}
|
|
29
|
-
var InternalState = (function () {
|
|
35
|
+
var InternalState = /** @class */ (function () {
|
|
30
36
|
function InternalState(client, query, previous) {
|
|
31
37
|
var _this = this;
|
|
32
38
|
this.client = client;
|
|
33
39
|
this.query = query;
|
|
40
|
+
/**
|
|
41
|
+
* Will be overwritten by the `useSyncExternalStore` "force update" method
|
|
42
|
+
* whenever it is available and reset to `forceUpdateState` when it isn't.
|
|
43
|
+
*/
|
|
34
44
|
this.forceUpdate = function () { return _this.forceUpdateState(); };
|
|
35
45
|
this.ssrDisabledResult = maybeDeepFreeze({
|
|
36
46
|
loading: true,
|
|
@@ -44,15 +54,28 @@ var InternalState = (function () {
|
|
|
44
54
|
error: void 0,
|
|
45
55
|
networkStatus: NetworkStatus.ready,
|
|
46
56
|
});
|
|
57
|
+
// This cache allows the referential stability of this.result (as returned by
|
|
58
|
+
// getCurrentResult) to translate into referential stability of the resulting
|
|
59
|
+
// QueryResult object returned by toQueryResult.
|
|
47
60
|
this.toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)();
|
|
48
61
|
verifyDocumentType(query, DocumentType.Query);
|
|
62
|
+
// Reuse previousData from previous InternalState (if any) to provide
|
|
63
|
+
// continuity of previousData even if/when the query or client changes.
|
|
49
64
|
var previousResult = previous && previous.result;
|
|
50
65
|
var previousData = previousResult && previousResult.data;
|
|
51
66
|
if (previousData) {
|
|
52
67
|
this.previousData = previousData;
|
|
53
68
|
}
|
|
54
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Forces an update using local component state.
|
|
72
|
+
* As this is not batched with `useSyncExternalStore` updates,
|
|
73
|
+
* this is only used as a fallback if the `useSyncExternalStore` "force update"
|
|
74
|
+
* method is not registered at the moment.
|
|
75
|
+
* See https://github.com/facebook/react/issues/25191
|
|
76
|
+
* */
|
|
55
77
|
InternalState.prototype.forceUpdateState = function () {
|
|
78
|
+
// Replaced (in useInternalState) with a method that triggers an update.
|
|
56
79
|
globalThis.__DEV__ !== false && invariant.warn(50);
|
|
57
80
|
};
|
|
58
81
|
InternalState.prototype.executeQuery = function (options) {
|
|
@@ -63,11 +86,18 @@ var InternalState = (function () {
|
|
|
63
86
|
}
|
|
64
87
|
this.watchQueryOptions = this.createWatchQueryOptions((this.queryHookOptions = options));
|
|
65
88
|
var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
|
|
89
|
+
// Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,
|
|
90
|
+
// but save the current data as this.previousData, just like setResult
|
|
91
|
+
// usually does.
|
|
66
92
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
67
93
|
this.result = void 0;
|
|
68
94
|
this.forceUpdate();
|
|
69
95
|
return new Promise(function (resolve) {
|
|
70
96
|
var result;
|
|
97
|
+
// Subscribe to the concast independently of the ObservableQuery in case
|
|
98
|
+
// the component gets unmounted before the promise resolves. This prevents
|
|
99
|
+
// the concast from terminating early and resolving with `undefined` when
|
|
100
|
+
// there are no more subscribers for the concast.
|
|
71
101
|
concast.subscribe({
|
|
72
102
|
next: function (value) {
|
|
73
103
|
result = value;
|
|
@@ -81,8 +111,18 @@ var InternalState = (function () {
|
|
|
81
111
|
});
|
|
82
112
|
});
|
|
83
113
|
};
|
|
114
|
+
// Methods beginning with use- should be called according to the standard
|
|
115
|
+
// rules of React hooks: only at the top level of the calling function, and
|
|
116
|
+
// without any dynamic conditional logic.
|
|
84
117
|
InternalState.prototype.useQuery = function (options) {
|
|
85
118
|
var _this = this;
|
|
119
|
+
// The renderPromises field gets initialized here in the useQuery method, at
|
|
120
|
+
// the beginning of everything (for a given component rendering, at least),
|
|
121
|
+
// so we can safely use this.renderPromises in other/later InternalState
|
|
122
|
+
// methods without worrying it might be uninitialized. Even after
|
|
123
|
+
// initialization, this.renderPromises is usually undefined (unless SSR is
|
|
124
|
+
// happening), but that's fine as long as it has been initialized that way,
|
|
125
|
+
// rather than left uninitialized.
|
|
86
126
|
this.renderPromises = React.useContext(getApolloContext()).renderPromises;
|
|
87
127
|
this.useOptions(options);
|
|
88
128
|
var obsQuery = this.useObservableQuery();
|
|
@@ -93,7 +133,11 @@ var InternalState = (function () {
|
|
|
93
133
|
_this.forceUpdate = handleStoreChange;
|
|
94
134
|
var onNext = function () {
|
|
95
135
|
var previousResult = _this.result;
|
|
136
|
+
// We use `getCurrentResult()` instead of the onNext argument because
|
|
137
|
+
// the values differ slightly. Specifically, loading results will have
|
|
138
|
+
// an empty object for data instead of `undefined` for some reason.
|
|
96
139
|
var result = obsQuery.getCurrentResult();
|
|
140
|
+
// Make sure we're not attempting to re-render similar results
|
|
97
141
|
if (previousResult &&
|
|
98
142
|
previousResult.loading === result.loading &&
|
|
99
143
|
previousResult.networkStatus === result.networkStatus &&
|
|
@@ -106,6 +150,7 @@ var InternalState = (function () {
|
|
|
106
150
|
subscription.unsubscribe();
|
|
107
151
|
subscription = obsQuery.resubscribeAfterError(onNext, onError);
|
|
108
152
|
if (!hasOwnProperty.call(error, "graphQLErrors")) {
|
|
153
|
+
// The error is not a GraphQL error
|
|
109
154
|
throw error;
|
|
110
155
|
}
|
|
111
156
|
var previousResult = _this.result;
|
|
@@ -121,40 +166,83 @@ var InternalState = (function () {
|
|
|
121
166
|
}
|
|
122
167
|
};
|
|
123
168
|
var subscription = obsQuery.subscribe(onNext, onError);
|
|
169
|
+
// Do the "unsubscribe" with a short delay.
|
|
170
|
+
// This way, an existing subscription can be reused without an additional
|
|
171
|
+
// request if "unsubscribe" and "resubscribe" to the same ObservableQuery
|
|
172
|
+
// happen in very fast succession.
|
|
124
173
|
return function () {
|
|
125
174
|
setTimeout(function () { return subscription.unsubscribe(); });
|
|
126
175
|
_this.forceUpdate = function () { return _this.forceUpdateState(); };
|
|
127
176
|
};
|
|
128
177
|
}, [
|
|
178
|
+
// We memoize the subscribe function using useCallback and the following
|
|
179
|
+
// dependency keys, because the subscribe function reference is all that
|
|
180
|
+
// useSyncExternalStore uses internally as a dependency key for the
|
|
181
|
+
// useEffect ultimately responsible for the subscription, so we are
|
|
182
|
+
// effectively passing this dependency array to that useEffect buried
|
|
183
|
+
// inside useSyncExternalStore, as desired.
|
|
129
184
|
obsQuery,
|
|
130
185
|
this.renderPromises,
|
|
131
186
|
this.client.disableNetworkFetches,
|
|
132
187
|
]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
|
|
188
|
+
// TODO Remove this method when we remove support for options.partialRefetch.
|
|
133
189
|
this.unsafeHandlePartialRefetch(result);
|
|
134
190
|
return this.toQueryResult(result);
|
|
135
191
|
};
|
|
136
192
|
InternalState.prototype.useOptions = function (options) {
|
|
137
193
|
var _a;
|
|
138
194
|
var watchQueryOptions = this.createWatchQueryOptions((this.queryHookOptions = options));
|
|
195
|
+
// Update this.watchQueryOptions, but only when they have changed, which
|
|
196
|
+
// allows us to depend on the referential stability of
|
|
197
|
+
// this.watchQueryOptions elsewhere.
|
|
139
198
|
var currentWatchQueryOptions = this.watchQueryOptions;
|
|
140
199
|
if (!equal(watchQueryOptions, currentWatchQueryOptions)) {
|
|
141
200
|
this.watchQueryOptions = watchQueryOptions;
|
|
142
201
|
if (currentWatchQueryOptions && this.observable) {
|
|
202
|
+
// Though it might be tempting to postpone this reobserve call to the
|
|
203
|
+
// useEffect block, we need getCurrentResult to return an appropriate
|
|
204
|
+
// loading:true result synchronously (later within the same call to
|
|
205
|
+
// useQuery). Since we already have this.observable here (not true for
|
|
206
|
+
// the very first call to useQuery), we are not initiating any new
|
|
207
|
+
// subscriptions, though it does feel less than ideal that reobserve
|
|
208
|
+
// (potentially) kicks off a network request (for example, when the
|
|
209
|
+
// variables have changed), which is technically a side-effect.
|
|
143
210
|
this.observable.reobserve(this.getObsQueryOptions());
|
|
211
|
+
// Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,
|
|
212
|
+
// but save the current data as this.previousData, just like setResult
|
|
213
|
+
// usually does.
|
|
144
214
|
this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
|
|
145
215
|
this.result = void 0;
|
|
146
216
|
}
|
|
147
217
|
}
|
|
218
|
+
// Make sure state.onCompleted and state.onError always reflect the latest
|
|
219
|
+
// options.onCompleted and options.onError callbacks provided to useQuery,
|
|
220
|
+
// since those functions are often recreated every time useQuery is called.
|
|
221
|
+
// Like the forceUpdate method, the versions of these methods inherited from
|
|
222
|
+
// InternalState.prototype are empty no-ops, but we can override them on the
|
|
223
|
+
// base state object (without modifying the prototype).
|
|
148
224
|
this.onCompleted =
|
|
149
225
|
options.onCompleted || InternalState.prototype.onCompleted;
|
|
150
226
|
this.onError = options.onError || InternalState.prototype.onError;
|
|
151
227
|
if ((this.renderPromises || this.client.disableNetworkFetches) &&
|
|
152
228
|
this.queryHookOptions.ssr === false &&
|
|
153
229
|
!this.queryHookOptions.skip) {
|
|
230
|
+
// If SSR has been explicitly disabled, and this function has been called
|
|
231
|
+
// on the server side, return the default loading state.
|
|
154
232
|
this.result = this.ssrDisabledResult;
|
|
155
233
|
}
|
|
156
234
|
else if (this.queryHookOptions.skip ||
|
|
157
235
|
this.watchQueryOptions.fetchPolicy === "standby") {
|
|
236
|
+
// When skipping a query (ie. we're not querying for data but still want to
|
|
237
|
+
// render children), make sure the `data` is cleared out and `loading` is
|
|
238
|
+
// set to `false` (since we aren't loading anything).
|
|
239
|
+
//
|
|
240
|
+
// NOTE: We no longer think this is the correct behavior. Skipping should
|
|
241
|
+
// not automatically set `data` to `undefined`, but instead leave the
|
|
242
|
+
// previous data in place. In other words, skipping should not mandate that
|
|
243
|
+
// previously received data is all of a sudden removed. Unfortunately,
|
|
244
|
+
// changing this is breaking, so we'll have to wait until Apollo Client 4.0
|
|
245
|
+
// to address this.
|
|
158
246
|
this.result = this.skipStandbyResult;
|
|
159
247
|
}
|
|
160
248
|
else if (this.result === this.ssrDisabledResult ||
|
|
@@ -170,17 +258,36 @@ var InternalState = (function () {
|
|
|
170
258
|
if (this.queryHookOptions.defaultOptions) {
|
|
171
259
|
toMerge.push(this.queryHookOptions.defaultOptions);
|
|
172
260
|
}
|
|
261
|
+
// We use compact rather than mergeOptions for this part of the merge,
|
|
262
|
+
// because we want watchQueryOptions.variables (if defined) to replace
|
|
263
|
+
// this.observable.options.variables whole. This replacement allows
|
|
264
|
+
// removing variables by removing them from the variables input to
|
|
265
|
+
// useQuery. If the variables were always merged together (rather than
|
|
266
|
+
// replaced), there would be no way to remove existing variables.
|
|
267
|
+
// However, the variables from options.defaultOptions and globalDefaults
|
|
268
|
+
// (if provided) should be merged, to ensure individual defaulted
|
|
269
|
+
// variables always have values, if not otherwise defined in
|
|
270
|
+
// observable.options or watchQueryOptions.
|
|
173
271
|
toMerge.push(compact(this.observable && this.observable.options, this.watchQueryOptions));
|
|
174
272
|
return toMerge.reduce(mergeOptions);
|
|
175
273
|
};
|
|
274
|
+
// A function to massage options before passing them to ObservableQuery.
|
|
176
275
|
InternalState.prototype.createWatchQueryOptions = function (_a) {
|
|
177
276
|
var _b;
|
|
178
277
|
if (_a === void 0) { _a = {}; }
|
|
179
|
-
var skip = _a.skip, ssr = _a.ssr, onCompleted = _a.onCompleted, onError = _a.onError, defaultOptions = _a.defaultOptions,
|
|
278
|
+
var skip = _a.skip, ssr = _a.ssr, onCompleted = _a.onCompleted, onError = _a.onError, defaultOptions = _a.defaultOptions,
|
|
279
|
+
// The above options are useQuery-specific, so this ...otherOptions spread
|
|
280
|
+
// makes otherOptions almost a WatchQueryOptions object, except for the
|
|
281
|
+
// query property that we add below.
|
|
282
|
+
otherOptions = __rest(_a, ["skip", "ssr", "onCompleted", "onError", "defaultOptions"]);
|
|
283
|
+
// This Object.assign is safe because otherOptions is a fresh ...rest object
|
|
284
|
+
// that did not exist until just now, so modifications are still allowed.
|
|
180
285
|
var watchQueryOptions = Object.assign(otherOptions, { query: this.query });
|
|
181
286
|
if (this.renderPromises &&
|
|
182
287
|
(watchQueryOptions.fetchPolicy === "network-only" ||
|
|
183
288
|
watchQueryOptions.fetchPolicy === "cache-and-network")) {
|
|
289
|
+
// this behavior was added to react-apollo without explanation in this PR
|
|
290
|
+
// https://github.com/apollographql/react-apollo/pull/1579
|
|
184
291
|
watchQueryOptions.fetchPolicy = "cache-first";
|
|
185
292
|
}
|
|
186
293
|
if (!watchQueryOptions.variables) {
|
|
@@ -188,6 +295,9 @@ var InternalState = (function () {
|
|
|
188
295
|
}
|
|
189
296
|
if (skip) {
|
|
190
297
|
var _c = watchQueryOptions.fetchPolicy, fetchPolicy = _c === void 0 ? this.getDefaultFetchPolicy() : _c, _d = watchQueryOptions.initialFetchPolicy, initialFetchPolicy = _d === void 0 ? fetchPolicy : _d;
|
|
298
|
+
// When skipping, we set watchQueryOptions.fetchPolicy initially to
|
|
299
|
+
// "standby", but we also need/want to preserve the initial non-standby
|
|
300
|
+
// fetchPolicy that would have been used if not skipping.
|
|
191
301
|
Object.assign(watchQueryOptions, {
|
|
192
302
|
initialFetchPolicy: initialFetchPolicy,
|
|
193
303
|
fetchPolicy: "standby",
|
|
@@ -206,13 +316,19 @@ var InternalState = (function () {
|
|
|
206
316
|
((_b = this.client.defaultOptions.watchQuery) === null || _b === void 0 ? void 0 : _b.fetchPolicy) ||
|
|
207
317
|
"cache-first");
|
|
208
318
|
};
|
|
319
|
+
// Defining these methods as no-ops on the prototype allows us to call
|
|
320
|
+
// state.onCompleted and/or state.onError without worrying about whether a
|
|
321
|
+
// callback was provided.
|
|
209
322
|
InternalState.prototype.onCompleted = function (data) { };
|
|
210
323
|
InternalState.prototype.onError = function (error) { };
|
|
211
324
|
InternalState.prototype.useObservableQuery = function () {
|
|
325
|
+
// See if there is an existing observable that was used to fetch the same
|
|
326
|
+
// data and if so, use it instead since it will contain the proper queryId
|
|
327
|
+
// to fetch the result set. This is used during SSR.
|
|
212
328
|
var obsQuery = (this.observable =
|
|
213
329
|
(this.renderPromises &&
|
|
214
330
|
this.renderPromises.getSSRObservable(this.watchQueryOptions)) ||
|
|
215
|
-
this.observable ||
|
|
331
|
+
this.observable || // Reuse this.observable if possible (and not SSR)
|
|
216
332
|
this.client.watchQuery(this.getObsQueryOptions()));
|
|
217
333
|
this.obsQueryFields = React.useMemo(function () { return ({
|
|
218
334
|
refetch: obsQuery.refetch.bind(obsQuery),
|
|
@@ -227,6 +343,7 @@ var InternalState = (function () {
|
|
|
227
343
|
if (this.renderPromises && ssrAllowed) {
|
|
228
344
|
this.renderPromises.registerSSRObservable(obsQuery);
|
|
229
345
|
if (obsQuery.getCurrentResult().loading) {
|
|
346
|
+
// TODO: This is a legacy API which could probably be cleaned up
|
|
230
347
|
this.renderPromises.addObservableQueryPromise(obsQuery);
|
|
231
348
|
}
|
|
232
349
|
}
|
|
@@ -238,6 +355,8 @@ var InternalState = (function () {
|
|
|
238
355
|
this.previousData = previousResult.data;
|
|
239
356
|
}
|
|
240
357
|
this.result = nextResult;
|
|
358
|
+
// Calling state.setResult always triggers an update, though some call sites
|
|
359
|
+
// perform additional equality checks before committing to an update.
|
|
241
360
|
this.forceUpdate();
|
|
242
361
|
this.handleErrorOrCompleted(nextResult, previousResult);
|
|
243
362
|
};
|
|
@@ -245,6 +364,7 @@ var InternalState = (function () {
|
|
|
245
364
|
var _this = this;
|
|
246
365
|
if (!result.loading) {
|
|
247
366
|
var error_1 = this.toApolloError(result);
|
|
367
|
+
// wait a tick in case we are in the middle of rendering a component
|
|
248
368
|
Promise.resolve()
|
|
249
369
|
.then(function () {
|
|
250
370
|
if (error_1) {
|
|
@@ -262,11 +382,14 @@ var InternalState = (function () {
|
|
|
262
382
|
}
|
|
263
383
|
};
|
|
264
384
|
InternalState.prototype.toApolloError = function (result) {
|
|
265
|
-
return isNonEmptyArray(result.errors)
|
|
266
|
-
|
|
385
|
+
return isNonEmptyArray(result.errors) ?
|
|
386
|
+
new ApolloError({ graphQLErrors: result.errors })
|
|
267
387
|
: result.error;
|
|
268
388
|
};
|
|
269
389
|
InternalState.prototype.getCurrentResult = function () {
|
|
390
|
+
// Using this.result as a cache ensures getCurrentResult continues returning
|
|
391
|
+
// the same (===) result object, unless state.setResult has been called, or
|
|
392
|
+
// we're doing server rendering and therefore override the result below.
|
|
270
393
|
if (!this.result) {
|
|
271
394
|
this.handleErrorOrCompleted((this.result = this.observable.getCurrentResult()));
|
|
272
395
|
}
|
|
@@ -279,11 +402,20 @@ var InternalState = (function () {
|
|
|
279
402
|
var data = result.data, partial = result.partial, resultWithoutPartial = __rest(result, ["data", "partial"]);
|
|
280
403
|
this.toQueryResultCache.set(result, (queryResult = __assign(__assign(__assign({ data: data }, resultWithoutPartial), this.obsQueryFields), { client: this.client, observable: this.observable, variables: this.observable.variables, called: !this.queryHookOptions.skip, previousData: this.previousData })));
|
|
281
404
|
if (!queryResult.error && isNonEmptyArray(result.errors)) {
|
|
405
|
+
// Until a set naming convention for networkError and graphQLErrors is
|
|
406
|
+
// decided upon, we map errors (graphQLErrors) to the error options.
|
|
407
|
+
// TODO: Is it possible for both result.error and result.errors to be
|
|
408
|
+
// defined here?
|
|
282
409
|
queryResult.error = new ApolloError({ graphQLErrors: result.errors });
|
|
283
410
|
}
|
|
284
411
|
return queryResult;
|
|
285
412
|
};
|
|
286
413
|
InternalState.prototype.unsafeHandlePartialRefetch = function (result) {
|
|
414
|
+
// WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION
|
|
415
|
+
//
|
|
416
|
+
// TODO: This code should be removed when the partialRefetch option is
|
|
417
|
+
// removed. I was unable to get this hook to behave reasonably in certain
|
|
418
|
+
// edge cases when this block was put in an effect.
|
|
287
419
|
if (result.partial &&
|
|
288
420
|
this.queryHookOptions.partialRefetch &&
|
|
289
421
|
!result.loading &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAMtC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AASpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CA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gC;QAMjE,IACE,MAAM,CAAC,OAAO;YACd,IAAI,CAAC,gBAAgB,CAAC,cAAc;YACpC,CAAC,MAAM,CAAC,OAAO;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,KAAK,YAAY,EACpD;YACA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,aAAa,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AApiBD,IAoiBC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"react\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type { ApolloContextValue } from \"../context/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloClient,\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n canUseWeakMap,\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return useInternalState(useApolloClient(options.client), query).useQuery(\n options\n );\n}\n\nexport function useInternalState<TData, TVariables extends OperationVariables>(\n client: ApolloClient<any>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>\n): InternalState<TData, TVariables> {\n const stateRef = React.useRef<InternalState<TData, TVariables>>();\n if (\n !stateRef.current ||\n client !== stateRef.current.client ||\n query !== stateRef.current.query\n ) {\n stateRef.current = new InternalState(client, query, stateRef.current);\n }\n const state = stateRef.current;\n\n // By default, InternalState.prototype.forceUpdate is an empty function, but\n // we replace it here (before anyone has had a chance to see this state yet)\n // with a function that unconditionally forces an update, using the latest\n // setTick function. Updating this state by calling state.forceUpdate is the\n // only way we trigger React component updates (no other useState calls within\n // the InternalState class).\n state.forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n\n return state;\n}\n\nclass InternalState<TData, TVariables extends OperationVariables> {\n constructor(\n public readonly client: ReturnType<typeof useApolloClient>,\n public readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n previous?: InternalState<TData, TVariables>\n ) {\n verifyDocumentType(query, DocumentType.Query);\n\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n const previousResult = previous && previous.result;\n const previousData = previousResult && previousResult.data;\n if (previousData) {\n this.previousData = previousData;\n }\n }\n\n /**\n * Forces an update using local component state.\n * As this is not batched with `useSyncExternalStore` updates,\n * this is only used as a fallback if the `useSyncExternalStore` \"force update\"\n * method is not registered at the moment.\n * See https://github.com/facebook/react/issues/25191\n * */\n forceUpdateState() {\n // Replaced (in useInternalState) with a method that triggers an update.\n invariant.warn(\n \"Calling default no-op implementation of InternalState#forceUpdate\"\n );\n }\n\n /**\n * Will be overwritten by the `useSyncExternalStore` \"force update\" method\n * whenever it is available and reset to `forceUpdateState` when it isn't.\n */\n forceUpdate = () => this.forceUpdateState();\n\n executeQuery(\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n }\n ) {\n if (options.query) {\n Object.assign(this, { query: options.query });\n }\n\n this.watchQueryOptions = this.createWatchQueryOptions(\n (this.queryHookOptions = options)\n );\n\n const concast = this.observable.reobserveAsConcast(\n this.getObsQueryOptions()\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n this.forceUpdate();\n\n return new Promise<QueryResult<TData, TVariables>>((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(this.toQueryResult(this.observable.getCurrentResult()));\n },\n complete: () => {\n resolve(this.toQueryResult(result));\n },\n });\n });\n }\n\n // Methods beginning with use- should be called according to the standard\n // rules of React hooks: only at the top level of the calling function, and\n // without any dynamic conditional logic.\n useQuery(options: QueryHookOptions<TData, TVariables>) {\n // The renderPromises field gets initialized here in the useQuery method, at\n // the beginning of everything (for a given component rendering, at least),\n // so we can safely use this.renderPromises in other/later InternalState\n // methods without worrying it might be uninitialized. Even after\n // initialization, this.renderPromises is usually undefined (unless SSR is\n // happening), but that's fine as long as it has been initialized that way,\n // rather than left uninitialized.\n this.renderPromises = React.useContext(getApolloContext()).renderPromises;\n\n this.useOptions(options);\n\n const obsQuery = this.useObservableQuery();\n\n const result = useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n if (this.renderPromises) {\n return () => {};\n }\n\n this.forceUpdate = handleStoreChange;\n\n const onNext = () => {\n const previousResult = this.result;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n this.setResult(result);\n };\n\n const onError = (error: Error) => {\n subscription.unsubscribe();\n subscription = obsQuery.resubscribeAfterError(onNext, onError);\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = this.result;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n this.setResult({\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n }\n };\n\n let subscription = obsQuery.subscribe(onNext, onError);\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.unsubscribe());\n this.forceUpdate = () => this.forceUpdateState();\n };\n },\n [\n // We memoize the subscribe function using useCallback and the following\n // dependency keys, because the subscribe function reference is all that\n // useSyncExternalStore uses internally as a dependency key for the\n // useEffect ultimately responsible for the subscription, so we are\n // effectively passing this dependency array to that useEffect buried\n // inside useSyncExternalStore, as desired.\n obsQuery,\n this.renderPromises,\n this.client.disableNetworkFetches,\n ]\n ),\n\n () => this.getCurrentResult(),\n () => this.getCurrentResult()\n );\n\n // TODO Remove this method when we remove support for options.partialRefetch.\n this.unsafeHandlePartialRefetch(result);\n\n return this.toQueryResult(result);\n }\n\n // These members (except for renderPromises) are all populated by the\n // useOptions method, which is called unconditionally at the beginning of the\n // useQuery method, so we can safely use these members in other/later methods\n // without worrying they might be uninitialized.\n private renderPromises: ApolloContextValue[\"renderPromises\"];\n private queryHookOptions: QueryHookOptions<TData, TVariables>;\n private watchQueryOptions: WatchQueryOptions<TVariables, TData>;\n\n private useOptions(options: QueryHookOptions<TData, TVariables>) {\n const watchQueryOptions = this.createWatchQueryOptions(\n (this.queryHookOptions = options)\n );\n\n // Update this.watchQueryOptions, but only when they have changed, which\n // allows us to depend on the referential stability of\n // this.watchQueryOptions elsewhere.\n const currentWatchQueryOptions = this.watchQueryOptions;\n\n if (!equal(watchQueryOptions, currentWatchQueryOptions)) {\n this.watchQueryOptions = watchQueryOptions;\n\n if (currentWatchQueryOptions && this.observable) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n this.observable.reobserve(this.getObsQueryOptions());\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n }\n }\n\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n this.onCompleted =\n options.onCompleted || InternalState.prototype.onCompleted;\n this.onError = options.onError || InternalState.prototype.onError;\n\n if (\n (this.renderPromises || this.client.disableNetworkFetches) &&\n this.queryHookOptions.ssr === false &&\n !this.queryHookOptions.skip\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n this.result = this.ssrDisabledResult;\n } else if (\n this.queryHookOptions.skip ||\n this.watchQueryOptions.fetchPolicy === \"standby\"\n ) {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n this.result = this.skipStandbyResult;\n } else if (\n this.result === this.ssrDisabledResult ||\n this.result === this.skipStandbyResult\n ) {\n this.result = void 0;\n }\n }\n\n private getObsQueryOptions(): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = this.client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (this.queryHookOptions.defaultOptions) {\n toMerge.push(this.queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(\n compact(\n this.observable && this.observable.options,\n this.watchQueryOptions\n )\n );\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n }\n\n private ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n });\n\n private skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n });\n\n // A function to massage options before passing them to ObservableQuery.\n private createWatchQueryOptions({\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {}): WatchQueryOptions<\n TVariables,\n TData\n > {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query: this.query });\n\n if (\n this.renderPromises &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n const {\n fetchPolicy = this.getDefaultFetchPolicy(),\n initialFetchPolicy = fetchPolicy,\n } = watchQueryOptions;\n\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n Object.assign(watchQueryOptions, {\n initialFetchPolicy,\n fetchPolicy: \"standby\",\n });\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n this.observable?.options.initialFetchPolicy ||\n this.getDefaultFetchPolicy();\n }\n\n return watchQueryOptions;\n }\n\n getDefaultFetchPolicy(): WatchQueryFetchPolicy {\n return (\n this.queryHookOptions.defaultOptions?.fetchPolicy ||\n this.client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n }\n\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n private onCompleted(data: TData) {}\n private onError(error: ApolloError) {}\n\n private observable: ObservableQuery<TData, TVariables>;\n private obsQueryFields: Omit<\n ObservableQueryFields<TData, TVariables>,\n \"variables\"\n >;\n\n private useObservableQuery() {\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n const obsQuery = (this.observable =\n (this.renderPromises &&\n this.renderPromises.getSSRObservable(this.watchQueryOptions)) ||\n this.observable || // Reuse this.observable if possible (and not SSR)\n this.client.watchQuery(this.getObsQueryOptions()));\n\n this.obsQueryFields = React.useMemo(\n () => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n reobserve: obsQuery.reobserve.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }),\n [obsQuery]\n );\n\n const ssrAllowed = !(\n this.queryHookOptions.ssr === false || this.queryHookOptions.skip\n );\n\n if (this.renderPromises && ssrAllowed) {\n this.renderPromises.registerSSRObservable(obsQuery);\n\n if (obsQuery.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n this.renderPromises.addObservableQueryPromise(obsQuery);\n }\n }\n\n return obsQuery;\n }\n\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n private result: undefined | ApolloQueryResult<TData>;\n private previousData: undefined | TData;\n\n private setResult(nextResult: ApolloQueryResult<TData>) {\n const previousResult = this.result;\n if (previousResult && previousResult.data) {\n this.previousData = previousResult.data;\n }\n this.result = nextResult;\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n this.forceUpdate();\n this.handleErrorOrCompleted(nextResult, previousResult);\n }\n\n private handleErrorOrCompleted(\n result: ApolloQueryResult<TData>,\n previousResult?: ApolloQueryResult<TData>\n ) {\n if (!result.loading) {\n const error = this.toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n this.onError(error);\n } else if (\n result.data &&\n previousResult?.networkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n this.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n }\n\n private toApolloError(\n result: ApolloQueryResult<TData>\n ): ApolloError | undefined {\n return isNonEmptyArray(result.errors)\n ? new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n }\n\n private getCurrentResult(): ApolloQueryResult<TData> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!this.result) {\n this.handleErrorOrCompleted(\n (this.result = this.observable.getCurrentResult())\n );\n }\n return this.result;\n }\n\n // This cache allows the referential stability of this.result (as returned by\n // getCurrentResult) to translate into referential stability of the resulting\n // QueryResult object returned by toQueryResult.\n private toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)<\n ApolloQueryResult<TData>,\n QueryResult<TData, TVariables>\n >();\n\n toQueryResult(\n result: ApolloQueryResult<TData>\n ): QueryResult<TData, TVariables> {\n let queryResult = this.toQueryResultCache.get(result);\n if (queryResult) return queryResult;\n\n const { data, partial, ...resultWithoutPartial } = result;\n this.toQueryResultCache.set(\n result,\n (queryResult = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n ...this.obsQueryFields,\n client: this.client,\n observable: this.observable,\n variables: this.observable.variables,\n called: !this.queryHookOptions.skip,\n previousData: this.previousData,\n })\n );\n\n if (!queryResult.error && isNonEmptyArray(result.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n }\n\n private unsafeHandlePartialRefetch(result: ApolloQueryResult<TData>) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n this.queryHookOptions.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n this.observable.options.fetchPolicy !== \"cache-only\"\n ) {\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.refetch,\n });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AAE,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,kDAA0B,GAAlC,UAAmC,MAAgC;QACjE,+CAA+C;QAC/C,EAAE;QACF,sEAAsE;QACtE,yEAAyE;QACzE,mDAAmD;QACnD,IACE,MAAM,CAAC,OAAO;YACd,IAAI,CAAC,gBAAgB,CAAC,cAAc;YACpC,CAAC,MAAM,CAAC,OAAO;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,KAAK,YAAY,EACpD,CAAC;YACD,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,aAAa,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC5B,CAAC;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AApiBD,IAoiBC","sourcesContent":["import { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"react\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport type { ApolloContextValue } from \"../context/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloClient,\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n canUseWeakMap,\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return useInternalState(useApolloClient(options.client), query).useQuery(\n options\n );\n}\n\nexport function useInternalState<TData, TVariables extends OperationVariables>(\n client: ApolloClient<any>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>\n): InternalState<TData, TVariables> {\n const stateRef = React.useRef<InternalState<TData, TVariables>>();\n if (\n !stateRef.current ||\n client !== stateRef.current.client ||\n query !== stateRef.current.query\n ) {\n stateRef.current = new InternalState(client, query, stateRef.current);\n }\n const state = stateRef.current;\n\n // By default, InternalState.prototype.forceUpdate is an empty function, but\n // we replace it here (before anyone has had a chance to see this state yet)\n // with a function that unconditionally forces an update, using the latest\n // setTick function. Updating this state by calling state.forceUpdate is the\n // only way we trigger React component updates (no other useState calls within\n // the InternalState class).\n state.forceUpdateState = React.useReducer((tick) => tick + 1, 0)[1];\n\n return state;\n}\n\nclass InternalState<TData, TVariables extends OperationVariables> {\n constructor(\n public readonly client: ReturnType<typeof useApolloClient>,\n public readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n previous?: InternalState<TData, TVariables>\n ) {\n verifyDocumentType(query, DocumentType.Query);\n\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n const previousResult = previous && previous.result;\n const previousData = previousResult && previousResult.data;\n if (previousData) {\n this.previousData = previousData;\n }\n }\n\n /**\n * Forces an update using local component state.\n * As this is not batched with `useSyncExternalStore` updates,\n * this is only used as a fallback if the `useSyncExternalStore` \"force update\"\n * method is not registered at the moment.\n * See https://github.com/facebook/react/issues/25191\n * */\n forceUpdateState() {\n // Replaced (in useInternalState) with a method that triggers an update.\n invariant.warn(\n \"Calling default no-op implementation of InternalState#forceUpdate\"\n );\n }\n\n /**\n * Will be overwritten by the `useSyncExternalStore` \"force update\" method\n * whenever it is available and reset to `forceUpdateState` when it isn't.\n */\n forceUpdate = () => this.forceUpdateState();\n\n executeQuery(\n options: QueryHookOptions<TData, TVariables> & {\n query?: DocumentNode;\n }\n ) {\n if (options.query) {\n Object.assign(this, { query: options.query });\n }\n\n this.watchQueryOptions = this.createWatchQueryOptions(\n (this.queryHookOptions = options)\n );\n\n const concast = this.observable.reobserveAsConcast(\n this.getObsQueryOptions()\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n this.forceUpdate();\n\n return new Promise<QueryResult<TData, TVariables>>((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case\n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(this.toQueryResult(this.observable.getCurrentResult()));\n },\n complete: () => {\n resolve(this.toQueryResult(result));\n },\n });\n });\n }\n\n // Methods beginning with use- should be called according to the standard\n // rules of React hooks: only at the top level of the calling function, and\n // without any dynamic conditional logic.\n useQuery(options: QueryHookOptions<TData, TVariables>) {\n // The renderPromises field gets initialized here in the useQuery method, at\n // the beginning of everything (for a given component rendering, at least),\n // so we can safely use this.renderPromises in other/later InternalState\n // methods without worrying it might be uninitialized. Even after\n // initialization, this.renderPromises is usually undefined (unless SSR is\n // happening), but that's fine as long as it has been initialized that way,\n // rather than left uninitialized.\n this.renderPromises = React.useContext(getApolloContext()).renderPromises;\n\n this.useOptions(options);\n\n const obsQuery = this.useObservableQuery();\n\n const result = useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n if (this.renderPromises) {\n return () => {};\n }\n\n this.forceUpdate = handleStoreChange;\n\n const onNext = () => {\n const previousResult = this.result;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n this.setResult(result);\n };\n\n const onError = (error: Error) => {\n subscription.unsubscribe();\n subscription = obsQuery.resubscribeAfterError(onNext, onError);\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = this.result;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n this.setResult({\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n }\n };\n\n let subscription = obsQuery.subscribe(onNext, onError);\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.unsubscribe());\n this.forceUpdate = () => this.forceUpdateState();\n };\n },\n [\n // We memoize the subscribe function using useCallback and the following\n // dependency keys, because the subscribe function reference is all that\n // useSyncExternalStore uses internally as a dependency key for the\n // useEffect ultimately responsible for the subscription, so we are\n // effectively passing this dependency array to that useEffect buried\n // inside useSyncExternalStore, as desired.\n obsQuery,\n this.renderPromises,\n this.client.disableNetworkFetches,\n ]\n ),\n\n () => this.getCurrentResult(),\n () => this.getCurrentResult()\n );\n\n // TODO Remove this method when we remove support for options.partialRefetch.\n this.unsafeHandlePartialRefetch(result);\n\n return this.toQueryResult(result);\n }\n\n // These members (except for renderPromises) are all populated by the\n // useOptions method, which is called unconditionally at the beginning of the\n // useQuery method, so we can safely use these members in other/later methods\n // without worrying they might be uninitialized.\n private renderPromises: ApolloContextValue[\"renderPromises\"];\n private queryHookOptions!: QueryHookOptions<TData, TVariables>;\n private watchQueryOptions!: WatchQueryOptions<TVariables, TData>;\n\n private useOptions(options: QueryHookOptions<TData, TVariables>) {\n const watchQueryOptions = this.createWatchQueryOptions(\n (this.queryHookOptions = options)\n );\n\n // Update this.watchQueryOptions, but only when they have changed, which\n // allows us to depend on the referential stability of\n // this.watchQueryOptions elsewhere.\n const currentWatchQueryOptions = this.watchQueryOptions;\n\n if (!equal(watchQueryOptions, currentWatchQueryOptions)) {\n this.watchQueryOptions = watchQueryOptions;\n\n if (currentWatchQueryOptions && this.observable) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n this.observable.reobserve(this.getObsQueryOptions());\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n }\n }\n\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n this.onCompleted =\n options.onCompleted || InternalState.prototype.onCompleted;\n this.onError = options.onError || InternalState.prototype.onError;\n\n if (\n (this.renderPromises || this.client.disableNetworkFetches) &&\n this.queryHookOptions.ssr === false &&\n !this.queryHookOptions.skip\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n this.result = this.ssrDisabledResult;\n } else if (\n this.queryHookOptions.skip ||\n this.watchQueryOptions.fetchPolicy === \"standby\"\n ) {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n this.result = this.skipStandbyResult;\n } else if (\n this.result === this.ssrDisabledResult ||\n this.result === this.skipStandbyResult\n ) {\n this.result = void 0;\n }\n }\n\n private getObsQueryOptions(): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = this.client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (this.queryHookOptions.defaultOptions) {\n toMerge.push(this.queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(\n compact(\n this.observable && this.observable.options,\n this.watchQueryOptions\n )\n );\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n }\n\n private ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n });\n\n private skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n });\n\n // A function to massage options before passing them to ObservableQuery.\n private createWatchQueryOptions({\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {}): WatchQueryOptions<\n TVariables,\n TData\n > {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query: this.query });\n\n if (\n this.renderPromises &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n const {\n fetchPolicy = this.getDefaultFetchPolicy(),\n initialFetchPolicy = fetchPolicy,\n } = watchQueryOptions;\n\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n Object.assign(watchQueryOptions, {\n initialFetchPolicy,\n fetchPolicy: \"standby\",\n });\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n this.observable?.options.initialFetchPolicy ||\n this.getDefaultFetchPolicy();\n }\n\n return watchQueryOptions;\n }\n\n getDefaultFetchPolicy(): WatchQueryFetchPolicy {\n return (\n this.queryHookOptions.defaultOptions?.fetchPolicy ||\n this.client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n }\n\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n private onCompleted(data: TData) {}\n private onError(error: ApolloError) {}\n\n private observable!: ObservableQuery<TData, TVariables>;\n private obsQueryFields!: Omit<\n ObservableQueryFields<TData, TVariables>,\n \"variables\"\n >;\n\n private useObservableQuery() {\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n const obsQuery = (this.observable =\n (this.renderPromises &&\n this.renderPromises.getSSRObservable(this.watchQueryOptions)) ||\n this.observable || // Reuse this.observable if possible (and not SSR)\n this.client.watchQuery(this.getObsQueryOptions()));\n\n this.obsQueryFields = React.useMemo(\n () => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n reobserve: obsQuery.reobserve.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }),\n [obsQuery]\n );\n\n const ssrAllowed = !(\n this.queryHookOptions.ssr === false || this.queryHookOptions.skip\n );\n\n if (this.renderPromises && ssrAllowed) {\n this.renderPromises.registerSSRObservable(obsQuery);\n\n if (obsQuery.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n this.renderPromises.addObservableQueryPromise(obsQuery);\n }\n }\n\n return obsQuery;\n }\n\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n private result: undefined | ApolloQueryResult<TData>;\n private previousData: undefined | TData;\n\n private setResult(nextResult: ApolloQueryResult<TData>) {\n const previousResult = this.result;\n if (previousResult && previousResult.data) {\n this.previousData = previousResult.data;\n }\n this.result = nextResult;\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n this.forceUpdate();\n this.handleErrorOrCompleted(nextResult, previousResult);\n }\n\n private handleErrorOrCompleted(\n result: ApolloQueryResult<TData>,\n previousResult?: ApolloQueryResult<TData>\n ) {\n if (!result.loading) {\n const error = this.toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n this.onError(error);\n } else if (\n result.data &&\n previousResult?.networkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n this.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n }\n\n private toApolloError(\n result: ApolloQueryResult<TData>\n ): ApolloError | undefined {\n return isNonEmptyArray(result.errors) ?\n new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n }\n\n private getCurrentResult(): ApolloQueryResult<TData> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!this.result) {\n this.handleErrorOrCompleted(\n (this.result = this.observable.getCurrentResult())\n );\n }\n return this.result;\n }\n\n // This cache allows the referential stability of this.result (as returned by\n // getCurrentResult) to translate into referential stability of the resulting\n // QueryResult object returned by toQueryResult.\n private toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)<\n ApolloQueryResult<TData>,\n QueryResult<TData, TVariables>\n >();\n\n toQueryResult(\n result: ApolloQueryResult<TData>\n ): QueryResult<TData, TVariables> {\n let queryResult = this.toQueryResultCache.get(result);\n if (queryResult) return queryResult;\n\n const { data, partial, ...resultWithoutPartial } = result;\n this.toQueryResultCache.set(\n result,\n (queryResult = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n ...this.obsQueryFields,\n client: this.client,\n observable: this.observable,\n variables: this.observable.variables,\n called: !this.queryHookOptions.skip,\n previousData: this.previousData,\n })\n );\n\n if (!queryResult.error && isNonEmptyArray(result.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n }\n\n private unsafeHandlePartialRefetch(result: ApolloQueryResult<TData>) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n this.queryHookOptions.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n this.observable.options.fetchPolicy !== \"cache-only\"\n ) {\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.refetch,\n });\n this.observable.refetch();\n }\n }\n}\n"]}
|
|
@@ -2,6 +2,11 @@ import * as React from "react";
|
|
|
2
2
|
import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
3
3
|
export function useReactiveVar(rv) {
|
|
4
4
|
return useSyncExternalStore(React.useCallback(function (update) {
|
|
5
|
+
// By reusing the same onNext function in the nested call to
|
|
6
|
+
// rv.onNextChange(onNext), we can keep using the initial clean-up function
|
|
7
|
+
// returned by rv.onNextChange(function onNext(v){...}), without having to
|
|
8
|
+
// register the new clean-up function (returned by the nested
|
|
9
|
+
// rv.onNextChange(onNext)) with yet another callback.
|
|
5
10
|
return rv.onNextChange(function onNext() {
|
|
6
11
|
update();
|
|
7
12
|
rv.onNextChange(onNext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReactiveVar.js","sourceRoot":"","sources":["../../../src/react/hooks/useReactiveVar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,UAAU,cAAc,CAAI,EAAkB;IAClD,OAAO,oBAAoB,CACzB,KAAK,CAAC,WAAW,CACf,UAAC,MAAM;
|
|
1
|
+
{"version":3,"file":"useReactiveVar.js","sourceRoot":"","sources":["../../../src/react/hooks/useReactiveVar.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,UAAU,cAAc,CAAI,EAAkB;IAClD,OAAO,oBAAoB,CACzB,KAAK,CAAC,WAAW,CACf,UAAC,MAAM;QACL,4DAA4D;QAC5D,2EAA2E;QAC3E,0EAA0E;QAC1E,6DAA6D;QAC7D,sDAAsD;QACtD,OAAO,EAAE,CAAC,YAAY,CAAC,SAAS,MAAM;YACpC,MAAM,EAAE,CAAC;YACT,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;QAC1B,CAAC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,EAAE,CAAC,CACL,EACD,EAAE,EACF,EAAE,CACH,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"react\";\nimport type { ReactiveVar } from \"../../core/index.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport function useReactiveVar<T>(rv: ReactiveVar<T>): T {\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n // By reusing the same onNext function in the nested call to\n // rv.onNextChange(onNext), we can keep using the initial clean-up function\n // returned by rv.onNextChange(function onNext(v){...}), without having to\n // register the new clean-up function (returned by the nested\n // rv.onNextChange(onNext)) with yet another callback.\n return rv.onNextChange(function onNext() {\n update();\n rv.onNextChange(onNext);\n });\n },\n [rv]\n ),\n rv,\n rv\n );\n}\n"]}
|
|
@@ -2,8 +2,27 @@ import type { QueryReference } from "../cache/QueryReference.js";
|
|
|
2
2
|
import type { ApolloError } from "../../errors/index.js";
|
|
3
3
|
import type { NetworkStatus } from "../../core/index.js";
|
|
4
4
|
export interface UseReadQueryResult<TData = unknown> {
|
|
5
|
+
/**
|
|
6
|
+
* An object containing the result of your GraphQL query after it completes.
|
|
7
|
+
*
|
|
8
|
+
* This value might be `undefined` if a query results in one or more errors
|
|
9
|
+
* (depending on the query's `errorPolicy`).
|
|
10
|
+
*/
|
|
5
11
|
data: TData;
|
|
12
|
+
/**
|
|
13
|
+
* If the query produces one or more errors, this object contains either an
|
|
14
|
+
* array of `graphQLErrors` or a single `networkError`. Otherwise, this value
|
|
15
|
+
* is `undefined`.
|
|
16
|
+
*
|
|
17
|
+
* This property can be ignored when using the default `errorPolicy` or an
|
|
18
|
+
* `errorPolicy` of `none`. The hook will throw the error instead of setting
|
|
19
|
+
* this property.
|
|
20
|
+
*/
|
|
6
21
|
error: ApolloError | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* A number indicating the current network state of the query's associated
|
|
24
|
+
* request. {@link https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/core/networkStatus.ts#L4 | See possible values}.
|
|
25
|
+
*/
|
|
7
26
|
networkStatus: NetworkStatus;
|
|
8
27
|
}
|
|
9
28
|
export declare function useReadQuery<TData>(queryRef: QueryReference<TData>): UseReadQueryResult<TData>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useReadQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useReadQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAE5D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AA6BjE,MAAM,UAAU,YAAY,CAC1B,QAA+B;IAE/B,IAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAClD,SAAS,CACP,gBAAgB,CAAC,YAAY,EAC7B,2EAA2E;QACzE,sEAAsE;QACtE,kFAAkF,CACrF,CAAC;IAEM,IAAA,YAAY,GAAU,gBAAgB,aAA1B,EAAE,GAAG,GAAK,gBAAgB,IAArB,CAAsB;IAE/C,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"useReadQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useReadQuery.ts"],"names":[],"mappings":"AAAA,OAA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,OAAO,KAAK,CAAC,OAAO,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC;SAC7B,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AACf,CAAC","sourcesContent":["import * as React from \"react\";\nimport { unwrapQueryRef } from \"../cache/QueryReference.js\";\nimport type { QueryReference } from \"../cache/QueryReference.js\";\nimport { __use } from \"./internal/index.js\";\nimport { toApolloError } from \"./useSuspenseQuery.js\";\nimport { invariant } from \"../../utilities/globals/index.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloError } from \"../../errors/index.js\";\nimport type { NetworkStatus } from \"../../core/index.js\";\n\nexport interface UseReadQueryResult<TData = unknown> {\n /**\n * An object containing the result of your GraphQL query after it completes.\n *\n * This value might be `undefined` if a query results in one or more errors\n * (depending on the query's `errorPolicy`).\n */\n data: TData;\n /**\n * If the query produces one or more errors, this object contains either an\n * array of `graphQLErrors` or a single `networkError`. Otherwise, this value\n * is `undefined`.\n *\n * This property can be ignored when using the default `errorPolicy` or an\n * `errorPolicy` of `none`. The hook will throw the error instead of setting\n * this property.\n */\n error: ApolloError | undefined;\n /**\n * A number indicating the current network state of the query's associated\n * request. {@link https://github.com/apollographql/apollo-client/blob/d96f4578f89b933c281bb775a39503f6cdb59ee8/src/core/networkStatus.ts#L4 | See possible values}.\n */\n networkStatus: NetworkStatus;\n}\n\nexport function useReadQuery<TData>(\n queryRef: QueryReference<TData>\n): UseReadQueryResult<TData> {\n const internalQueryRef = unwrapQueryRef(queryRef);\n invariant(\n internalQueryRef.promiseCache,\n \"It appears that `useReadQuery` was used outside of `useBackgroundQuery`. \" +\n \"`useReadQuery` is only supported for use with `useBackgroundQuery`. \" +\n \"Please ensure you are passing the `queryRef` returned from `useBackgroundQuery`.\"\n );\n\n const { promiseCache, key } = internalQueryRef;\n\n if (!promiseCache.has(key)) {\n promiseCache.set(key, internalQueryRef.promise);\n }\n\n const promise = useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n return internalQueryRef.listen((promise) => {\n internalQueryRef.promiseCache!.set(internalQueryRef.key, promise);\n forceUpdate();\n });\n },\n [internalQueryRef]\n ),\n () => promiseCache.get(key)!,\n () => promiseCache.get(key)!\n );\n\n const result = __use(promise);\n\n return React.useMemo(() => {\n return {\n data: result.data,\n networkStatus: result.networkStatus,\n error: toApolloError(result),\n };\n }, [result]);\n}\n"]}
|
|
@@ -95,6 +95,8 @@ export function useSubscription(subscription, options) {
|
|
|
95
95
|
}
|
|
96
96
|
var result = {
|
|
97
97
|
loading: false,
|
|
98
|
+
// TODO: fetchResult.data can be null but SubscriptionResult.data
|
|
99
|
+
// expects TData | undefined only
|
|
98
100
|
data: fetchResult.data,
|
|
99
101
|
error: void 0,
|
|
100
102
|
variables: options === null || options === void 0 ? void 0 : options.variables,
|
|
@@ -138,6 +140,9 @@ export function useSubscription(subscription, options) {
|
|
|
138
140
|
},
|
|
139
141
|
});
|
|
140
142
|
return function () {
|
|
143
|
+
// immediately stop receiving subscription values, but do not unsubscribe
|
|
144
|
+
// until after a short delay in case another useSubscription hook is
|
|
145
|
+
// reusing the same underlying observable and is about to subscribe
|
|
141
146
|
subscriptionStopped = true;
|
|
142
147
|
setTimeout(function () {
|
|
143
148
|
subscription.unsubscribe();
|