Skip to content

Global omitempty option #260

Open
Open
@liron-navon

Description

@liron-navon

Let's say a graphql query accepts an input object, which has an optional string in it, if I use the input object, and not give a value to that string, it should be committed, that's just how graphql works.
Unfortunately, this library doesn't work that way.

Is your feature request related to a problem? Please describe.
I have this input for shopify, the non struct fields are not required

Screenshot 2023-02-27 at 11 29 36

The generation works well, but if In don't include the optional fields, genqlient turns them into null (when defining value as pointer) or to an empty string (when defining value as value).

They should just be omitted as I don't want to send them, otherwise shopify will fail to use this.

Using the "@genqlient(omitempty: true)" is impossible, because the import is required, even tho every field on it is optional.

Describe the solution you'd like
add to the settings.yml file an option "omitempty: boolean" that would just cover all the json fields.

Describe alternatives you've considered
Adding manually the "omitempty" directive, but with thousands of fields it's makes it really hard to use, and time consuming and prone to humen errors.

Additional context
What I get generated, why would an optional pointer to a string not have omit empty?

Screenshot 2023-02-27 at 11 28 53

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions