@apollo/client 4.2.0-alpha.4 → 4.2.0-alpha.6
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 +12 -0
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +29 -2
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +1023 -23
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +115 -7
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +195 -8
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +20 -9
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +288 -19
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +409 -17
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +29 -2
- package/core/ApolloClient.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/useBackgroundQuery.d.ts +1023 -23
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +115 -7
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +195 -8
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +20 -9
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +288 -19
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +409 -17
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1023 -23
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +115 -7
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +195 -8
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +20 -9
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +288 -19
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +409 -17
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sources":["../../../src/react/hooks/useMutation.ts"],"sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type {\n LazyType,\n NoInfer,\n Prettify,\n SignatureStyle,\n} from \"@apollo/client/utilities/internal\";\nimport {\n mergeOptions,\n preventUnhandledRejection,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\n// Extract the `variables` value from an inferred `TOptions`. We use a keyof\n// guard (rather than `TOptions extends { variables: infer V }`) because\n// `variables` in the modern signature's constraint is declared optional, so\n// the `extends { variables: infer V }` form fails to match when the user\n// passes a complex options object that gets widened to include the optional\n// modifier. `TOptions[\"variables\"]` works for both required and optional\n// `variables` entries.\ntype ExtractConfiguredVariables<\n TOptions,\n TVariables extends OperationVariables,\n> = \"variables\" extends keyof TOptions ?\n Exclude<TOptions[\"variables\"], undefined> extends infer V ?\n [V] extends [never] ? {}\n : V extends Partial<TVariables> ? V\n : {}\n : {}\n: {};\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: Partial<TVariables> & TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export namespace Base {\n export interface Result {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n }\n\n /**\n * Maps `errorPolicy` to the shape of `data` and `error` as observable from\n * the hook result state.\n *\n * The hook has additional states (before call, during loading) where `data`\n * and `error` are `undefined`, so `data` remains nullable even on error\n * policies that would otherwise guarantee it. Only `error` is narrowed away\n * for `\"ignore\"`, since the underlying `client.mutate` promise never rejects\n * and never resolves with an error for that policy.\n */\n export type ResultStateMap<TData = unknown> = {\n none: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n all: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n ignore: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: undefined;\n };\n undefined: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n };\n\n export type Result<\n TData = unknown,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = Base.Result & ResultStateMap<TData>[`${TErrorPolicy}`];\n\n export namespace DocumentationTypes {\n namespace useMutation {\n export interface Result<TData = unknown> extends Base.Result {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n }\n }\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache, TErrorPolicy>,\n result: Result<TData, TErrorPolicy>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>, TErrorPolicy>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache> & {\n /**\n * {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member}\n *\n * @remarks\n * When provided as a callback function, the function is called with the\n * value of `context` provided to the `useMutation` hook.\n */\n context?:\n | DefaultContext\n | ((hookContext: DefaultContext | undefined) => DefaultContext);\n };\n\n export interface DefaultOptions\n extends ApolloClient.DefaultOptions.Mutate.Calculated {}\n\n export type ResultForOptions<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n TOptions extends Record<string, never> | Options<TData, TVariables, TCache>,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = LazyType<\n ResultTuple<\n TData,\n MakeRequiredVariablesOptional<\n TVariables,\n ExtractConfiguredVariables<TOptions, TVariables>\n >,\n TCache,\n [TErrorPolicy] extends [undefined] ?\n DefaultOptions extends { errorPolicy: infer D } ?\n D\n : undefined\n : TErrorPolicy\n >\n >;\n\n export namespace DocumentationTypes {\n /**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\n export interface useMutation {\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: Options<TData, TVariables>\n ): ResultTuple<TData, TVariables>;\n }\n\n /**\n * @deprecated Avoid manually specifying generics on `useMutation`.\n * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your mutation results.\n *\n * {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)}\n */\n export interface useMutation_Deprecated {\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: Options<TData, TVariables>\n ): ResultTuple<TData, TVariables>;\n }\n }\n\n export namespace Signatures {\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation_Deprecated:call(1)} */\n export interface Classic {\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation_Deprecated:call(1)} */\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n > & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: TErrorPolicy;\n }\n ): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache,\n TErrorPolicy\n >;\n }\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n export interface Modern {\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>\n ): useMutation.ResultForOptions<\n TData,\n TVariables,\n TCache,\n Record<string, never>\n >;\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache\n > & {\n variables?: {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n };\n },\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: TOptions & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: TErrorPolicy;\n }\n ): useMutation.ResultForOptions<\n TData,\n TVariables,\n TCache,\n TOptions,\n TErrorPolicy\n >;\n }\n\n export type Evaluated = SignatureStyle extends \"classic\" ? Classic : Modern;\n }\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n export interface Signature extends Signatures.Evaluated {}\n}\n\n/** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\nexport const useMutation: useMutation.Signature = function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n const context =\n typeof executeOptions.context === \"function\" ?\n executeOptions.context(options?.context)\n : executeOptions.context;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, {\n ...executeOptions,\n context,\n } as any);\n\n return preventUnhandledRejection(\n client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<\n TData,\n OperationVariables\n >\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (\n ref.current.isMounted &&\n !equal(ref.current.result, result)\n ) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n )\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n} as any;\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useMutation.js","sources":["../../../src/react/hooks/useMutation.ts"],"sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type {\n LazyType,\n NoInfer,\n Prettify,\n SignatureStyle,\n} from \"@apollo/client/utilities/internal\";\nimport {\n mergeOptions,\n preventUnhandledRejection,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\n// Extract the `variables` value from an inferred `TOptions`. We use a keyof\n// guard (rather than `TOptions extends { variables: infer V }`) because\n// `variables` in the modern signature's constraint is declared optional, so\n// the `extends { variables: infer V }` form fails to match when the user\n// passes a complex options object that gets widened to include the optional\n// modifier. `TOptions[\"variables\"]` works for both required and optional\n// `variables` entries.\ntype ExtractConfiguredVariables<\n TOptions,\n TVariables extends OperationVariables,\n> = \"variables\" extends keyof TOptions ?\n Exclude<TOptions[\"variables\"], undefined> extends infer V ?\n [V] extends [never] ? {}\n : V extends Partial<TVariables> ? V\n : {}\n : {}\n: {};\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: Partial<TVariables> & TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export namespace Base {\n export interface Result {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n }\n\n /**\n * Maps `errorPolicy` to the shape of `data` and `error` as observable from\n * the hook result state.\n *\n * The hook has additional states (before call, during loading) where `data`\n * and `error` are `undefined`, so `data` remains nullable even on error\n * policies that would otherwise guarantee it. Only `error` is narrowed away\n * for `\"ignore\"`, since the underlying `client.mutate` promise never rejects\n * and never resolves with an error for that policy.\n */\n export type ResultStateMap<TData = unknown> = {\n none: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n all: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n ignore: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: undefined;\n };\n undefined: {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n };\n };\n\n export type Result<\n TData = unknown,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = Base.Result & ResultStateMap<TData>[`${TErrorPolicy}`];\n\n export namespace DocumentationTypes {\n namespace useMutation {\n export interface Result<TData = unknown> extends Base.Result {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n }\n }\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache, TErrorPolicy>,\n result: Result<TData, TErrorPolicy>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>, TErrorPolicy>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache> & {\n /**\n * {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member}\n *\n * @remarks\n * When provided as a callback function, the function is called with the\n * value of `context` provided to the `useMutation` hook.\n */\n context?:\n | DefaultContext\n | ((hookContext: DefaultContext | undefined) => DefaultContext);\n };\n\n export interface DefaultOptions\n extends ApolloClient.DefaultOptions.Mutate.Calculated {}\n\n export type ResultForOptions<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n TOptions extends Record<string, never> | Options<TData, TVariables, TCache>,\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n > = LazyType<\n ResultTuple<\n TData,\n MakeRequiredVariablesOptional<\n TVariables,\n ExtractConfiguredVariables<TOptions, TVariables>\n >,\n TCache,\n [TErrorPolicy] extends [undefined] ?\n DefaultOptions extends { errorPolicy: infer D } ?\n D\n : undefined\n : TErrorPolicy\n >\n >;\n\n export namespace DocumentationTypes {\n /**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\n export interface useMutation {\n <\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: Options<TData, TVariables>\n ): ResultTuple<TData, TVariables>;\n }\n }\n\n export namespace Signatures {\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n export interface Classic {\n // _INFERENCE_ONLY_DO_NOT_SPECIFY is used to distinguish between inferred\n // generics arguments and explicit generic arguments so that we can\n // provide a `@deprecated` signature for explicit generic arguments. As\n // soon as a user provides a generic arg (e.g. useMutation<TData>(mutation))`,\n // the overload falls through to the overloads without\n // _INFERENCE_ONLY_DO_NOT_SPECIFY.\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n _INFERENCE_ONLY_DO_NOT_SPECIFY extends \"inferred\",\n TConfiguredVariables extends Partial<TVariables> = {},\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n ApolloCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n > & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: TErrorPolicy;\n }\n ): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n ApolloCache,\n TErrorPolicy\n >;\n\n /**\n * @deprecated Avoid manually specifying generics on `useMutation`.\n * Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your mutation results.\n *\n * {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)}\n */\n <\n TData,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n > &\n (TErrorPolicy extends undefined ? {}\n : {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy: TErrorPolicy;\n })\n ): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache,\n TErrorPolicy\n >;\n }\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n export interface Modern {\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends never,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>\n ): useMutation.ResultForOptions<\n TData,\n TVariables,\n TCache,\n Record<string, never>\n >;\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n <\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache,\n // this overload should never be manually defined, it should always be inferred\n TOptions extends useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache\n > & {\n variables?: {\n [K in Exclude<\n keyof TOptions[\"variables\"],\n keyof TVariables\n >]?: never;\n };\n },\n TErrorPolicy extends ErrorPolicy | undefined = undefined,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: TOptions & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: TErrorPolicy;\n }\n ): useMutation.ResultForOptions<\n TData,\n TVariables,\n TCache,\n TOptions,\n TErrorPolicy\n >;\n }\n\n export type Evaluated = SignatureStyle extends \"classic\" ? Classic : Modern;\n }\n\n /** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\n export interface Signature extends Signatures.Evaluated {}\n}\n\n/** {@inheritDoc @apollo/client/react!useMutation.DocumentationTypes.useMutation:call(1)} */\nexport const useMutation: useMutation.Signature = function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n const context =\n typeof executeOptions.context === \"function\" ?\n executeOptions.context(options?.context)\n : executeOptions.context;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, {\n ...executeOptions,\n context,\n } as any);\n\n return preventUnhandledRejection(\n client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<\n TData,\n OperationVariables\n >\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (\n ref.current.isMounted &&\n !equal(ref.current.result, result)\n ) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n )\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n} as any;\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -341,10 +341,6 @@ export declare namespace useQuery {
|
|
|
341
341
|
}
|
|
342
342
|
namespace Signatures {
|
|
343
343
|
/**
|
|
344
|
-
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
345
|
-
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
344
|
* A hook for executing queries in an Apollo application.
|
|
349
345
|
*
|
|
350
346
|
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
@@ -381,6 +377,279 @@ export declare namespace useQuery {
|
|
|
381
377
|
* @returns Query result object
|
|
382
378
|
*/
|
|
383
379
|
interface Classic {
|
|
380
|
+
/**
|
|
381
|
+
* A hook for executing queries in an Apollo application.
|
|
382
|
+
*
|
|
383
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
384
|
+
*
|
|
385
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
386
|
+
*
|
|
387
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
*
|
|
391
|
+
* ```jsx
|
|
392
|
+
* import { gql } from "@apollo/client";
|
|
393
|
+
* import { useQuery } from "@apollo/client/react";
|
|
394
|
+
*
|
|
395
|
+
* const GET_GREETING = gql`
|
|
396
|
+
* query GetGreeting($language: String!) {
|
|
397
|
+
* greeting(language: $language) {
|
|
398
|
+
* message
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
* `;
|
|
402
|
+
*
|
|
403
|
+
* function Hello() {
|
|
404
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
405
|
+
* variables: { language: "english" },
|
|
406
|
+
* });
|
|
407
|
+
* if (loading) return <p>Loading ...</p>;
|
|
408
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
409
|
+
* }
|
|
410
|
+
* ```
|
|
411
|
+
*
|
|
412
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
413
|
+
* @param options - Options to control how the query is executed.
|
|
414
|
+
* @returns Query result object
|
|
415
|
+
*/
|
|
416
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
417
|
+
returnPartialData: true;
|
|
418
|
+
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
419
|
+
/**
|
|
420
|
+
* A hook for executing queries in an Apollo application.
|
|
421
|
+
*
|
|
422
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
423
|
+
*
|
|
424
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
425
|
+
*
|
|
426
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
427
|
+
*
|
|
428
|
+
* @example
|
|
429
|
+
*
|
|
430
|
+
* ```jsx
|
|
431
|
+
* import { gql } from "@apollo/client";
|
|
432
|
+
* import { useQuery } from "@apollo/client/react";
|
|
433
|
+
*
|
|
434
|
+
* const GET_GREETING = gql`
|
|
435
|
+
* query GetGreeting($language: String!) {
|
|
436
|
+
* greeting(language: $language) {
|
|
437
|
+
* message
|
|
438
|
+
* }
|
|
439
|
+
* }
|
|
440
|
+
* `;
|
|
441
|
+
*
|
|
442
|
+
* function Hello() {
|
|
443
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
444
|
+
* variables: { language: "english" },
|
|
445
|
+
* });
|
|
446
|
+
* if (loading) return <p>Loading ...</p>;
|
|
447
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
448
|
+
* }
|
|
449
|
+
* ```
|
|
450
|
+
*
|
|
451
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
452
|
+
* @param options - Options to control how the query is executed.
|
|
453
|
+
* @returns Query result object
|
|
454
|
+
*/
|
|
455
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): useQuery.Result<TData, TVariables, "empty", Record<string, never>>;
|
|
456
|
+
/**
|
|
457
|
+
* A hook for executing queries in an Apollo application.
|
|
458
|
+
*
|
|
459
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
460
|
+
*
|
|
461
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
462
|
+
*
|
|
463
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
*
|
|
467
|
+
* ```jsx
|
|
468
|
+
* import { gql } from "@apollo/client";
|
|
469
|
+
* import { useQuery } from "@apollo/client/react";
|
|
470
|
+
*
|
|
471
|
+
* const GET_GREETING = gql`
|
|
472
|
+
* query GetGreeting($language: String!) {
|
|
473
|
+
* greeting(language: $language) {
|
|
474
|
+
* message
|
|
475
|
+
* }
|
|
476
|
+
* }
|
|
477
|
+
* `;
|
|
478
|
+
*
|
|
479
|
+
* function Hello() {
|
|
480
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
481
|
+
* variables: { language: "english" },
|
|
482
|
+
* });
|
|
483
|
+
* if (loading) return <p>Loading ...</p>;
|
|
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 - Options to control how the query is executed.
|
|
490
|
+
* @returns Query result object
|
|
491
|
+
*/
|
|
492
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
493
|
+
returnPartialData: true;
|
|
494
|
+
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
495
|
+
/**
|
|
496
|
+
* A hook for executing queries in an Apollo application.
|
|
497
|
+
*
|
|
498
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
499
|
+
*
|
|
500
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
501
|
+
*
|
|
502
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
503
|
+
*
|
|
504
|
+
* @example
|
|
505
|
+
*
|
|
506
|
+
* ```jsx
|
|
507
|
+
* import { gql } from "@apollo/client";
|
|
508
|
+
* import { useQuery } 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 { loading, error, data } = useQuery(GET_GREETING, {
|
|
520
|
+
* variables: { language: "english" },
|
|
521
|
+
* });
|
|
522
|
+
* if (loading) return <p>Loading ...</p>;
|
|
523
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
524
|
+
* }
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
528
|
+
* @param options - Options to control how the query is executed.
|
|
529
|
+
* @returns Query result object
|
|
530
|
+
*/
|
|
531
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
532
|
+
returnPartialData: boolean;
|
|
533
|
+
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
534
|
+
/**
|
|
535
|
+
* A hook for executing queries in an Apollo application.
|
|
536
|
+
*
|
|
537
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
538
|
+
*
|
|
539
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
540
|
+
*
|
|
541
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
*
|
|
545
|
+
* ```jsx
|
|
546
|
+
* import { gql } from "@apollo/client";
|
|
547
|
+
* import { useQuery } from "@apollo/client/react";
|
|
548
|
+
*
|
|
549
|
+
* const GET_GREETING = gql`
|
|
550
|
+
* query GetGreeting($language: String!) {
|
|
551
|
+
* greeting(language: $language) {
|
|
552
|
+
* message
|
|
553
|
+
* }
|
|
554
|
+
* }
|
|
555
|
+
* `;
|
|
556
|
+
*
|
|
557
|
+
* function Hello() {
|
|
558
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
559
|
+
* variables: { language: "english" },
|
|
560
|
+
* });
|
|
561
|
+
* if (loading) return <p>Loading ...</p>;
|
|
562
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
563
|
+
* }
|
|
564
|
+
* ```
|
|
565
|
+
*
|
|
566
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
567
|
+
* @param options - Options to control how the query is executed.
|
|
568
|
+
* @returns Query result object
|
|
569
|
+
*/
|
|
570
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
571
|
+
returnPartialData: boolean;
|
|
572
|
+
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
573
|
+
/**
|
|
574
|
+
* A hook for executing queries in an Apollo application.
|
|
575
|
+
*
|
|
576
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
577
|
+
*
|
|
578
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
579
|
+
*
|
|
580
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
*
|
|
584
|
+
* ```jsx
|
|
585
|
+
* import { gql } from "@apollo/client";
|
|
586
|
+
* import { useQuery } from "@apollo/client/react";
|
|
587
|
+
*
|
|
588
|
+
* const GET_GREETING = gql`
|
|
589
|
+
* query GetGreeting($language: String!) {
|
|
590
|
+
* greeting(language: $language) {
|
|
591
|
+
* message
|
|
592
|
+
* }
|
|
593
|
+
* }
|
|
594
|
+
* `;
|
|
595
|
+
*
|
|
596
|
+
* function Hello() {
|
|
597
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
598
|
+
* variables: { language: "english" },
|
|
599
|
+
* });
|
|
600
|
+
* if (loading) return <p>Loading ...</p>;
|
|
601
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
602
|
+
* }
|
|
603
|
+
* ```
|
|
604
|
+
*
|
|
605
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
606
|
+
* @param options - Options to control how the query is executed.
|
|
607
|
+
* @returns Query result object
|
|
608
|
+
*/
|
|
609
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
610
|
+
options?: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
611
|
+
] : [options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>]): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
612
|
+
/**
|
|
613
|
+
* A hook for executing queries in an Apollo application.
|
|
614
|
+
*
|
|
615
|
+
* To run a query within a React component, call `useQuery` and pass it a GraphQL query document.
|
|
616
|
+
*
|
|
617
|
+
* When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, `dataState`, and `data` properties you can use to render your UI.
|
|
618
|
+
*
|
|
619
|
+
* > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
*
|
|
623
|
+
* ```jsx
|
|
624
|
+
* import { gql } from "@apollo/client";
|
|
625
|
+
* import { useQuery } from "@apollo/client/react";
|
|
626
|
+
*
|
|
627
|
+
* const GET_GREETING = gql`
|
|
628
|
+
* query GetGreeting($language: String!) {
|
|
629
|
+
* greeting(language: $language) {
|
|
630
|
+
* message
|
|
631
|
+
* }
|
|
632
|
+
* }
|
|
633
|
+
* `;
|
|
634
|
+
*
|
|
635
|
+
* function Hello() {
|
|
636
|
+
* const { loading, error, data } = useQuery(GET_GREETING, {
|
|
637
|
+
* variables: { language: "english" },
|
|
638
|
+
* });
|
|
639
|
+
* if (loading) return <p>Loading ...</p>;
|
|
640
|
+
* return <h1>Hello {data.greeting.message}!</h1>;
|
|
641
|
+
* }
|
|
642
|
+
* ```
|
|
643
|
+
*
|
|
644
|
+
* @param query - A GraphQL query document parsed into an AST by `gql`.
|
|
645
|
+
* @param options - Options to control how the query is executed.
|
|
646
|
+
* @returns Query result object
|
|
647
|
+
*/
|
|
648
|
+
<TData, TVariables extends OperationVariables, _INFERENCE_ONLY_DO_NOT_SPECIFY extends "inferred">(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
649
|
+
options?: SkipToken | useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
650
|
+
] : [
|
|
651
|
+
options: SkipToken | useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
652
|
+
]): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming", Partial<TVariables>>;
|
|
384
653
|
/**
|
|
385
654
|
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
386
655
|
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
@@ -421,7 +690,7 @@ export declare namespace useQuery {
|
|
|
421
690
|
* @param options - Options to control how the query is executed.
|
|
422
691
|
* @returns Query result object
|
|
423
692
|
*/
|
|
424
|
-
<TData
|
|
693
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
425
694
|
returnPartialData: true;
|
|
426
695
|
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
427
696
|
/**
|
|
@@ -464,7 +733,7 @@ export declare namespace useQuery {
|
|
|
464
733
|
* @param options - Options to control how the query is executed.
|
|
465
734
|
* @returns Query result object
|
|
466
735
|
*/
|
|
467
|
-
<TData
|
|
736
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): useQuery.Result<TData, TVariables, "empty", Record<string, never>>;
|
|
468
737
|
/**
|
|
469
738
|
* @deprecated Avoid manually specifying generics on `useQuery`.
|
|
470
739
|
* Instead, rely on TypeScript's type inference along with a correctly typed `TypedDocumentNode` to get accurate types for your query results.
|
|
@@ -505,7 +774,7 @@ export declare namespace useQuery {
|
|
|
505
774
|
* @param options - Options to control how the query is executed.
|
|
506
775
|
* @returns Query result object
|
|
507
776
|
*/
|
|
508
|
-
<TData
|
|
777
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
509
778
|
returnPartialData: true;
|
|
510
779
|
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
511
780
|
/**
|
|
@@ -548,7 +817,7 @@ export declare namespace useQuery {
|
|
|
548
817
|
* @param options - Options to control how the query is executed.
|
|
549
818
|
* @returns Query result object
|
|
550
819
|
*/
|
|
551
|
-
<TData
|
|
820
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
552
821
|
returnPartialData: boolean;
|
|
553
822
|
}): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial">;
|
|
554
823
|
/**
|
|
@@ -591,7 +860,7 @@ export declare namespace useQuery {
|
|
|
591
860
|
* @param options - Options to control how the query is executed.
|
|
592
861
|
* @returns Query result object
|
|
593
862
|
*/
|
|
594
|
-
<TData
|
|
863
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken | (useQuery.Options<NoInfer<TData>, NoInfer<TVariables>> & {
|
|
595
864
|
returnPartialData: boolean;
|
|
596
865
|
})): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming" | "partial", Partial<TVariables>>;
|
|
597
866
|
/**
|
|
@@ -634,7 +903,7 @@ export declare namespace useQuery {
|
|
|
634
903
|
* @param options - Options to control how the query is executed.
|
|
635
904
|
* @returns Query result object
|
|
636
905
|
*/
|
|
637
|
-
<TData
|
|
906
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
638
907
|
options?: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
639
908
|
] : [options: useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>]): useQuery.Result<TData, TVariables, "empty" | "complete" | "streaming">;
|
|
640
909
|
/**
|
|
@@ -677,7 +946,7 @@ export declare namespace useQuery {
|
|
|
677
946
|
* @param options - Options to control how the query is executed.
|
|
678
947
|
* @returns Query result object
|
|
679
948
|
*/
|
|
680
|
-
<TData
|
|
949
|
+
<TData, TVariables extends OperationVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: {} extends TVariables ? [
|
|
681
950
|
options?: SkipToken | useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
682
951
|
] : [
|
|
683
952
|
options: SkipToken | useQuery.Options<NoInfer<TData>, NoInfer<TVariables>>
|
|
@@ -794,7 +1063,13 @@ export declare namespace useQuery {
|
|
|
794
1063
|
* @param options - Options to control how the query is executed.
|
|
795
1064
|
* @returns Query result object
|
|
796
1065
|
*/
|
|
797
|
-
<TData, TVariables extends OperationVariables, TOptions extends
|
|
1066
|
+
<TData, TVariables extends OperationVariables, TOptions extends useQuery.Options<TData, NoInfer<TVariables>> & VariablesOption<TVariables & {
|
|
1067
|
+
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
1068
|
+
}>>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: [
|
|
1069
|
+
TVariables
|
|
1070
|
+
] extends [never] ? [options: never] : {} extends TVariables ? [options?: TOptions] : [
|
|
1071
|
+
options: TOptions
|
|
1072
|
+
]): useQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
798
1073
|
/**
|
|
799
1074
|
* A hook for executing queries in an Apollo application.
|
|
800
1075
|
*
|
|
@@ -831,13 +1106,7 @@ export declare namespace useQuery {
|
|
|
831
1106
|
* @param options - Options to control how the query is executed.
|
|
832
1107
|
* @returns Query result object
|
|
833
1108
|
*/
|
|
834
|
-
<TData, TVariables extends OperationVariables, TOptions extends useQuery.
|
|
835
|
-
[K in Exclude<keyof TOptions["variables"], keyof TVariables>]?: never;
|
|
836
|
-
}>>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, ...[options]: [
|
|
837
|
-
TVariables
|
|
838
|
-
] extends [never] ? [options: never] : {} extends TVariables ? [options?: TOptions] : [
|
|
839
|
-
options: TOptions
|
|
840
|
-
]): useQuery.ResultForOptions<TData, TVariables, TOptions>;
|
|
1109
|
+
<TData, TVariables extends OperationVariables, TOptions extends SkipToken>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options: SkipToken): useQuery.Result<TData, TVariables, "empty", Record<string, never>>;
|
|
841
1110
|
/**
|
|
842
1111
|
* A hook for executing queries in an Apollo application.
|
|
843
1112
|
*
|