-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make null value configurable, to allow undefined #1298
Comments
I'm afraid I don't understand what you're asking for. Could you point out where you're seeing this? Perhaps some example code or a gist which shows what you expect vs what actually happens? |
Sorry, so here's an example https://runkit.com/caub/5abd4916eef72b00127e27af first case: seconds case, inner fields are filled with I'd be interested to keep undefined undefined similar discussion: brianc/node-postgres#1274 (where it ends up keeping codeconst { graphql, GraphQLObjectType: ObjectType, GraphQLNonNull: NonNull, GraphQLID: ID, GraphQLString: String, GraphQLList: List, GraphQLSchema: Schema, } = require('graphql');const Foo = new ObjectType({ const QueryType = new ObjectType({ let getFoos = () => undefined; const {data: {foos}} = await gql( console.log(foos); getFoos = () => [{id: '1', name: 'foo1'}, {id: '2'}]; const {data: {foos: foos2}} = await gql( console.log(foos2); |
Thanks for this extra info. This makes way more sense now. Unfortunately this isn't something GraphQL.js would consider adding since it breaks some of the core constraints of the spec - which is that you will get a field in the result for every field you ask for in the query. Because of how JSON serializes data, JavaScript is also a bit strange in this respect, since most languages do not have a concept of a runtime value for In this way, To preserve the differences between |
In your client could you just trim the null values to allow for defaults. This library appears to do that: |
|
It's common schenario to have fields that are omittable, not nullable. for example when you have password field in the update mutation, it can be omitted (in case user don't want to update password). Currently I use nullable notation for omittable inputs and tell client developer to send undefined, that doesn't feel so good :-\ Is there any alternative way of handling this? |
@leebyron Don't yout think that there should be something for achiving what we were doing with REST patch method in graphql? It's very common thing in APIs. 😞 |
If reducing the JSON response size is the objective an interesting approach would be to use graphql-crunch. |
undefined
is practical in JS for destructuring default, so it would be great to allow graphql to avoid convertingundefined
tonull
I see some
return null
orreturn Promise.resovle(null)
frequently in the sources, how about using aNULL
configuration variable, defaulting tonull
The text was updated successfully, but these errors were encountered: