Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.09k stars 112 forks source link

omitempty validation on input fields with/without defaults #338

Closed Fazt01 closed 5 months ago

Fazt01 commented 6 months ago

Fixes https://github.com/Khan/genqlient/issues/290 and https://github.com/Khan/genqlient/issues/228#issuecomment-2023396706 (for latter, only the comment of mine, not the whole issue)

This is only changing where the omitempty is allowed and forbidden - it does not change where is the omitempty actually generated or not in generated code.

Separately each line of changelog:

In general, I have also moved the omitempty check from directives to the time of creating Go types/tags of field. This seems more consistent, as not all possibilities were caught before (i.e. general @genqlient(omitemtpy: true) vs @genqlient(for: ..., omitempty: true)). When creating Go type/tags, all the options/directives are already merged, so the final result is being checked. There is minor difference in error message (instead of reference to directive, the error refers to the whole operation, but also includes type.field name)

I have: