-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Required Query Variables are optional #2870
Comments
@tbrannam the query and fragment you mentioned are not valid. Can you please share a reproduction of the issue? in a repo or in a codesandbox. Also, which version of codegen do you use? |
Using 1.8.3. I've created a mock server here: https://codesandbox.io/s/apollo-server-de1p6 It has client.ts which could call then generated hook variable contract isn't being typechecked. It would seem that if a Query required variables, the baseOptions would no longer be marked as optional. |
closing pending further research |
Why did you close this? |
@Stuart4 if you are still having issue with this, can you please open a new issue with a reproduction? |
Having the same issue here, the generated typing does not enforce user to provide mandatory variables. |
@eyalw can you please share a reproduction? |
@dotansimha Thanks for maintaining that awesome library. Here's a sandbox inspired by the one above to reproduce the issue: In that sandbox you can see that the mutation However in the component: // INCORRECT - Missing id
// This should throws an error because id is a required variable
// BaseOption should not be optional
update();
// CORRECT - Throw an error
update({ variables: { input: { } } });
// CORRECT
update({ variables: { input: { id: "hello" } } }); |
@dotansimha |
Is your feature request related to a problem? Please describe.
I'm frustrated that my GraphQL variables are not enforced in generated hooks
Describe the solution you'd like
Hooks (Apollo 3) generated typically have optional baseOptions. So callers of the generated hooks sometimes forget that a query requires a variable. If a query document includes a variable - it would be ideal if the type signature reflected this requirement.
See: https://codesandbox.io/s/apollo-server-de1p6
Describe alternatives you've considered
Create module level override hooks that add required fields from their signature and call the generated ones.
The text was updated successfully, but these errors were encountered: