Comments (6)
Thanks for the clear repro! It took me a while to understand the subtle case even looking at all the code so the fact that it was all there was very helpful.
I think you're right that we should just propagate the json tags. It's happening in the first place because the premarshal types are generated in a separate code path (regular types, premarshal types), which arguably we could change. But anyway that's probably not necessary right now, probably we can just add a check for omitempty in the premarshal code.
I'm hoping to have some time to work on genqlient this weekend and if I do will try to get to this, but if you are excited to, I think this would actually be a good first PR; the code change is probably one line (in the premarshal types linked above; I think the data we need is already available) and the main thing is just adding some unit and integration tests to show that it works.
from genqlient.
Hey @benjaminjkraft — glad my repro was helpful!
Me, taking a guess
If I had to take a crack at it, I'd say we want to add
{{if .Omitempty -}},omitEmpty{{end}}
in the necessary places.
For example, we'd change this:
{{.GoName}} {{repeat .GoType.SliceDepth "[]"}}{{ref "encoding/json.RawMessage"}} `json:"{{.JSONName}}"`
{{else}}
{{.GoName}} {{.GoType.Reference}} `json:"{{.JSONName}}"`
to something like this:
{{.GoName}} {{repeat .GoType.SliceDepth "[]"}}{{ref "encoding/json.RawMessage"}} `json:"{{.JSONName}}{{if .Omitempty -}},omitEmpty{{end}}"`
{{else}}
{{.GoName}} {{.GoType.Reference}} `json:"{{.JSONName}}{{if .Omitempty -}},omitEmpty{{end}}"`
where Omitempty
comes from goStructField
.
Contributing
If that sounds like the correct approach, I can try to put up a PR and look into adding some test cases where needed.
from genqlient.
Yep I think that's right! Good catch that we need the change in both places.
from genqlient.
Hey @benjaminjkraft — threw up a PR here: #267
Still need to sign the CLA and add a changelog entry.
Should I add/modify documentation anywhere?
from genqlient.
In the meantime, I'll try to run my fork and see if it generates Hasura sub-sub-fields in the expected way.
Update: I ran it against nested BoolExp structs, and it looks like I'm still missing something!
from genqlient.
from genqlient.
Related Issues (20)
- Potential improvement to generated getters for pointer-optionals HOT 1
- Add an option to add custom Header when submitting via MakeRequest() HOT 5
- `convertDefinition` failing when `name` == concatenated `namePrefix` HOT 1
- Does the genqlient support extensions on requests? HOT 1
- Errors with Strawberry Generated Schema including `JSON` Scalar HOT 1
- Tests failing on Go 1.22+
- Lint failing on 1.21+
- Using `# @genqlient(typename: "Webhook")` adds `json:"-"` to generated struct (?) HOT 7
- Support `optional: generic` inline
- Support, new release HOT 1
- How can I get response header HOT 1
- Allow globs for schema/queries to be optional, if at least one file is found HOT 1
- Inconsistent JSON Tag Generation for Required Boolean Fields in Structs HOT 3
- Optional input with required output HOT 1
- Support for @authenticated directive HOT 2
- Standardise the error return from http request HOT 2
- Add option to not generate the client, only the types HOT 1
- Option to generate multiple files HOT 2
- Using an Interface inline fragment inside of a Union is awkward to unpack HOT 2
- Optional parameter made required HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genqlient.