Make null value configurable, to allow undefined
See original GitHub issueundefined is practical in JS for destructuring default, so it would be great to allow graphql to avoid converting undefined to null
I see some return null or return Promise.resovle(null) frequently in the sources, how about using a NULL configuration variable, defaulting to null
Issue Analytics
- State:
- Created 5 years ago
- Reactions:7
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Fun JavaScript: Safely dealing with undefined/null values ...
We have “lifted” the number into a container, in this case, an array, we have excluded the value if it is undefined/null (by...
Read more >null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >Can I set null as the default value for a @Value in Spring?
This puts an empty String into the variable if the attribute is not present. I would like to have null as the default...
Read more >Documentation - TypeScript 2.0
Null - and undefined-aware types. TypeScript has two special types, Null and Undefined, that have the values null and undefined respectively.
Read more >Understanding the difference between null and undefined in ...
A property with a null value must have it explicitly assigned. Properties not defined in an item have an undefined value. In the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

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,
undefinedvalues imply removal of fields, which breaks this core constraint.JavaScript is also a bit strange in this respect, since most languages do not have a concept of a runtime value for
undefined. Since GraphQL.js seeks to be a reference implementation for other GraphQL libraries built in other languages, it’s important to remain close to the spec.In this way,
nullandundefinedactually have special meaning to GraphQL results outside of typical results.nullmeans that the field requested is not available (either due to being non-existent or from an error) whileundefined(or absent from response) means that the field was not requested.To preserve the differences between
nullandundefinedvalues as typical values rather than special meaning - perhaps because either you intend to translate to a transport mechanism different from JSON whereundefinedvalues are preserved (is there such a thing?) or you don’t intend to send the results over the network at all - then I would suggest taking a look at some of the libraries that offer resolver middleware to replaceundefinedwith a different placeholder value.undefined(from server-side) also reduces JSON responses size