-
Notifications
You must be signed in to change notification settings - Fork 114
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
use_struct_references not compatible with new omitempty validation logic #342
Comments
Thanks for the report. The issue is that after moving the validation to later stage (from parsing directives to generating Go types) (in my attempt to make the validation more consistent with various directives and global options), and the fact that The Solutions: After trying for a while to do a change of (2) - unsuccessfully (the conditions just keep growing) - and also considering the necessity to change the generated type in some cases, I'm currently leaning towards (1) just removing these validations and will try to do a PR if I (or someone else) won't come up with better solution. Temporary workaround (if necessary): |
Great analysis. Can we do something like (2) but apply it only to omitempty (not pointer)? Off the top of my head that seems like it would preserve behavior at least in the obvious cases. |
The omitempty and pointer are quite related: removing just omitempty would still leave the type "not valid", in a sense that zero value would send a (all related to
Just to be clear, "not valid" above means the type can be generated and used, just that there is a possibility of having invalid value (zero value) in the type that causes error during sending of the query. In the #338 , I added this pointer validation (together with moving the omitempty validation from directives to type generation): https://github.com/Khan/genqlient/blob/main/generate/convert.go#L453 |
Hmm, I see what you mean. But on reading slightly more carefully, removing the pointers seems like too big a compat break; I suspect it will break many of the Hasura users using this option, at least, and in a "rewrite most of your code that uses genqlient types" kind of way. (See #149 for examples of the schemas we're dealing with here. Unfortunately it seems we don't have any tests with required inputs with this option, which we should.) Another possible least-bad option: what if we disable the validation only if Optionally we could also add By the way, I forgot to say: @klondikedragon thanks for testing the latest version! This is how we keep this stuff out of the tagged releases :-) . |
That does seem like the most reasonbale middleground. I requested a PR. I also want to mention a weird behaviour that I encountered when attempting (2) in #343. When the input field type is a list, the omitempty (from use_struct_references) is propagated from the struct item to the list itself. E.g: Probably nothing to change now, but maybe could be considered if there was some larger refactor or new option like |
Yeah, we generally never do |
Fix for #342. As `use_struct_references` is incompatible with `omitempty` and `pointer` validation, the most simple change is to disable the validation when the `use_struct_references` is enabled. Note this implementation disables the validation even for types that are not influenced by `use_struct_references`, but still better than disabling the validation globally. I have: - [x] Written a clear PR title and description (above) - [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla) - [x] Added tests covering my changes, if applicable - [x] Included a link to the issue fixed, if applicable - [ ] Included documentation, for new features - [x] Added an entry to the changelog
my point is that for |
Thanks for all the careful consideration with this use case! Just for reference, I landed up also adding the following to my genqlient.yaml, as I was fighting some non-deterministic behavior trying to mark only certain fields in responses as using pointers and as optional. (I think it had to do with the order of resolving certain shared fragment types used in mutation inputs for different queries where one query had a field in the fragment type marked as optional, and another query that referenced the same fragment type as mandatory. use_struct_references: true
optional: pointer I haven't tried this configuration yet with the latest code after #344, I imagine it would work as expected, I'll report back if there is an issue. Thanks! |
@benjaminjkraft -- I can confirm this is working correctly with the latest HEAD. Thank you! There is an unrelated usability consideration with Hasura schemas that I'll add as a comment to #272 |
Describe the bug
In trying out the latest unreleased version of the repo (hoping it would fix a different bug with nondeterministic failures during codegen where it's sometimes (but not always) ignoring a "pointer: true" option for a deeply nested input field), I found that the new omitempty validation logic in #338 is incompatible with
use_struct_references: true
ingenqlient.yaml
. I'm not specifyingomitempty
explicitly anywhere in my GraphQL queries. Since use_struct_references is set to true, it seems to be automatically settingpointer: true
andomitempty: true
on every struct field, but the new validation logic does not likeomitempty: true
being set if the struct field is not optional.To Reproduce
I'm using a fairly complex GraphQL schema (auto-generated by Hasura). Here is an example failure message:
Here is the relevant portion of the GraphQL schema:
Expected behavior
The new omitempty validation logic should be compatible with
use_struct_references: true
genqlient version
Tip of main branch: 35fbf5b
The text was updated successfully, but these errors were encountered: