useMutation
/useLazyQuery
execution functions always requires full variables when using TypedDocumentNode
#12100
Labels
Issue Description
The documentation for hooks like
useMutation
anduseLazyQuery
mention that there are two distinct ways to provide variables to the actual request: (1) as an option to the hook itself and (2) as an option to the query function returned by the hook. These allow variable merging such that the query function used at the call-site can override any values provided in the hook, and the docs linked above advertise this as a good way to provide defaults.The issue I'm running into is using this with Typescript and specifically
TypedDocumentNode
s that strongly type the variables to the operation, because the hooks always require the fully formed Variables rather than something than might support the merging / default structure you'd expect. Some possible solutions might be something straightforward like allowing aPartial
at both sites or something more involved that makes any fields provided in the hook optional in the query function.Check the quick sketch below as well as the provided Codesandbox to see this issue in more detail:
Imagine we'd like to use the following mutation
Usage of
useMutation
might look something like this, which creates errors in both the hook declaration and the execution usage, despite functionally working properly if you erase those errors withas any
.The same sort of issue occurs for
useLazyQuery
instances where the provided operation takes variables.Link to Reproduction
https://codesandbox.io/p/devbox/determined-elbakyan-vrsjcs?workspaceId=59bd876a-c3ad-4ffd-a783-ffc36a11e7d9
Reproduction Steps
Try it out
To the code
as any
typecasts arounduseMutation
and the usage of the execution function insrc/index.tsx
Observe type errors despite the working functionality described in the first section above
@apollo/client
version3.11.8
The text was updated successfully, but these errors were encountered: