@apollo/client 4.0.0-rc.6 → 4.0.0-rc.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/CHANGELOG.md +159 -0
- package/__cjs/cache/core/cache.cjs +12 -7
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +12 -7
- package/__cjs/core/ApolloClient.cjs +2 -2
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +80 -98
- package/__cjs/core/ObservableQuery.d.cts +41 -74
- package/__cjs/core/QueryInfo.cjs.map +1 -1
- package/__cjs/core/QueryInfo.d.cts +3 -3
- package/__cjs/core/QueryManager.cjs +0 -2
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/QueryManager.d.cts +3 -3
- package/__cjs/core/index.cjs +1 -2
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -3
- package/__cjs/core/types.d.cts +40 -28
- package/__cjs/errors/CombinedGraphQLErrors.cjs +22 -17
- package/__cjs/errors/CombinedGraphQLErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedGraphQLErrors.d.cts +39 -20
- package/__cjs/errors/CombinedProtocolErrors.cjs +12 -6
- package/__cjs/errors/CombinedProtocolErrors.cjs.map +1 -1
- package/__cjs/errors/CombinedProtocolErrors.d.cts +12 -6
- package/__cjs/errors/ServerError.cjs +2 -1
- package/__cjs/errors/ServerError.cjs.map +1 -1
- package/__cjs/errors/ServerError.d.cts +2 -1
- package/__cjs/errors/ServerParseError.cjs +2 -1
- package/__cjs/errors/ServerParseError.cjs.map +1 -1
- package/__cjs/errors/ServerParseError.d.cts +2 -1
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +4 -4
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/incremental/handlers/notImplemented.d.cts +2 -2
- package/__cjs/incremental/types.d.cts +4 -4
- package/__cjs/invariantErrorCodes.cjs +15 -11
- package/__cjs/link/batch/batchLink.cjs +4 -12
- package/__cjs/link/batch/batchLink.cjs.map +1 -1
- package/__cjs/link/batch/batchLink.d.cts +36 -28
- package/__cjs/link/batch/batching.cjs +1 -1
- package/__cjs/link/batch/batching.cjs.map +1 -1
- package/__cjs/link/batch/batching.d.cts +8 -8
- package/__cjs/link/batch/index.cjs +1 -2
- package/__cjs/link/batch/index.cjs.map +1 -1
- package/__cjs/link/batch/index.d.cts +1 -2
- package/__cjs/link/batch-http/batchHttpLink.cjs +29 -6
- package/__cjs/link/batch-http/batchHttpLink.cjs.map +1 -1
- package/__cjs/link/batch-http/batchHttpLink.d.cts +45 -6
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs +33 -0
- package/__cjs/link/client-awareness/ClientAwarenessLink.cjs.map +1 -1
- package/__cjs/link/client-awareness/ClientAwarenessLink.d.cts +35 -2
- package/__cjs/link/context/index.cjs.map +1 -1
- package/__cjs/link/context/index.d.cts +3 -4
- package/__cjs/link/core/ApolloLink.cjs +226 -54
- package/__cjs/link/core/ApolloLink.cjs.map +1 -1
- package/__cjs/link/core/ApolloLink.d.cts +355 -9
- package/__cjs/link/core/concat.cjs +4 -0
- package/__cjs/link/core/concat.cjs.map +1 -1
- package/__cjs/link/core/concat.d.cts +4 -0
- package/__cjs/link/core/deprecated.cjs +3 -0
- package/__cjs/link/core/deprecated.cjs.map +1 -0
- package/__cjs/link/core/deprecated.d.cts +10 -0
- package/__cjs/link/core/empty.cjs +4 -0
- package/__cjs/link/core/empty.cjs.map +1 -1
- package/__cjs/link/core/empty.d.cts +4 -0
- package/__cjs/link/core/from.cjs +4 -0
- package/__cjs/link/core/from.cjs.map +1 -1
- package/__cjs/link/core/from.d.cts +4 -0
- package/__cjs/link/core/split.cjs +4 -0
- package/__cjs/link/core/split.cjs.map +1 -1
- package/__cjs/link/core/split.d.cts +4 -0
- package/__cjs/link/core/types.d.cts +2 -33
- package/__cjs/link/error/index.cjs +44 -0
- package/__cjs/link/error/index.cjs.map +1 -1
- package/__cjs/link/error/index.d.cts +68 -9
- package/__cjs/link/http/BaseHttpLink.cjs +3 -4
- package/__cjs/link/http/BaseHttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.cjs +26 -1
- package/__cjs/link/http/HttpLink.cjs.map +1 -1
- package/__cjs/link/http/HttpLink.d.cts +191 -89
- package/__cjs/link/http/index.cjs +1 -3
- package/__cjs/link/http/index.cjs.map +1 -1
- package/__cjs/link/http/index.d.cts +0 -2
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs +40 -25
- package/__cjs/link/http/parseAndCheckHttpResponse.cjs.map +1 -1
- package/__cjs/link/http/parseAndCheckHttpResponse.d.cts +2 -2
- package/__cjs/link/http/rewriteURIForGET.cjs +2 -3
- package/__cjs/link/http/rewriteURIForGET.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.cjs.map +1 -1
- package/__cjs/link/http/selectHttpOptionsAndBody.d.cts +3 -3
- package/__cjs/link/http/selectURI.cjs.map +1 -1
- package/__cjs/link/http/selectURI.d.cts +2 -2
- package/__cjs/link/index.cjs.map +1 -1
- package/__cjs/link/index.d.cts +2 -1
- package/__cjs/link/persisted-queries/index.cjs.map +1 -1
- package/__cjs/link/persisted-queries/index.d.cts +23 -25
- package/__cjs/link/remove-typename/index.cjs.map +1 -1
- package/__cjs/link/remove-typename/index.d.cts +0 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.cjs.map +1 -1
- package/__cjs/link/remove-typename/removeTypenameFromVariables.d.cts +9 -8
- package/__cjs/link/retry/delayFunction.cjs.map +1 -1
- package/__cjs/link/retry/delayFunction.d.cts +2 -39
- package/__cjs/link/retry/retryFunction.cjs.map +1 -1
- package/__cjs/link/retry/retryFunction.d.cts +2 -29
- package/__cjs/link/retry/retryLink.cjs +12 -9
- package/__cjs/link/retry/retryLink.cjs.map +1 -1
- package/__cjs/link/retry/retryLink.d.cts +57 -6
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +3 -4
- package/__cjs/link/subscriptions/index.cjs +23 -0
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- package/__cjs/link/subscriptions/index.d.cts +24 -2
- package/__cjs/link/utils/createOperation.cjs +12 -4
- package/__cjs/link/utils/createOperation.cjs.map +1 -1
- package/__cjs/link/utils/createOperation.d.cts +2 -2
- package/__cjs/link/utils/index.cjs +1 -5
- package/__cjs/link/utils/index.cjs.map +1 -1
- package/__cjs/link/utils/index.d.cts +0 -2
- package/__cjs/link/ws/index.cjs +17 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +8 -2
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +125 -93
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +2 -2
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +70 -108
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +52 -61
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +36 -54
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +64 -105
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.d.cts +17 -8
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +6 -9
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +32 -24
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +75 -94
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +3 -1
- package/__cjs/react/query-preloader/createQueryPreloader.cjs.map +1 -1
- package/__cjs/react/query-preloader/createQueryPreloader.d.cts +29 -20
- package/__cjs/react/types/types.documentation.d.cts +5 -5
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +5 -6
- package/__cjs/testing/core/mocking/mockSubscriptionLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockSubscriptionLink.d.cts +3 -4
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +20 -28
- package/__cjs/utilities/internal/types/VariablesOption.d.cts +2 -6
- package/__cjs/utilities/subscriptions/relay/index.cjs +1 -2
- package/__cjs/utilities/subscriptions/relay/index.cjs.map +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +12 -7
- package/cache/core/cache.js +12 -7
- package/cache/core/cache.js.map +1 -1
- package/core/ApolloClient.d.ts +80 -98
- package/core/ApolloClient.js +2 -2
- package/core/ApolloClient.js.map +1 -1
- package/core/ObservableQuery.d.ts +41 -74
- package/core/QueryInfo.d.ts +3 -3
- package/core/QueryInfo.js.map +1 -1
- package/core/QueryManager.d.ts +3 -3
- package/core/QueryManager.js +0 -2
- package/core/QueryManager.js.map +1 -1
- package/core/index.d.ts +2 -3
- package/core/index.js +1 -1
- package/core/index.js.map +1 -1
- package/core/types.d.ts +40 -28
- package/errors/CombinedGraphQLErrors.d.ts +39 -20
- package/errors/CombinedGraphQLErrors.js +22 -17
- package/errors/CombinedGraphQLErrors.js.map +1 -1
- package/errors/CombinedProtocolErrors.d.ts +12 -6
- package/errors/CombinedProtocolErrors.js +12 -6
- package/errors/CombinedProtocolErrors.js.map +1 -1
- package/errors/ServerError.d.ts +2 -1
- package/errors/ServerError.js +2 -1
- package/errors/ServerError.js.map +1 -1
- package/errors/ServerParseError.d.ts +2 -1
- package/errors/ServerParseError.js +2 -1
- package/errors/ServerParseError.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +4 -4
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/notImplemented.d.ts +2 -2
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/incremental/types.d.ts +4 -4
- package/incremental/types.js.map +1 -1
- package/invariantErrorCodes.js +15 -11
- package/link/batch/batchLink.d.ts +37 -29
- package/link/batch/batchLink.js +3 -10
- package/link/batch/batchLink.js.map +1 -1
- package/link/batch/batching.d.ts +8 -8
- package/link/batch/batching.js +2 -2
- package/link/batch/batching.js.map +1 -1
- package/link/batch/index.d.ts +1 -2
- package/link/batch/index.js +1 -1
- package/link/batch/index.js.map +1 -1
- package/link/batch-http/batchHttpLink.d.ts +46 -7
- package/link/batch-http/batchHttpLink.js +30 -7
- package/link/batch-http/batchHttpLink.js.map +1 -1
- package/link/client-awareness/ClientAwarenessLink.d.ts +35 -2
- package/link/client-awareness/ClientAwarenessLink.js +33 -0
- package/link/client-awareness/ClientAwarenessLink.js.map +1 -1
- package/link/context/index.d.ts +3 -4
- package/link/context/index.js.map +1 -1
- package/link/core/ApolloLink.d.ts +355 -9
- package/link/core/ApolloLink.js +227 -56
- package/link/core/ApolloLink.js.map +1 -1
- package/link/core/concat.d.ts +4 -0
- package/link/core/concat.js +4 -0
- package/link/core/concat.js.map +1 -1
- package/link/core/deprecated.d.ts +10 -0
- package/link/core/deprecated.js +2 -0
- package/link/core/deprecated.js.map +1 -0
- package/link/core/empty.d.ts +4 -0
- package/link/core/empty.js +4 -0
- package/link/core/empty.js.map +1 -1
- package/link/core/from.d.ts +4 -0
- package/link/core/from.js +4 -0
- package/link/core/from.js.map +1 -1
- package/link/core/split.d.ts +4 -0
- package/link/core/split.js +4 -0
- package/link/core/split.js.map +1 -1
- package/link/core/types.d.ts +2 -33
- package/link/core/types.js.map +1 -1
- package/link/error/index.d.ts +69 -10
- package/link/error/index.js +44 -0
- package/link/error/index.js.map +1 -1
- package/link/http/BaseHttpLink.js +3 -4
- package/link/http/BaseHttpLink.js.map +1 -1
- package/link/http/HttpLink.d.ts +192 -90
- package/link/http/HttpLink.js +26 -1
- package/link/http/HttpLink.js.map +1 -1
- package/link/http/index.d.ts +0 -2
- package/link/http/index.js +0 -1
- package/link/http/index.js.map +1 -1
- package/link/http/parseAndCheckHttpResponse.d.ts +2 -2
- package/link/http/parseAndCheckHttpResponse.js +40 -25
- package/link/http/parseAndCheckHttpResponse.js.map +1 -1
- package/link/http/rewriteURIForGET.js +2 -3
- package/link/http/rewriteURIForGET.js.map +1 -1
- package/link/http/selectHttpOptionsAndBody.d.ts +3 -3
- package/link/http/selectHttpOptionsAndBody.js.map +1 -1
- package/link/http/selectURI.d.ts +2 -2
- package/link/http/selectURI.js.map +1 -1
- package/link/index.d.ts +2 -1
- package/link/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +23 -25
- package/link/persisted-queries/index.js.map +1 -1
- package/link/remove-typename/index.d.ts +0 -1
- package/link/remove-typename/index.js.map +1 -1
- package/link/remove-typename/removeTypenameFromVariables.d.ts +9 -8
- package/link/remove-typename/removeTypenameFromVariables.js.map +1 -1
- package/link/retry/delayFunction.d.ts +2 -39
- package/link/retry/delayFunction.js.map +1 -1
- package/link/retry/retryFunction.d.ts +2 -29
- package/link/retry/retryFunction.js.map +1 -1
- package/link/retry/retryLink.d.ts +57 -6
- package/link/retry/retryLink.js +13 -10
- package/link/retry/retryLink.js.map +1 -1
- package/link/schema/index.d.ts +3 -4
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.d.ts +24 -2
- package/link/subscriptions/index.js +23 -0
- package/link/subscriptions/index.js.map +1 -1
- package/link/utils/createOperation.d.ts +2 -2
- package/link/utils/createOperation.js +12 -4
- package/link/utils/createOperation.js.map +1 -1
- package/link/utils/index.d.ts +0 -2
- package/link/utils/index.js +0 -2
- package/link/utils/index.js.map +1 -1
- package/link/ws/index.d.ts +8 -2
- package/link/ws/index.js +13 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +125 -93
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.d.ts +2 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +70 -108
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +52 -61
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +36 -54
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +64 -105
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.d.ts +17 -8
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +6 -9
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +32 -24
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +75 -94
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +125 -93
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +2 -2
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +70 -108
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +52 -61
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +36 -54
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +64 -105
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.d.ts +17 -8
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +6 -9
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +32 -24
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +75 -94
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +3 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/query-preloader/createQueryPreloader.d.ts +29 -20
- package/react/query-preloader/createQueryPreloader.js.map +1 -1
- package/react/types/types.documentation.d.ts +5 -5
- package/testing/core/mocking/mockLink.d.ts +5 -6
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/testing/core/mocking/mockSubscriptionLink.d.ts +3 -4
- package/testing/core/mocking/mockSubscriptionLink.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +20 -28
- package/utilities/internal/types/VariablesOption.d.ts +2 -6
- package/utilities/subscriptions/relay/index.js +1 -2
- package/utilities/subscriptions/relay/index.js.map +1 -1
- package/version.js +1 -1
- package/__cjs/link/http/serializeFetchParameter.cjs +0 -18
- package/__cjs/link/http/serializeFetchParameter.cjs.map +0 -1
- package/__cjs/link/http/serializeFetchParameter.d.cts +0 -6
- package/__cjs/link/utils/transformOperation.cjs +0 -22
- package/__cjs/link/utils/transformOperation.cjs.map +0 -1
- package/__cjs/link/utils/transformOperation.d.cts +0 -3
- package/__cjs/link/utils/validateOperation.cjs +0 -21
- package/__cjs/link/utils/validateOperation.cjs.map +0 -1
- package/__cjs/link/utils/validateOperation.d.cts +0 -3
- package/link/http/serializeFetchParameter.d.ts +0 -6
- package/link/http/serializeFetchParameter.js +0 -14
- package/link/http/serializeFetchParameter.js.map +0 -1
- package/link/utils/transformOperation.d.ts +0 -3
- package/link/utils/transformOperation.js +0 -19
- package/link/utils/transformOperation.js.map +0 -1
- package/link/utils/validateOperation.d.ts +0 -3
- package/link/utils/validateOperation.js +0 -18
- package/link/utils/validateOperation.js.map +0 -1
|
@@ -11,19 +11,16 @@ export declare namespace useSuspenseQuery {
|
|
|
11
11
|
/**
|
|
12
12
|
* The instance of `ApolloClient` to use to execute the query.
|
|
13
13
|
*
|
|
14
|
-
* By default, the instance that's passed down via context is used, but you
|
|
14
|
+
* By default, the instance that's passed down via context is used, but you
|
|
15
|
+
* can provide a different instance here.
|
|
15
16
|
*
|
|
16
|
-
* @docGroup
|
|
17
|
-
*
|
|
18
|
-
* 1. Operation options
|
|
17
|
+
* @docGroup 1. Operation options
|
|
19
18
|
*/
|
|
20
19
|
client?: ApolloClient;
|
|
21
20
|
/**
|
|
22
21
|
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
23
22
|
*
|
|
24
|
-
* @docGroup
|
|
25
|
-
*
|
|
26
|
-
* 2. Networking options
|
|
23
|
+
* @docGroup 2. Networking options
|
|
27
24
|
*/
|
|
28
25
|
context?: DefaultContext;
|
|
29
26
|
/**
|
|
@@ -33,9 +30,7 @@ export declare namespace useSuspenseQuery {
|
|
|
33
30
|
*
|
|
34
31
|
* The default value is `none`, meaning that the query result includes error details but not partial results.
|
|
35
32
|
*
|
|
36
|
-
* @docGroup
|
|
37
|
-
*
|
|
38
|
-
* 1. Operation options
|
|
33
|
+
* @docGroup 1. Operation options
|
|
39
34
|
*/
|
|
40
35
|
errorPolicy?: ErrorPolicy;
|
|
41
36
|
/**
|
|
@@ -43,9 +38,7 @@ export declare namespace useSuspenseQuery {
|
|
|
43
38
|
*
|
|
44
39
|
* The default value is `false`.
|
|
45
40
|
*
|
|
46
|
-
* @docGroup
|
|
47
|
-
*
|
|
48
|
-
* 3. Caching options
|
|
41
|
+
* @docGroup 3. Caching options
|
|
49
42
|
*/
|
|
50
43
|
returnPartialData?: boolean;
|
|
51
44
|
/**
|
|
@@ -53,9 +46,7 @@ export declare namespace useSuspenseQuery {
|
|
|
53
46
|
*
|
|
54
47
|
* The default value is "overwrite".
|
|
55
48
|
*
|
|
56
|
-
* @docGroup
|
|
57
|
-
*
|
|
58
|
-
* 3. Caching options
|
|
49
|
+
* @docGroup 3. Caching options
|
|
59
50
|
*/
|
|
60
51
|
refetchWritePolicy?: RefetchWritePolicy;
|
|
61
52
|
/**
|
|
@@ -65,34 +56,31 @@ export declare namespace useSuspenseQuery {
|
|
|
65
56
|
*
|
|
66
57
|
* The default value is `cache-first`.
|
|
67
58
|
*
|
|
68
|
-
* @docGroup
|
|
69
|
-
*
|
|
70
|
-
* 3. Caching options
|
|
59
|
+
* @docGroup 3. Caching options
|
|
71
60
|
*/
|
|
72
61
|
fetchPolicy?: FetchPolicy;
|
|
73
62
|
/**
|
|
74
|
-
* A unique identifier for the query. Each item in the array must be a stable
|
|
63
|
+
* A unique identifier for the query. Each item in the array must be a stable
|
|
64
|
+
* identifier to prevent infinite fetches.
|
|
75
65
|
*
|
|
76
|
-
* This is useful when using the same query and variables combination in more
|
|
66
|
+
* This is useful when using the same query and variables combination in more
|
|
67
|
+
* than one component, otherwise the components may clobber each other. This
|
|
68
|
+
* can also be used to force the query to re-evaluate fresh.
|
|
77
69
|
*
|
|
78
|
-
* @docGroup
|
|
79
|
-
*
|
|
80
|
-
* 1. Operation options
|
|
70
|
+
* @docGroup 1. Operation options
|
|
81
71
|
*/
|
|
82
72
|
queryKey?: string | number | any[];
|
|
83
73
|
/**
|
|
84
74
|
* If `true`, the query is not executed. The default value is `false`.
|
|
85
75
|
*
|
|
86
|
-
* @deprecated
|
|
87
|
-
*
|
|
88
|
-
* We recommend using `skipToken` in place of the `skip` option as it is more type-safe.
|
|
89
|
-
*
|
|
90
|
-
* This option is deprecated and only supported to ease the migration from `useQuery`. It will be removed in a future release. Please use [`skipToken`](https://www.apollographql.com/docs/react/api/react/hooks#skiptoken) instead of the `skip` option as it is more type-safe.
|
|
76
|
+
* @deprecated We recommend using `skipToken` in place of the `skip` option as
|
|
77
|
+
* it is more type-safe.
|
|
91
78
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* 1. Operation options
|
|
79
|
+
* This option is deprecated and only supported to ease the migration from `useQuery`. It will be removed in a future release.
|
|
80
|
+
* Please use [`skipToken`](https://www.apollographql.com/docs/react/api/react/hooks#skiptoken) instead of the `skip` option as it is more type-safe.
|
|
95
81
|
*
|
|
82
|
+
* @docGroup 1. Operation options
|
|
83
|
+
*
|
|
96
84
|
*
|
|
97
85
|
* @example Recommended usage of `skipToken`:
|
|
98
86
|
*
|
|
@@ -120,31 +108,27 @@ export declare namespace useSuspenseQuery {
|
|
|
120
108
|
/**
|
|
121
109
|
* The instance of `ApolloClient` to use to execute the query.
|
|
122
110
|
*
|
|
123
|
-
* By default, the instance that's passed down via context is used, but you
|
|
124
|
-
*
|
|
125
|
-
* @docGroup
|
|
111
|
+
* By default, the instance that's passed down via context is used, but you
|
|
112
|
+
* can provide a different instance here.
|
|
126
113
|
*
|
|
127
|
-
* 1. Operation options
|
|
114
|
+
* @docGroup 1. Operation options
|
|
128
115
|
*/
|
|
129
116
|
client: ApolloClient;
|
|
130
117
|
/**
|
|
131
|
-
* A single ErrorLike object describing the error that occured during the latest
|
|
118
|
+
* A single ErrorLike object describing the error that occured during the latest
|
|
119
|
+
* query execution.
|
|
132
120
|
*
|
|
133
121
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
134
122
|
*
|
|
135
|
-
* @docGroup
|
|
136
|
-
*
|
|
137
|
-
* 1. Operation data
|
|
123
|
+
* @docGroup 1. Operation data
|
|
138
124
|
*/
|
|
139
125
|
error: ErrorLike | undefined;
|
|
140
126
|
/**
|
|
141
127
|
* A function that helps you fetch the next set of results for a [paginated list field](https://www.apollographql.com/docs/react/pagination/core-api/).
|
|
128
|
+
*
|
|
142
129
|
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
* 3. Helper functions
|
|
147
|
-
*
|
|
130
|
+
* @docGroup 3. Helper functions
|
|
131
|
+
*
|
|
148
132
|
*
|
|
149
133
|
* @remarks
|
|
150
134
|
* Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).
|
|
@@ -155,9 +139,7 @@ export declare namespace useSuspenseQuery {
|
|
|
155
139
|
*
|
|
156
140
|
* Used in conjunction with the [`notifyOnNetworkStatusChange`](#notifyonnetworkstatuschange) option.
|
|
157
141
|
*
|
|
158
|
-
* @docGroup
|
|
159
|
-
*
|
|
160
|
-
* 2. Network info
|
|
142
|
+
* @docGroup 2. Network info
|
|
161
143
|
*/
|
|
162
144
|
networkStatus: NetworkStatus;
|
|
163
145
|
/**
|
|
@@ -167,12 +149,12 @@ export declare namespace useSuspenseQuery {
|
|
|
167
149
|
*
|
|
168
150
|
* See also [Refetching](https://www.apollographql.com/docs/react/data/queries/#refetching).
|
|
169
151
|
*
|
|
170
|
-
* Returns a `ResultPromise` with an additional `.retain()` method. Calling
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* 3. Helper functions
|
|
152
|
+
* Returns a `ResultPromise` with an additional `.retain()` method. Calling
|
|
153
|
+
* `.retain()` keeps the network operation running even if the `ObservableQuery`
|
|
154
|
+
* no longer requires the result.
|
|
175
155
|
*
|
|
156
|
+
* @docGroup 3. Helper functions
|
|
157
|
+
*
|
|
176
158
|
*
|
|
177
159
|
* @remarks
|
|
178
160
|
* Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).
|
|
@@ -182,11 +164,9 @@ export declare namespace useSuspenseQuery {
|
|
|
182
164
|
* A function that enables you to execute a [subscription](https://www.apollographql.com/docs/react/data/subscriptions/), usually to subscribe to specific fields that were included in the query.
|
|
183
165
|
*
|
|
184
166
|
* This function returns _another_ function that you can call to terminate the subscription.
|
|
167
|
+
*
|
|
185
168
|
*
|
|
186
|
-
*
|
|
187
|
-
* @docGroup
|
|
188
|
-
*
|
|
189
|
-
* 3. Helper functions
|
|
169
|
+
* @docGroup 3. Helper functions
|
|
190
170
|
*/
|
|
191
171
|
subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;
|
|
192
172
|
}
|
|
@@ -200,13 +180,11 @@ export declare namespace useSuspenseQuery {
|
|
|
200
180
|
}
|
|
201
181
|
namespace DocumentationTypes {
|
|
202
182
|
/**
|
|
203
|
-
* Test
|
|
204
|
-
*
|
|
205
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
206
|
-
*
|
|
207
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
183
|
+
* Test
|
|
184
|
+
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
208
185
|
*
|
|
209
186
|
* @example
|
|
187
|
+
*
|
|
210
188
|
* ```jsx
|
|
211
189
|
* import { Suspense } from "react";
|
|
212
190
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -239,6 +217,9 @@ export declare namespace useSuspenseQuery {
|
|
|
239
217
|
* );
|
|
240
218
|
* }
|
|
241
219
|
* ```
|
|
220
|
+
*
|
|
221
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
222
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
242
223
|
*/
|
|
243
224
|
function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useSuspenseQuery.Options<TVariables>): useSuspenseQuery.Result<TData, TVariables>;
|
|
244
225
|
}
|
|
@@ -291,11 +272,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
291
272
|
/**
|
|
292
273
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
293
274
|
*
|
|
294
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
295
|
-
*
|
|
296
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
297
|
-
*
|
|
298
275
|
* @example
|
|
276
|
+
*
|
|
299
277
|
* ```jsx
|
|
300
278
|
* import { Suspense } from "react";
|
|
301
279
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -328,6 +306,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
328
306
|
* );
|
|
329
307
|
* }
|
|
330
308
|
* ```
|
|
309
|
+
*
|
|
310
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
311
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
331
312
|
*/
|
|
332
313
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useSuspenseQuery.Options<NoInfer<TVariables>> & {
|
|
333
314
|
errorPolicy: "ignore" | "all";
|
|
@@ -335,11 +316,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
335
316
|
/**
|
|
336
317
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
337
318
|
*
|
|
338
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
339
|
-
*
|
|
340
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
341
|
-
*
|
|
342
319
|
* @example
|
|
320
|
+
*
|
|
343
321
|
* ```jsx
|
|
344
322
|
* import { Suspense } from "react";
|
|
345
323
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -372,6 +350,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
372
350
|
* );
|
|
373
351
|
* }
|
|
374
352
|
* ```
|
|
353
|
+
*
|
|
354
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
355
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
375
356
|
*/
|
|
376
357
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useSuspenseQuery.Options<NoInfer<TVariables>> & {
|
|
377
358
|
skip: boolean;
|
|
@@ -380,11 +361,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
380
361
|
/**
|
|
381
362
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
382
363
|
*
|
|
383
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
384
|
-
*
|
|
385
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
386
|
-
*
|
|
387
364
|
* @example
|
|
365
|
+
*
|
|
388
366
|
* ```jsx
|
|
389
367
|
* import { Suspense } from "react";
|
|
390
368
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -417,6 +395,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
417
395
|
* );
|
|
418
396
|
* }
|
|
419
397
|
* ```
|
|
398
|
+
*
|
|
399
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
400
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
420
401
|
*/
|
|
421
402
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useSuspenseQuery.Options<NoInfer<TVariables>> & {
|
|
422
403
|
returnPartialData: true;
|
|
@@ -424,11 +405,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
424
405
|
/**
|
|
425
406
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
426
407
|
*
|
|
427
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
428
|
-
*
|
|
429
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
430
|
-
*
|
|
431
408
|
* @example
|
|
409
|
+
*
|
|
432
410
|
* ```jsx
|
|
433
411
|
* import { Suspense } from "react";
|
|
434
412
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -461,6 +439,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
461
439
|
* );
|
|
462
440
|
* }
|
|
463
441
|
* ```
|
|
442
|
+
*
|
|
443
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
444
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
464
445
|
*/
|
|
465
446
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useSuspenseQuery.Options<NoInfer<TVariables>> & {
|
|
466
447
|
skip: boolean;
|
|
@@ -468,11 +449,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
468
449
|
/**
|
|
469
450
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
470
451
|
*
|
|
471
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
472
|
-
*
|
|
473
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
474
|
-
*
|
|
475
452
|
* @example
|
|
453
|
+
*
|
|
476
454
|
* ```jsx
|
|
477
455
|
* import { Suspense } from "react";
|
|
478
456
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -505,6 +483,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
505
483
|
* );
|
|
506
484
|
* }
|
|
507
485
|
* ```
|
|
486
|
+
*
|
|
487
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
488
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
508
489
|
*/
|
|
509
490
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useSuspenseQuery.Options<NoInfer<TVariables>> & {
|
|
510
491
|
returnPartialData: true;
|
|
@@ -512,11 +493,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
512
493
|
/**
|
|
513
494
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
514
495
|
*
|
|
515
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
516
|
-
*
|
|
517
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
518
|
-
*
|
|
519
496
|
* @example
|
|
497
|
+
*
|
|
520
498
|
* ```jsx
|
|
521
499
|
* import { Suspense } from "react";
|
|
522
500
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -549,6 +527,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
549
527
|
* );
|
|
550
528
|
* }
|
|
551
529
|
* ```
|
|
530
|
+
*
|
|
531
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
532
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
552
533
|
*/
|
|
553
534
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
554
535
|
options?: useSuspenseQuery.Options<NoInfer<TVariables>>
|
|
@@ -556,11 +537,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
556
537
|
/**
|
|
557
538
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
558
539
|
*
|
|
559
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
560
|
-
*
|
|
561
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
562
|
-
*
|
|
563
540
|
* @example
|
|
541
|
+
*
|
|
564
542
|
* ```jsx
|
|
565
543
|
* import { Suspense } from "react";
|
|
566
544
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -593,6 +571,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
593
571
|
* );
|
|
594
572
|
* }
|
|
595
573
|
* ```
|
|
574
|
+
*
|
|
575
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
576
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
596
577
|
*/
|
|
597
578
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
598
579
|
options?: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>
|
|
@@ -600,11 +581,8 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
600
581
|
/**
|
|
601
582
|
* For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).
|
|
602
583
|
*
|
|
603
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
604
|
-
*
|
|
605
|
-
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
606
|
-
*
|
|
607
584
|
* @example
|
|
585
|
+
*
|
|
608
586
|
* ```jsx
|
|
609
587
|
* import { Suspense } from "react";
|
|
610
588
|
* import { useSuspenseQuery } from "@apollo/client";
|
|
@@ -637,6 +615,9 @@ export declare function useSuspenseQuery<TData = unknown, TVariables extends Ope
|
|
|
637
615
|
* );
|
|
638
616
|
* }
|
|
639
617
|
* ```
|
|
618
|
+
*
|
|
619
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
620
|
+
* @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.
|
|
640
621
|
*/
|
|
641
622
|
export declare function useSuspenseQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>): useSuspenseQuery.Result<TData, TVariables, "complete" | "streaming" | "empty">;
|
|
642
623
|
interface UseWatchQueryOptionsHookOptions<TData, TVariables extends OperationVariables> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAE,MAAM,sCAAsC,CAAC;AAQ/D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,2BAA2B,EAAE,MAAM,2CAA2C,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA2SvD,MAAM,UAAU,gBAAgB,CAI9B,KAA0D,EAC1D,OAAmE;IAMnE,aAAa,CAAC;IACd,OAAO,QAAQ,CACb,kBAAkB;IAClB,yDAAyD;IACzD,iBAAiB,EACjB,eAAe,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAC1E,CAAC,KAAK,EAAE,OAAO,IAAK,EAAU,CA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c,CAAC,UAAU,EAAE,WAAW;YAC7C,aAAa,CAAC;QAEhB,MAAM,iBAAiB,GACrB;YACE,GAAG,OAAO;YACV,WAAW;YACX,KAAK;YACL,2BAA2B,EAAE,KAAK;YAClC,eAAe,EAAE,KAAK,CAAC;SACxB,CAAC;QAEJ,IAAI,OAAO,EAAE,CAAC;YACZ,2BAA2B,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,0EAA0E;QAC1E,qEAAqE;QACrE,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,iBAAiB,CAAC,WAAW,GAAG,SAAS,CAAC;QAC5C,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n GetDataState,\n MaybeMasked,\n ObservableQuery,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport { NetworkStatus } from \"@apollo/client\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type {\n CacheKey,\n FetchMoreFunction,\n QueryKey,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { skipToken } from \"./constants.js\";\nimport { __use, useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { validateSuspenseHookOptions } from \"./internal/validateSuspenseHookOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport declare namespace useSuspenseQuery {\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useSuspenseQuery } from \"@apollo/client\";\n *\n * const { data } = useSuspenseQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options<TVariables> & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useSuspenseQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export namespace Base {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#fetchMore:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#networkStatus:member} */\n networkStatus: NetworkStatus;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#subscribeToMore:member} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n }\n }\n export type Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends\n DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n > = Base.Result<TData, TVariables> &\n GetDataState<MaybeMasked<TData>, TStates>;\n\n export namespace DocumentationTypes {\n namespace useSuspenseQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Result<TData, TVariables>,\n UtilityDocumentationTypes.DataState<TData> {}\n }\n }\n export namespace DocumentationTypes {\n /** Test {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\n export function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useSuspenseQuery.Options<TVariables>\n ): useSuspenseQuery.Result<TData, TVariables>;\n }\n}\n\n/**\n * For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { useSuspenseQuery } from \"@apollo/client\";\n *\n * const listQuery = gql`\n * query {\n * list {\n * id\n * }\n * }\n * `;\n *\n * function App() {\n * return (\n * <Suspense fallback={<Spinner />}>\n * <List />\n * </Suspense>\n * );\n * }\n *\n * function List() {\n * const { data } = useSuspenseQuery(listQuery);\n *\n * return (\n * <ol>\n * {data.list.map((item) => (\n * <Item key={item.id} id={item.id} />\n * ))}\n * </ol>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.\n */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"partial\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: true;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"empty\" | \"streaming\" | \"partial\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"partial\" | \"streaming\" | \"complete\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n })\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"empty\" | \"streaming\" | \"complete\" | \"partial\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useSuspenseQuery.Options<NoInfer<TVariables>>]\n : [options: useSuspenseQuery.Options<NoInfer<TVariables>>]\n): useSuspenseQuery.Result<TData, TVariables, \"complete\" | \"streaming\">;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>]\n : [options: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>]\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"empty\" | \"streaming\" | \"complete\" | \"partial\"\n> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useSuspenseQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n}\n\nfunction useSuspenseQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useSuspenseQuery.Options<TVariables>>)\n | useSuspenseQuery.Options<TVariables>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"partial\" | \"complete\" | \"streaming\" | \"empty\"\n> {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions<any, any>({\n client,\n query,\n options,\n });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions)\n );\n\n let [current, setPromise] = React.useState<\n [QueryKey, Promise<ObservableQuery.Result<any>>]\n >([queryRef.key, queryRef.promise]);\n\n // This saves us a re-execution of the render function when a variable changed.\n if (current[0] !== queryRef.key) {\n // eslint-disable-next-line react-compiler/react-compiler\n current[0] = queryRef.key;\n current[1] = queryRef.promise;\n }\n let promise = current[1];\n\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n current[1] = promise = queryRef.applyOptions(watchQueryOptions);\n }\n\n React.useEffect(() => {\n const dispose = queryRef.retain();\n\n const removeListener = queryRef.listen((promise) => {\n setPromise([queryRef.key, promise]);\n });\n\n return () => {\n removeListener();\n dispose();\n };\n }, [queryRef]);\n\n const skipResult = React.useMemo<ObservableQuery.Result<TData>>(() => {\n const error = queryRef.result.error;\n const complete = !!queryRef.result.data;\n\n return {\n loading: false,\n data: queryRef.result.data,\n dataState: queryRef.result.dataState,\n networkStatus: error ? NetworkStatus.error : NetworkStatus.ready,\n error,\n complete,\n partial: !complete,\n };\n }, [queryRef.result]);\n\n const result = fetchPolicy === \"standby\" ? skipResult : __use(promise);\n\n const fetchMore = React.useCallback<\n FetchMoreFunction<unknown, OperationVariables>\n >(\n (options) => {\n const promise = queryRef.fetchMore(options);\n setPromise([queryRef.key, queryRef.promise]);\n\n return promise;\n },\n [queryRef]\n ) as FetchMoreFunction<TData | undefined, TVariables>;\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n setPromise([queryRef.key, queryRef.promise]);\n\n return promise;\n },\n [queryRef]\n );\n\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n const subscribeToMore = queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData | undefined, TVariables>;\n\n return React.useMemo<\n useSuspenseQuery.Result<TData, TVariables, DataState<TData>[\"dataState\"]>\n >(() => {\n return {\n client,\n data: result.data,\n dataState: result.dataState,\n error: result.error,\n networkStatus: result.networkStatus,\n fetchMore,\n refetch,\n subscribeToMore,\n } as useSuspenseQuery.Result<\n TData,\n TVariables,\n DataState<TData>[\"dataState\"]\n >;\n }, [client, fetchMore, refetch, result, subscribeToMore]);\n}\n\ninterface UseWatchQueryOptionsHookOptions<\n TData,\n TVariables extends OperationVariables,\n> {\n client: ApolloClient;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n options: SkipToken | useSuspenseQuery.Options<TVariables>;\n}\n\nexport function useWatchQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>({\n client,\n query,\n options,\n}: UseWatchQueryOptionsHookOptions<\n TData,\n TVariables\n>): ApolloClient.WatchQueryOptions<TData, TVariables> {\n return useDeepMemo<ApolloClient.WatchQueryOptions<TData, TVariables>>(() => {\n if (options === skipToken) {\n return {\n query,\n fetchPolicy: \"standby\",\n } as ApolloClient.WatchQueryOptions<TData, TVariables>;\n }\n\n const fetchPolicy =\n options.fetchPolicy ||\n client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\";\n\n const watchQueryOptions: ApolloClient.WatchQueryOptions<TData, TVariables> =\n {\n ...options,\n fetchPolicy,\n query,\n notifyOnNetworkStatusChange: false,\n nextFetchPolicy: void 0,\n };\n\n if (__DEV__) {\n validateSuspenseHookOptions(watchQueryOptions);\n }\n\n // Assign the updated fetch policy after our validation since `standby` is\n // not a supported fetch policy on its own without the use of `skip`.\n if (options.skip) {\n watchQueryOptions.fetchPolicy = \"standby\";\n }\n\n return watchQueryOptions;\n }, [client, options, query]);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useSuspenseQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseQuery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkB/B,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B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,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,SAAS,EAAE,MAAM,CAAC,SAAS;YAC3B,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,aAAa,EAAE,MAAM,CAAC,aAAa;YACnC,SAAS;YACT,OAAO;YACP,eAAe;SAKhB,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;AAC5D,CAAC;AAWD,MAAM,UAAU,oBAAoB,CAGlC,EACA,MAAM,EACN,KAAK,EACL,OAAO,GAIR;IACC,OAAO,WAAW,CAAoD,GAAG,EAAE;QACzE,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,OAAO;gBACL,KAAK;gBACL,WAAW,EAAE,SAAS;aAC8B,CAAC;QACzD,CAAC;QAED,MAAM,WAAW,GACf,OAAO,CAAC,WAAW;YACnB,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW;YAC7C,aAAa,CAAC;QAEhB,MAAM,iBAAiB,GACrB;YACE,GAAG,OAAO;YACV,WAAW;YACX,KAAK;YACL,2BAA2B,EAAE,KAAK;YAClC,eAAe,EAAE,KAAK,CAAC;SACxB,CAAC;QAEJ,IAAI,OAAO,EAAE,CAAC;YACZ,2BAA2B,CAAC,iBAAiB,CAAC,CAAC;QACjD,CAAC;QAED,0EAA0E;QAC1E,qEAAqE;QACrE,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,iBAAiB,CAAC,WAAW,GAAG,SAAS,CAAC;QAC5C,CAAC;QAED,OAAO,iBAAiB,CAAC;IAC3B,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n GetDataState,\n MaybeMasked,\n ObservableQuery,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport { NetworkStatus } from \"@apollo/client\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type {\n CacheKey,\n FetchMoreFunction,\n QueryKey,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport { __DEV__ } from \"@apollo/client/utilities/environment\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { skipToken } from \"./constants.js\";\nimport { __use, useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { validateSuspenseHookOptions } from \"./internal/validateSuspenseHookOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport declare namespace useSuspenseQuery {\n export type FetchPolicy = Extract<\n WatchQueryFetchPolicy,\n \"cache-first\" | \"network-only\" | \"no-cache\" | \"cache-and-network\"\n >;\n\n export namespace Base {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: FetchPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#queryKey:member} */\n queryKey?: string | number | any[];\n\n /**\n * {@inheritDoc @apollo/client!QueryOptionsDocumentation#skip_deprecated:member}\n *\n * @example Recommended usage of `skipToken`:\n *\n * ```ts\n * import { skipToken, useSuspenseQuery } from \"@apollo/client\";\n *\n * const { data } = useSuspenseQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options<TVariables> & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useSuspenseQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export namespace Base {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#fetchMore:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#networkStatus:member} */\n networkStatus: NetworkStatus;\n\n /**\n * {@inheritDoc @apollo/client!QueryResultDocumentation#refetch:member}\n *\n * @remarks\n * Calling this function will cause the component to re-suspend, unless the call site is wrapped in [`startTransition`](https://react.dev/reference/react/startTransition).\n */\n refetch: RefetchFunction<TData, TVariables>;\n\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#subscribeToMore:member} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n }\n }\n export type Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends\n DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n > = Base.Result<TData, TVariables> &\n GetDataState<MaybeMasked<TData>, TStates>;\n\n export namespace DocumentationTypes {\n namespace useSuspenseQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Result<TData, TVariables>,\n UtilityDocumentationTypes.DataState<TData> {}\n }\n }\n export namespace DocumentationTypes {\n /** Test {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\n export function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useSuspenseQuery.Options<TVariables>\n ): useSuspenseQuery.Result<TData, TVariables>;\n }\n}\n\n/**\n * For a detailed explanation of `useSuspenseQuery`, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { useSuspenseQuery } from \"@apollo/client\";\n *\n * const listQuery = gql`\n * query {\n * list {\n * id\n * }\n * }\n * `;\n *\n * function App() {\n * return (\n * <Suspense fallback={<Spinner />}>\n * <List />\n * </Suspense>\n * );\n * }\n *\n * function List() {\n * const { data } = useSuspenseQuery(listQuery);\n *\n * return (\n * <ol>\n * {data.list.map((item) => (\n * <Item key={item.id} id={item.id} />\n * ))}\n * </ol>\n * );\n * }\n * ```\n *\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - An optional object containing options for the query. Instead of passing a `useSuspenseQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useSuspenseQuery` hook from executing the query or suspending.\n */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"partial\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: true;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"empty\" | \"streaming\" | \"partial\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"partial\" | \"streaming\" | \"complete\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useSuspenseQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useSuspenseQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: true;\n })\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"empty\" | \"streaming\" | \"complete\" | \"partial\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useSuspenseQuery.Options<NoInfer<TVariables>>]\n : [options: useSuspenseQuery.Options<NoInfer<TVariables>>]\n): useSuspenseQuery.Result<TData, TVariables, \"complete\" | \"streaming\">;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>]\n : [options: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>]\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseQuery:function(1)} */\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"empty\"\n>;\n\nexport function useSuspenseQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useSuspenseQuery.Options<NoInfer<TVariables>>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"empty\" | \"streaming\" | \"complete\" | \"partial\"\n> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useSuspenseQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n}\n\nfunction useSuspenseQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useSuspenseQuery.Options<TVariables>>)\n | useSuspenseQuery.Options<TVariables>\n): useSuspenseQuery.Result<\n TData,\n TVariables,\n \"partial\" | \"complete\" | \"streaming\" | \"empty\"\n> {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions<any, any>({\n client,\n query,\n options,\n });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions)\n );\n\n let [current, setPromise] = React.useState<\n [QueryKey, Promise<ObservableQuery.Result<any>>]\n >([queryRef.key, queryRef.promise]);\n\n // This saves us a re-execution of the render function when a variable changed.\n if (current[0] !== queryRef.key) {\n // eslint-disable-next-line react-compiler/react-compiler\n current[0] = queryRef.key;\n current[1] = queryRef.promise;\n }\n let promise = current[1];\n\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n current[1] = promise = queryRef.applyOptions(watchQueryOptions);\n }\n\n React.useEffect(() => {\n const dispose = queryRef.retain();\n\n const removeListener = queryRef.listen((promise) => {\n setPromise([queryRef.key, promise]);\n });\n\n return () => {\n removeListener();\n dispose();\n };\n }, [queryRef]);\n\n const skipResult = React.useMemo<ObservableQuery.Result<TData>>(() => {\n const error = queryRef.result.error;\n const complete = !!queryRef.result.data;\n\n return {\n loading: false,\n data: queryRef.result.data,\n dataState: queryRef.result.dataState,\n networkStatus: error ? NetworkStatus.error : NetworkStatus.ready,\n error,\n complete,\n partial: !complete,\n };\n }, [queryRef.result]);\n\n const result = fetchPolicy === \"standby\" ? skipResult : __use(promise);\n\n const fetchMore = React.useCallback<\n FetchMoreFunction<unknown, OperationVariables>\n >(\n (options) => {\n const promise = queryRef.fetchMore(options);\n setPromise([queryRef.key, queryRef.promise]);\n\n return promise;\n },\n [queryRef]\n ) as FetchMoreFunction<TData | undefined, TVariables>;\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n setPromise([queryRef.key, queryRef.promise]);\n\n return promise;\n },\n [queryRef]\n );\n\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n const subscribeToMore = queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData | undefined, TVariables>;\n\n return React.useMemo<\n useSuspenseQuery.Result<TData, TVariables, DataState<TData>[\"dataState\"]>\n >(() => {\n return {\n client,\n data: result.data,\n dataState: result.dataState,\n error: result.error,\n networkStatus: result.networkStatus,\n fetchMore,\n refetch,\n subscribeToMore,\n } as useSuspenseQuery.Result<\n TData,\n TVariables,\n DataState<TData>[\"dataState\"]\n >;\n }, [client, fetchMore, refetch, result, subscribeToMore]);\n}\n\ninterface UseWatchQueryOptionsHookOptions<\n TData,\n TVariables extends OperationVariables,\n> {\n client: ApolloClient;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n options: SkipToken | useSuspenseQuery.Options<TVariables>;\n}\n\nexport function useWatchQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>({\n client,\n query,\n options,\n}: UseWatchQueryOptionsHookOptions<\n TData,\n TVariables\n>): ApolloClient.WatchQueryOptions<TData, TVariables> {\n return useDeepMemo<ApolloClient.WatchQueryOptions<TData, TVariables>>(() => {\n if (options === skipToken) {\n return {\n query,\n fetchPolicy: \"standby\",\n } as ApolloClient.WatchQueryOptions<TData, TVariables>;\n }\n\n const fetchPolicy =\n options.fetchPolicy ||\n client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\";\n\n const watchQueryOptions: ApolloClient.WatchQueryOptions<TData, TVariables> =\n {\n ...options,\n fetchPolicy,\n query,\n notifyOnNetworkStatusChange: false,\n nextFetchPolicy: void 0,\n };\n\n if (__DEV__) {\n validateSuspenseHookOptions(watchQueryOptions);\n }\n\n // Assign the updated fetch policy after our validation since `standby` is\n // not a supported fetch policy on its own without the use of `skip`.\n if (options.skip) {\n watchQueryOptions.fetchPolicy = \"standby\";\n }\n\n return watchQueryOptions;\n }, [client, options, query]);\n}\n"]}
|