GithubHelp home page GithubHelp logo

Comments (6)

benjaminjkraft avatar benjaminjkraft commented on June 2, 2024

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.

kevinmichaelchen avatar kevinmichaelchen commented on June 2, 2024

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.

benjaminjkraft avatar benjaminjkraft commented on June 2, 2024

Yep I think that's right! Good catch that we need the change in both places.

from genqlient.

kevinmichaelchen avatar kevinmichaelchen commented on June 2, 2024

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.

kevinmichaelchen avatar kevinmichaelchen commented on June 2, 2024

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.

benjaminjkraft avatar benjaminjkraft commented on June 2, 2024

#267

from genqlient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.