Issue Description
Using modern signatures ApolloClient.QueryResult<TData, TErrorPolicy> correctly narrows based on error policy — e.g. errorPolicy: 'none' maps to { data: TData; error?: never } since GraphQL errors reject the promise instead of resolving with partial data.
useLazyQuery's ExecFunction type hardcodes the default policy and never looks at the errorPolicy passed to the hook:
type ExecFunction<TData, TVariables extends OperationVariables> = (...args: {} extends TVariables ? [
options?: useLazyQuery.ExecOptions<TVariables>
] : [options: useLazyQuery.ExecOptions<TVariables>]) => ObservableQuery.ResultPromise<ApolloClient.QueryResult<TData /*, missing TErrorPolicy here */>>;
Repro
import type { TypedDocumentNode } from '@apollo/client';
import { useLazyQuery } from '@apollo/client/react';
const [loadOperation] = useLazyQuery({} as TypedDocumentNode<{ someField: boolean }, {}>, { errorPolicy: 'none' });
loadOperation({}).then(({ data }) => {
data.someField; // TS18048: 'data' is possibly 'undefined'
});
Even though at runtime, with errorPolicy: 'none', data is guaranteed defined on promise resolution (a GraphQL error rejects the promise instead), the type says otherwise. Expected: ExecFunction/ResultTuple should carry the resolved TErrorPolicy (from the hook's Options), so the exec function's promise resolves to the correctly narrowed QueryResult<TData, TErrorPolicy>.
Link to Reproduction
This is a Typescript-only issue
Reproduction Steps
No response
@apollo/client version
4.2.8
Issue Description
Using modern signatures
ApolloClient.QueryResult<TData, TErrorPolicy>correctly narrows based on error policy — e.g.errorPolicy: 'none'maps to{ data: TData; error?: never }since GraphQL errors reject the promise instead of resolving with partial data.useLazyQuery'sExecFunctiontype hardcodes the default policy and never looks at theerrorPolicypassed to the hook:Repro
Even though at runtime, with
errorPolicy: 'none',datais guaranteed defined on promise resolution (a GraphQL error rejects the promise instead), the type says otherwise. Expected:ExecFunction/ResultTupleshould carry the resolvedTErrorPolicy(from the hook'sOptions), so the exec function's promise resolves to the correctly narrowedQueryResult<TData, TErrorPolicy>.Link to Reproduction
This is a Typescript-only issue
Reproduction Steps
No response
@apollo/clientversion4.2.8