-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useMutation
/useLazyQuery
execution functions always requires full variables when using TypedDocumentNode
#12100
Comments
Hey @maciesielka 👋 Good catch! FYI the team is away at a conference this week so we won't be able to look at this until at least next week. Thanks for raising the issue! |
Hi @jerelmiller, can I have a try at this if possible? |
@naman1608 absolutely! |
@jerelmiller, I have a doubt if you could take a look? Should |
Hi @maciesielka and @naman1608, As these "double options", especially the merging behaviour between them, are very confusing, we're actually considering to deprecate or even remove the In that context, I'm honestly very reluctant towards any type changes here now - we want to start work on 4.0 very soon, and it would be very confusing for users if we went back-and-forth on this so quickly. |
Okay that makes sense if improving the typing experience here might encourage usage of functionality that's on its way out. I'll try and soft-deprecate usage of the variable merging in my projects until y'all get around to officially deprecating it. |
Yup makes sense, thanks @phryneas!! |
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: