@apollo/client 4.2.0-alpha.1 → 4.2.0-alpha.3
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 +209 -0
- package/__cjs/core/ApolloClient.cjs +25 -12
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +305 -146
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/defaultOptions.cjs +3 -0
- package/__cjs/core/defaultOptions.cjs.map +1 -0
- package/__cjs/core/defaultOptions.d.cts +90 -0
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -1
- package/__cjs/link/ws/index.cjs +9 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -3
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +1598 -765
- package/__cjs/react/hooks/useLazyQuery.cjs +3 -5
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +369 -115
- package/__cjs/react/hooks/useLoadableQuery.cjs +8 -4
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +507 -192
- package/__cjs/react/hooks/useMutation.cjs +5 -48
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +239 -130
- package/__cjs/react/hooks/useQuery.cjs +5 -5
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +636 -276
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +2 -2
- package/__cjs/react/hooks/useSuspenseQuery.cjs +3 -3
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +799 -399
- package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/getSuspenseCache.d.cts +7 -0
- package/__cjs/utilities/internal/LazyType.cjs +3 -0
- package/__cjs/utilities/internal/LazyType.cjs.map +1 -0
- package/__cjs/utilities/internal/LazyType.d.cts +10 -0
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs.map +1 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.d.cts +5 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs +3 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs.map +1 -0
- package/__cjs/utilities/internal/types/SignatureStyle.d.cts +24 -0
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +305 -146
- package/core/ApolloClient.js +25 -12
- package/core/ApolloClient.js.map +1 -1
- package/core/QueryManager.js.map +1 -1
- package/core/defaultOptions.d.ts +90 -0
- package/core/defaultOptions.js +2 -0
- package/core/defaultOptions.js.map +1 -0
- package/core/index.d.ts +2 -1
- package/core/index.js.map +1 -1
- package/link/ws/index.d.ts +1 -1
- package/link/ws/index.js +9 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +3 -7
- package/react/hooks/useBackgroundQuery.d.ts +1598 -765
- package/react/hooks/useBackgroundQuery.js +2 -2
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +369 -115
- package/react/hooks/useLazyQuery.js +2 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +507 -192
- package/react/hooks/useLoadableQuery.js +7 -3
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +239 -130
- package/react/hooks/useMutation.js +5 -48
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +636 -276
- package/react/hooks/useQuery.js +2 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +799 -399
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1598 -765
- package/react/hooks-compiled/useBackgroundQuery.js +2 -2
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +369 -115
- package/react/hooks-compiled/useLazyQuery.js +2 -4
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +507 -192
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +239 -130
- package/react/hooks-compiled/useMutation.js +4 -47
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +636 -276
- package/react/hooks-compiled/useQuery.js +2 -2
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +2 -2
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +799 -399
- package/react/hooks-compiled/useSuspenseQuery.js +2 -2
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/getSuspenseCache.d.ts +7 -0
- package/react/internal/cache/getSuspenseCache.js.map +1 -1
- package/skills/apollo-client/SKILL.md +168 -0
- package/skills/apollo-client/references/caching.md +560 -0
- package/skills/apollo-client/references/error-handling.md +350 -0
- package/skills/apollo-client/references/fragments.md +804 -0
- package/skills/apollo-client/references/integration-client.md +336 -0
- package/skills/apollo-client/references/integration-nextjs.md +325 -0
- package/skills/apollo-client/references/integration-react-router.md +256 -0
- package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
- package/skills/apollo-client/references/mutations.md +549 -0
- package/skills/apollo-client/references/queries.md +416 -0
- package/skills/apollo-client/references/state-management.md +428 -0
- package/skills/apollo-client/references/suspense-hooks.md +773 -0
- package/skills/apollo-client/references/troubleshooting.md +487 -0
- package/skills/apollo-client/references/typescript-codegen.md +133 -0
- package/utilities/internal/LazyType.d.ts +10 -0
- package/utilities/internal/LazyType.js +2 -0
- package/utilities/internal/LazyType.js.map +1 -0
- package/utilities/internal/index.d.ts +3 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/types/OptionWithFallback.d.ts +5 -0
- package/utilities/internal/types/OptionWithFallback.js +2 -0
- package/utilities/internal/types/OptionWithFallback.js.map +1 -0
- package/utilities/internal/types/SignatureStyle.d.ts +24 -0
- package/utilities/internal/types/SignatureStyle.js +2 -0
- package/utilities/internal/types/SignatureStyle.js.map +1 -0
- package/version.js +1 -1
|
@@ -3,10 +3,10 @@ import { getSuspenseCache, unwrapQueryRef, updateWrappedQueryRef, wrapQueryRef,
|
|
|
3
3
|
import { useSuspenseHookCacheKey, wrapHook } from "./internal/index.js";
|
|
4
4
|
import { useApolloClient } from "./useApolloClient.js";
|
|
5
5
|
import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
6
|
-
export function useBackgroundQuery(query, options) {
|
|
6
|
+
export const useBackgroundQuery = function useBackgroundQuery(query, options) {
|
|
7
7
|
"use no memo";
|
|
8
8
|
return wrapHook("useBackgroundQuery", useBackgroundQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options ?? {});
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
function useBackgroundQuery_(query, options) {
|
|
11
11
|
const client = useApolloClient(options.client);
|
|
12
12
|
const suspenseCache = getSuspenseCache(client);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { useSuspenseHookCacheKey, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\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 /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\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, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\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 /**\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\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\n export function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n}\n\n/**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\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 `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n/** {@inheritDoc @apollo/client/react!useBackgroundQuery:function(1)} */\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy } = watchQueryOptions;\n const cacheKey = useSuspenseHookCacheKey(query, options);\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":"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","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataState,\n DefaultContext,\n DocumentNode,\n ErrorPolicy,\n OperationVariables,\n RefetchWritePolicy,\n TypedDocumentNode,\n WatchQueryFetchPolicy,\n} from \"@apollo/client\";\nimport type { SubscribeToMoreFunction } from \"@apollo/client\";\nimport type { QueryRef } from \"@apollo/client/react\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n} from \"@apollo/client/react/internal\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n OptionWithFallback,\n SignatureStyle,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport type { SkipToken } from \"./constants.js\";\nimport { useSuspenseHookCacheKey, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\n\nexport declare namespace useBackgroundQuery {\n import _self = useBackgroundQuery;\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 /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#refetchWritePolicy_suspense:member} */\n refetchWritePolicy?: RefetchWritePolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!QueryOptionsDocumentation#returnPartialData:member} */\n returnPartialData?: boolean;\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, useBackgroundQuery } from \"@apollo/client\";\n *\n * const [queryRef] = useBackgroundQuery(\n * query,\n * id ? { variables: { id } } : skipToken\n * );\n * ```\n */\n skip?: boolean;\n }\n }\n\n export type Options<\n TVariables extends OperationVariables = OperationVariables,\n > = Base.Options & VariablesOption<TVariables>;\n\n export namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Options<\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n\n /**\n * {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)}\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 /**\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\n namespace DocumentationTypes {\n namespace useBackgroundQuery {\n export interface Result<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Result<TData, TVariables> {}\n }\n }\n\n export interface DefaultOptions\n extends ApolloClient.DefaultOptions.WatchQuery.Calculated {\n skip: false;\n }\n\n export type ResultForOptions<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Record<string, never> | Options<TVariables> | SkipToken,\n > = [\n queryRef: TOptions extends any ?\n TOptions extends SkipToken ?\n undefined\n : | QueryRef<\n TData,\n TVariables,\n | \"complete\"\n | \"streaming\"\n | (\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"errorPolicy\"\n > extends \"none\" ?\n never\n : \"empty\")\n | (OptionWithFallback<\n TOptions,\n DefaultOptions,\n \"returnPartialData\"\n > extends false ?\n never\n : \"partial\")\n )\n >\n | (OptionWithFallback<TOptions, DefaultOptions, \"skip\"> extends false ?\n never\n : undefined)\n : never,\n result: useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n export namespace DocumentationTypes {\n export interface useBackgroundQuery {\n /**\n * For a detailed explanation of useBackgroundQuery, see the [fetching with Suspense reference](https://www.apollographql.com/docs/react/data/suspense).\n *\n * @returns A tuple containing:\n *\n * 1. A `QueryRef` that can be passed to `useReadQuery` to read the query result. The `queryRef` is `undefined` if the query is skipped.\n * 2. An object containing helper functions for the query:\n * - `refetch`: A function to re-execute the query\n * - `fetchMore`: A function to fetch more results for pagination\n * - `subscribeToMore`: A function to subscribe to updates\n *\n * @example\n *\n * ```jsx\n * import { Suspense } from \"react\";\n * import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\";\n * import { useBackgroundQuery, useReadQuery } from \"@apollo/client/react\";\n *\n * const query = gql`\n * foo {\n * bar\n * }\n * `;\n *\n * const client = new ApolloClient({\n * link: new HttpLink({ uri: \"http://localhost:4000/graphql\" }),\n * cache: new InMemoryCache(),\n * });\n *\n * function SuspenseFallback() {\n * return <div>Loading...</div>;\n * }\n *\n * function Child({ queryRef }) {\n * const { data } = useReadQuery(queryRef);\n *\n * return <div>{data.foo.bar}</div>;\n * }\n *\n * function Parent() {\n * const [queryRef] = useBackgroundQuery(query);\n *\n * return (\n * <Suspense fallback={<SuspenseFallback />}>\n * <Child queryRef={queryRef} />\n * </Suspense>\n * );\n * }\n *\n * function App() {\n * return (\n * <ApolloProvider client={client}>\n * <Parent />\n * </ApolloProvider>\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 `useBackgroundQuery.Options` object into the hook, you can also pass a [`skipToken`](#skiptoken) to prevent the `useBackgroundQuery` hook from executing the query or suspending.\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n export interface useBackgroundQuery_Deprecated {\n /**\n * @deprecated Avoid manually specifying generics on `useBackgroundQuery`.\n * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.\n *\n * {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)}\n */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<TVariables>\n ): [\n QueryRef<TData, TVariables> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n }\n\n export namespace Signatures {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n export interface Classic {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n /** @deprecated `returnPartialData` has no effect on `no-cache` queries */\n returnPartialData: boolean;\n fetchPolicy: \"no-cache\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<\n TData,\n TVariables,\n \"complete\" | \"streaming\" | \"partial\" | \"empty\"\n >,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"empty\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n returnPartialData: boolean;\n }\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: useBackgroundQuery.Options<NoInfer<TVariables>> & {\n skip: boolean;\n }\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n ): [undefined, useBackgroundQuery.Result<TData, TVariables>];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: false;\n })\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (useBackgroundQuery.Options<NoInfer<TVariables>> & {\n returnPartialData: boolean;\n })\n ): [\n (\n | QueryRef<TData, TVariables, \"complete\" | \"streaming\" | \"partial\">\n | undefined\n ),\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [options?: useBackgroundQuery.Options<NoInfer<TVariables>>]\n : [options: useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\">,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ?\n [\n options?:\n | SkipToken\n | useBackgroundQuery.Options<NoInfer<TVariables>>,\n ]\n : [options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>]\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, \"complete\" | \"streaming\"> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ];\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Modern {\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: {} extends TVariables ?\n DocumentNode | TypedDocumentNode<TData, TVariables>\n : // this overload should only be accessible if all `TVariables` are optional\n never\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n Record<string, never>\n >;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n skipToken: SkipToken\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, SkipToken>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions]\n : [options: TOptions]\n ): useBackgroundQuery.ResultForOptions<TData, TVariables, TOptions>;\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useBackgroundQuery.Options<NoInfer<TVariables>> &\n VariablesOption<\n TVariables & {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n }\n >,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n ...[options]: {} extends TVariables ? [options?: TOptions | SkipToken]\n : [options: TOptions | SkipToken]\n ): useBackgroundQuery.ResultForOptions<\n TData,\n TVariables,\n TOptions | SkipToken\n >;\n }\n\n export type Evaluated = SignatureStyle extends \"classic\" ? Classic : Modern;\n }\n\n /** {@inheritDoc @apollo/client/react!useBackgroundQuery.DocumentationTypes.useBackgroundQuery:call(1)} */\n export interface Signature extends Signatures.Evaluated {}\n}\n\nexport const useBackgroundQuery: useBackgroundQuery.Signature =\n function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | useBackgroundQuery.Options<NoInfer<TVariables>>\n ): [\n QueryRef<TData, TVariables, DataState<TData>[\"dataState\"]> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n ] {\n \"use no memo\";\n return wrapHook(\n \"useBackgroundQuery\",\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options ?? ({} as any));\n } as any;\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TStates extends DataState<TData>[\"dataState\"] = DataState<TData>[\"dataState\"],\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken & Partial<useBackgroundQuery.Options<NoInfer<TVariables>>>)\n | useBackgroundQuery.Options<NoInfer<TVariables>>\n): [\n QueryRef<TData, TVariables, TStates> | undefined,\n useBackgroundQuery.Result<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy } = watchQueryOptions;\n const cacheKey = useSuspenseHookCacheKey(query, options);\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const queryRef = suspenseCache.getQueryRef<TData, TStates>(cacheKey, () =>\n client.watchQuery(\n watchQueryOptions as ApolloClient.WatchQueryOptions<any, any>\n )\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n // TODO: The internalQueryRef doesn't have TVariables' type information so we have to cast it here\n subscribeToMore: queryRef.observable\n .subscribeToMore as SubscribeToMoreFunction<TData, TVariables>,\n },\n ];\n}\n"]}
|
|
@@ -2,7 +2,7 @@ import type { TypedDocumentNode } from "@graphql-typed-document-node/core";
|
|
|
2
2
|
import type { DocumentNode } from "graphql";
|
|
3
3
|
import type { ApolloClient, DataState, DefaultContext, ErrorLike, ErrorPolicy, GetDataState, InternalTypes, MaybeMasked, ObservableQuery, OperationVariables, RefetchWritePolicy, SubscribeToMoreFunction, UpdateQueryMapFn, WatchQueryFetchPolicy } from "@apollo/client";
|
|
4
4
|
import { NetworkStatus } from "@apollo/client";
|
|
5
|
-
import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, VariablesOption } from "@apollo/client/utilities/internal";
|
|
5
|
+
import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, OptionWithFallback, SignatureStyle, VariablesOption } from "@apollo/client/utilities/internal";
|
|
6
6
|
export declare namespace useLazyQuery {
|
|
7
7
|
import _self = useLazyQuery;
|
|
8
8
|
interface Options<TData = unknown, TVariables extends OperationVariables = OperationVariables> {
|
|
@@ -279,11 +279,100 @@ export declare namespace useLazyQuery {
|
|
|
279
279
|
] : [options: useLazyQuery.ExecOptions<TVariables>]) => ObservableQuery.ResultPromise<ApolloClient.QueryResult<TData>>;
|
|
280
280
|
namespace DocumentationTypes {
|
|
281
281
|
namespace useLazyQuery {
|
|
282
|
-
export
|
|
282
|
+
export type { ResultTuple };
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
+
interface DefaultOptions extends ApolloClient.DefaultOptions.WatchQuery.Calculated {
|
|
286
|
+
}
|
|
287
|
+
type ResultForOptions<TData, TVariables extends OperationVariables, TOptions extends Record<string, never> | Options<TData, TVariables>> = ResultTuple<TData, TVariables, "complete" | "streaming" | "empty" | (OptionWithFallback<TOptions, DefaultOptions, "returnPartialData"> extends false ? never : "partial")>;
|
|
285
288
|
namespace DocumentationTypes {
|
|
289
|
+
interface useLazyQuery {
|
|
290
|
+
/**
|
|
291
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
292
|
+
*
|
|
293
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
*
|
|
297
|
+
* ```jsx
|
|
298
|
+
* import { gql } from "@apollo/client";
|
|
299
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
300
|
+
*
|
|
301
|
+
* const GET_GREETING = gql`
|
|
302
|
+
* query GetGreeting($language: String!) {
|
|
303
|
+
* greeting(language: $language) {
|
|
304
|
+
* message
|
|
305
|
+
* }
|
|
306
|
+
* }
|
|
307
|
+
* `;
|
|
308
|
+
*
|
|
309
|
+
* function Hello() {
|
|
310
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
311
|
+
* variables: { language: "english" },
|
|
312
|
+
* });
|
|
313
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
314
|
+
* if (!called) {
|
|
315
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
316
|
+
* }
|
|
317
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
322
|
+
* @param options - Default options to control how the query is executed.
|
|
323
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
324
|
+
*/
|
|
325
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
|
|
326
|
+
}
|
|
327
|
+
interface useLazyQuery_Deprecated {
|
|
328
|
+
/**
|
|
329
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
330
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
331
|
+
*
|
|
332
|
+
*
|
|
333
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
334
|
+
*
|
|
335
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
*
|
|
339
|
+
* ```jsx
|
|
340
|
+
* import { gql } from "@apollo/client";
|
|
341
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
342
|
+
*
|
|
343
|
+
* const GET_GREETING = gql`
|
|
344
|
+
* query GetGreeting($language: String!) {
|
|
345
|
+
* greeting(language: $language) {
|
|
346
|
+
* message
|
|
347
|
+
* }
|
|
348
|
+
* }
|
|
349
|
+
* `;
|
|
350
|
+
*
|
|
351
|
+
* function Hello() {
|
|
352
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
353
|
+
* variables: { language: "english" },
|
|
354
|
+
* });
|
|
355
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
356
|
+
* if (!called) {
|
|
357
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
358
|
+
* }
|
|
359
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
360
|
+
* }
|
|
361
|
+
* ```
|
|
362
|
+
*
|
|
363
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
364
|
+
* @param options - Default options to control how the query is executed.
|
|
365
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
366
|
+
*/
|
|
367
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<TData, TVariables>): useLazyQuery.ResultTuple<TData, TVariables>;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
namespace Signatures {
|
|
286
371
|
/**
|
|
372
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
373
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
374
|
+
*
|
|
375
|
+
*
|
|
287
376
|
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
288
377
|
*
|
|
289
378
|
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
@@ -318,119 +407,284 @@ export declare namespace useLazyQuery {
|
|
|
318
407
|
* @param options - Default options to control how the query is executed.
|
|
319
408
|
* @returns A tuple in the form of `[execute, result]`
|
|
320
409
|
*/
|
|
321
|
-
|
|
410
|
+
interface Classic {
|
|
411
|
+
/**
|
|
412
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
413
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
414
|
+
*
|
|
415
|
+
*
|
|
416
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
417
|
+
*
|
|
418
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
419
|
+
*
|
|
420
|
+
* @example
|
|
421
|
+
*
|
|
422
|
+
* ```jsx
|
|
423
|
+
* import { gql } from "@apollo/client";
|
|
424
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
425
|
+
*
|
|
426
|
+
* const GET_GREETING = gql`
|
|
427
|
+
* query GetGreeting($language: String!) {
|
|
428
|
+
* greeting(language: $language) {
|
|
429
|
+
* message
|
|
430
|
+
* }
|
|
431
|
+
* }
|
|
432
|
+
* `;
|
|
433
|
+
*
|
|
434
|
+
* function Hello() {
|
|
435
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
436
|
+
* variables: { language: "english" },
|
|
437
|
+
* });
|
|
438
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
439
|
+
* if (!called) {
|
|
440
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
441
|
+
* }
|
|
442
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
443
|
+
* }
|
|
444
|
+
* ```
|
|
445
|
+
*
|
|
446
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
447
|
+
* @param options - Default options to control how the query is executed.
|
|
448
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
449
|
+
*/
|
|
450
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
451
|
+
returnPartialData: true;
|
|
452
|
+
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
453
|
+
/**
|
|
454
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
455
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
456
|
+
*
|
|
457
|
+
*
|
|
458
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
459
|
+
*
|
|
460
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
461
|
+
*
|
|
462
|
+
* @example
|
|
463
|
+
*
|
|
464
|
+
* ```jsx
|
|
465
|
+
* import { gql } from "@apollo/client";
|
|
466
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
467
|
+
*
|
|
468
|
+
* const GET_GREETING = gql`
|
|
469
|
+
* query GetGreeting($language: String!) {
|
|
470
|
+
* greeting(language: $language) {
|
|
471
|
+
* message
|
|
472
|
+
* }
|
|
473
|
+
* }
|
|
474
|
+
* `;
|
|
475
|
+
*
|
|
476
|
+
* function Hello() {
|
|
477
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
478
|
+
* variables: { language: "english" },
|
|
479
|
+
* });
|
|
480
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
481
|
+
* if (!called) {
|
|
482
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
483
|
+
* }
|
|
484
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
485
|
+
* }
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
489
|
+
* @param options - Default options to control how the query is executed.
|
|
490
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
491
|
+
*/
|
|
492
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
493
|
+
returnPartialData: boolean;
|
|
494
|
+
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
495
|
+
/**
|
|
496
|
+
* @deprecated Avoid manually specifying generics on `useLazyQuery`.
|
|
497
|
+
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
498
|
+
*
|
|
499
|
+
*
|
|
500
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
501
|
+
*
|
|
502
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
*
|
|
506
|
+
* ```jsx
|
|
507
|
+
* import { gql } from "@apollo/client";
|
|
508
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
509
|
+
*
|
|
510
|
+
* const GET_GREETING = gql`
|
|
511
|
+
* query GetGreeting($language: String!) {
|
|
512
|
+
* greeting(language: $language) {
|
|
513
|
+
* message
|
|
514
|
+
* }
|
|
515
|
+
* }
|
|
516
|
+
* `;
|
|
517
|
+
*
|
|
518
|
+
* function Hello() {
|
|
519
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
520
|
+
* variables: { language: "english" },
|
|
521
|
+
* });
|
|
522
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
523
|
+
* if (!called) {
|
|
524
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
525
|
+
* }
|
|
526
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
527
|
+
* }
|
|
528
|
+
* ```
|
|
529
|
+
*
|
|
530
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
531
|
+
* @param options - Default options to control how the query is executed.
|
|
532
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
533
|
+
*/
|
|
534
|
+
<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>>): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
538
|
+
*
|
|
539
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
*
|
|
543
|
+
* ```jsx
|
|
544
|
+
* import { gql } from "@apollo/client";
|
|
545
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
546
|
+
*
|
|
547
|
+
* const GET_GREETING = gql`
|
|
548
|
+
* query GetGreeting($language: String!) {
|
|
549
|
+
* greeting(language: $language) {
|
|
550
|
+
* message
|
|
551
|
+
* }
|
|
552
|
+
* }
|
|
553
|
+
* `;
|
|
554
|
+
*
|
|
555
|
+
* function Hello() {
|
|
556
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
557
|
+
* variables: { language: "english" },
|
|
558
|
+
* });
|
|
559
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
560
|
+
* if (!called) {
|
|
561
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
562
|
+
* }
|
|
563
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*
|
|
567
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
568
|
+
* @param options - Default options to control how the query is executed.
|
|
569
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
570
|
+
*/
|
|
571
|
+
interface Modern {
|
|
572
|
+
/**
|
|
573
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
574
|
+
*
|
|
575
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
*
|
|
579
|
+
* ```jsx
|
|
580
|
+
* import { gql } from "@apollo/client";
|
|
581
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
582
|
+
*
|
|
583
|
+
* const GET_GREETING = gql`
|
|
584
|
+
* query GetGreeting($language: String!) {
|
|
585
|
+
* greeting(language: $language) {
|
|
586
|
+
* message
|
|
587
|
+
* }
|
|
588
|
+
* }
|
|
589
|
+
* `;
|
|
590
|
+
*
|
|
591
|
+
* function Hello() {
|
|
592
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
593
|
+
* variables: { language: "english" },
|
|
594
|
+
* });
|
|
595
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
596
|
+
* if (!called) {
|
|
597
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
598
|
+
* }
|
|
599
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
600
|
+
* }
|
|
601
|
+
* ```
|
|
602
|
+
*
|
|
603
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
604
|
+
* @param options - Default options to control how the query is executed.
|
|
605
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
606
|
+
*/
|
|
607
|
+
<TData, TVariables extends OperationVariables, TOptions extends never>(query: DocumentNode | TypedDocumentNode<TData, TVariables>): useLazyQuery.ResultForOptions<TData, TVariables, Record<string, never>>;
|
|
608
|
+
/**
|
|
609
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
610
|
+
*
|
|
611
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
612
|
+
*
|
|
613
|
+
* @example
|
|
614
|
+
*
|
|
615
|
+
* ```jsx
|
|
616
|
+
* import { gql } from "@apollo/client";
|
|
617
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
618
|
+
*
|
|
619
|
+
* const GET_GREETING = gql`
|
|
620
|
+
* query GetGreeting($language: String!) {
|
|
621
|
+
* greeting(language: $language) {
|
|
622
|
+
* message
|
|
623
|
+
* }
|
|
624
|
+
* }
|
|
625
|
+
* `;
|
|
626
|
+
*
|
|
627
|
+
* function Hello() {
|
|
628
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
629
|
+
* variables: { language: "english" },
|
|
630
|
+
* });
|
|
631
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
632
|
+
* if (!called) {
|
|
633
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
634
|
+
* }
|
|
635
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
636
|
+
* }
|
|
637
|
+
* ```
|
|
638
|
+
*
|
|
639
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
640
|
+
* @param options - Default options to control how the query is executed.
|
|
641
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
642
|
+
*/
|
|
643
|
+
<TData, TVariables extends OperationVariables, TOptions extends useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
644
|
+
variables?: {
|
|
645
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
646
|
+
};
|
|
647
|
+
}>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: TOptions): useLazyQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
648
|
+
}
|
|
649
|
+
type Evaluated = SignatureStyle extends "classic" ? Classic : Modern;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
653
|
+
*
|
|
654
|
+
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
655
|
+
*
|
|
656
|
+
* @example
|
|
657
|
+
*
|
|
658
|
+
* ```jsx
|
|
659
|
+
* import { gql } from "@apollo/client";
|
|
660
|
+
* import { useLazyQuery } from "@apollo/client/react";
|
|
661
|
+
*
|
|
662
|
+
* const GET_GREETING = gql`
|
|
663
|
+
* query GetGreeting($language: String!) {
|
|
664
|
+
* greeting(language: $language) {
|
|
665
|
+
* message
|
|
666
|
+
* }
|
|
667
|
+
* }
|
|
668
|
+
* `;
|
|
669
|
+
*
|
|
670
|
+
* function Hello() {
|
|
671
|
+
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
672
|
+
* variables: { language: "english" },
|
|
673
|
+
* });
|
|
674
|
+
* if (called && loading) return <p>Loading ...</p>;
|
|
675
|
+
* if (!called) {
|
|
676
|
+
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
677
|
+
* }
|
|
678
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
679
|
+
* }
|
|
680
|
+
* ```
|
|
681
|
+
*
|
|
682
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
683
|
+
* @param options - Default options to control how the query is executed.
|
|
684
|
+
* @returns A tuple in the form of `[execute, result]`
|
|
685
|
+
*/
|
|
686
|
+
interface Signature extends Signatures.Evaluated {
|
|
322
687
|
}
|
|
323
688
|
}
|
|
324
|
-
|
|
325
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
326
|
-
*
|
|
327
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
328
|
-
*
|
|
329
|
-
* @example
|
|
330
|
-
*
|
|
331
|
-
* ```jsx
|
|
332
|
-
* import { gql } from "@apollo/client";
|
|
333
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
334
|
-
*
|
|
335
|
-
* const GET_GREETING = gql`
|
|
336
|
-
* query GetGreeting($language: String!) {
|
|
337
|
-
* greeting(language: $language) {
|
|
338
|
-
* message
|
|
339
|
-
* }
|
|
340
|
-
* }
|
|
341
|
-
* `;
|
|
342
|
-
*
|
|
343
|
-
* function Hello() {
|
|
344
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
345
|
-
* variables: { language: "english" },
|
|
346
|
-
* });
|
|
347
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
348
|
-
* if (!called) {
|
|
349
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
350
|
-
* }
|
|
351
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
352
|
-
* }
|
|
353
|
-
* ```
|
|
354
|
-
*
|
|
355
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
356
|
-
* @param options - Default options to control how the query is executed.
|
|
357
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
358
|
-
*/
|
|
359
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
360
|
-
returnPartialData: true;
|
|
361
|
-
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
362
|
-
/**
|
|
363
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
364
|
-
*
|
|
365
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
366
|
-
*
|
|
367
|
-
* @example
|
|
368
|
-
*
|
|
369
|
-
* ```jsx
|
|
370
|
-
* import { gql } from "@apollo/client";
|
|
371
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
372
|
-
*
|
|
373
|
-
* const GET_GREETING = gql`
|
|
374
|
-
* query GetGreeting($language: String!) {
|
|
375
|
-
* greeting(language: $language) {
|
|
376
|
-
* message
|
|
377
|
-
* }
|
|
378
|
-
* }
|
|
379
|
-
* `;
|
|
380
|
-
*
|
|
381
|
-
* function Hello() {
|
|
382
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
383
|
-
* variables: { language: "english" },
|
|
384
|
-
* });
|
|
385
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
386
|
-
* if (!called) {
|
|
387
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
388
|
-
* }
|
|
389
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
390
|
-
* }
|
|
391
|
-
* ```
|
|
392
|
-
*
|
|
393
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
394
|
-
* @param options - Default options to control how the query is executed.
|
|
395
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
396
|
-
*/
|
|
397
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
398
|
-
returnPartialData: boolean;
|
|
399
|
-
}): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
400
|
-
/**
|
|
401
|
-
* A hook for imperatively executing queries in an Apollo application, e.g. in response to user interaction.
|
|
402
|
-
*
|
|
403
|
-
* > Refer to the [Queries - Manual execution with useLazyQuery](https://www.apollographql.com/docs/react/data/queries#manual-execution-with-uselazyquery) section for a more in-depth overview of `useLazyQuery`.
|
|
404
|
-
*
|
|
405
|
-
* @example
|
|
406
|
-
*
|
|
407
|
-
* ```jsx
|
|
408
|
-
* import { gql } from "@apollo/client";
|
|
409
|
-
* import { useLazyQuery } from "@apollo/client/react";
|
|
410
|
-
*
|
|
411
|
-
* const GET_GREETING = gql`
|
|
412
|
-
* query GetGreeting($language: String!) {
|
|
413
|
-
* greeting(language: $language) {
|
|
414
|
-
* message
|
|
415
|
-
* }
|
|
416
|
-
* }
|
|
417
|
-
* `;
|
|
418
|
-
*
|
|
419
|
-
* function Hello() {
|
|
420
|
-
* const [loadGreeting, { called, loading, data }] = useLazyQuery(GET_GREETING, {
|
|
421
|
-
* variables: { language: "english" },
|
|
422
|
-
* });
|
|
423
|
-
* if (called && loading) return <p>Loading ...</p>;
|
|
424
|
-
* if (!called) {
|
|
425
|
-
* return <button onClick={() => loadGreeting()}>Load greeting</button>;
|
|
426
|
-
* }
|
|
427
|
-
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
428
|
-
* }
|
|
429
|
-
* ```
|
|
430
|
-
*
|
|
431
|
-
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
432
|
-
* @param options - Default options to control how the query is executed.
|
|
433
|
-
* @returns A tuple in the form of `[execute, result]`
|
|
434
|
-
*/
|
|
435
|
-
export declare function useLazyQuery<TData = unknown, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: useLazyQuery.Options<NoInfer<TData>, NoInfer<TVariables>>): useLazyQuery.ResultTuple<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
689
|
+
export declare const useLazyQuery: useLazyQuery.Signature;
|
|
436
690
|
//# sourceMappingURL=useLazyQuery.d.ts.map
|