GithubHelp home page GithubHelp logo

Global omitempty option about genqlient HOT 12 OPEN

liron-navon avatar liron-navon commented on September 27, 2024 2
Global omitempty option

from genqlient.

Comments (12)

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

Check out the optional: pointer setting in genqlient.yaml! If I'm understanding your request correctly that's exactly what it does.

from genqlient.

liron-navon avatar liron-navon commented on September 27, 2024

@benjaminjkraft why did you close it? you don't understand correctly, the "optional: pointer" doesn't omit empty, it passes "null" instead, this breaks different apis, namely "shopify" and "spacex"

from genqlient.

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

Thanks for clarifying. I guess it's valid GraphQL to treat explicit null differently. It seems like what you are proposing is a global config to turn on omitempty. That seems reasonable to add, although soon we are going to have to figure out how to make all these related config options not explode the config complexity.

from genqlient.

mujagic-nermin avatar mujagic-nermin commented on September 27, 2024

Looking at the documentation, I'm trying to achieve what it says here with the global omitempty.
image

Doesn't seem to be working for my code, even though I followed exactly?
image
Where is the ,omitempty json tag??? Below is my genqlient.graphql
image

from genqlient.

dharijanto avatar dharijanto commented on September 27, 2024

Thanks for clarifying. I guess it's valid GraphQL to treat explicit null differently. It seems like what you are proposing is a global config to turn on omitempty. That seems reasonable to add, although soon we are going to have to figure out how to make all these related config options not explode the config complexity.

Hi Benjamin, just to clarify, I think the author wants the global omitempty: true only for input parameter. He is probably using Hasura 2.0 (just like I am)

Just to give you a bit more background, in Hasura 2.0, they introduced a breaking change that distinguishes "implicit null" vs. "explicit null".

hasura/graphql-engine#7484 (comment)

from genqlient.

dharijanto avatar dharijanto commented on September 27, 2024

Hi @benjaminjkraft I created a draft PR to fix the issue. Would you mind taking a look?
#264

I haven't written/fixed tests associated to it, I figure I'd check with you first if the direction is okay.

from genqlient.

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

Thanks for the context and the PR. I can see why they have ended up wanting the distinction. (For others reading, the changelog entry describes the breaking part of the change, although it sounds like this isn't the only place they draw the distinction.)

I commented in the PR -- for a couple reasons I think a new config option might be useful but I think if we do do that it's a fine way to do things.

At some point we should probably also have a clearer example/FAQ entry for how to use genqlient with hasura, since the hasura-generated schemas seem to have a bunch of quirks that genqlient's defaults don't match with. (But that doesn't have to be now.)

from genqlient.

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

One realization I had on the way home: a workaround is to have your inputs be the fields you want to set, rather than the whole object. For example, instead of:

myQuery(myInput: SomeInputType) {
  field(input: $myInput) { ... }
}

you'd do

myQuery(myField: String!) {
  field(input: {myField: $myField}) { ... }
}

Obviously some pluses and minuses there, so it doesn't obviate the issue, but may be useful until we get this option sorted.

from genqlient.

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

Ah, I realized while trying to consolidate issues that we also have use_struct_references, which is not quite the same but may also be useful to folks in this issue.

from genqlient.

benjaminjkraft avatar benjaminjkraft commented on September 27, 2024

Hasura users -- please take a look at #272 and add any thoughts!

from genqlient.

dharijanto avatar dharijanto commented on September 27, 2024

Hi Ben,

At some point we should probably also have a clearer example/FAQ entry for how to use genqlient with hasura, since the hasura-generated schemas seem to have a bunch of quirks that genqlient's defaults don't match with. (But that doesn't have to be now.)

Yeah I totally agree. Feels a bit non-intuitive at the moment to get genqlient to work with Hasura.

Thanks for responding to the thread and commenting on the PR. Since you've created a separate issue to consolidate Hasura-related discussions, should I just close the PR?

from genqlient.

skandragon avatar skandragon commented on September 27, 2024

It is also difficult to use Dgraph because IDs are passed as empty strings, and DGraph rejects this.

Dgraph takes the schema submitted and augments it in various ways, such as:

input AddComponentInput {
  type: String!
  name: String!
  version: String!
  publisher: String
  licenses: [ComponentLicenseRef!]
  purl: String
  cpe: String
  vulnerabilities: [VulnerabilityRef!]
}

type AddComponentPayload {
  component(filter: ComponentFilter, order: ComponentOrder, first: Int, offset: Int): [Component]
  numUids: Int
}

type Mutation {
  addComponent(input: [AddComponentInput!]!): AddComponentPayload
}

The issue I have is I want to set things to "omit empty" on at least some of the fields in this Dgraph-generated type list. I am not sure how to do this. Right now, I can modify the generated Go file, but that is quickly a pain.

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.