Comments (12)
Check out the optional: pointer
setting in genqlient.yaml
! If I'm understanding your request correctly that's exactly what it does.
from genqlient.
@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.
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.
Looking at the documentation, I'm trying to achieve what it says here with the global omitempty.
Doesn't seem to be working for my code, even though I followed exactly?
Where is the ,omitempty json tag??? Below is my genqlient.graphql
from genqlient.
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.
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.
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.
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.
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.
Hasura users -- please take a look at #272 and add any thoughts!
from genqlient.
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.
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)
- 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 3
- Add option to not generate the client, only the types HOT 2
- Option to generate multiple files HOT 2
- Using an Interface inline fragment inside of a Union is awkward to unpack HOT 3
- Optional parameter made required HOT 2
- schema.md has some formatting issues
- Running genqlient on large schemas fails HOT 4
- use_struct_references not compatible with new omitempty validation logic HOT 9
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.