Repository navigation
Conversation
… provided" null support This is an early push for demostration purposes
The current behaviour is as following:type query {
foo (bar: String): String
foo2 (bar: ComplexInput): String
}
input ComplexInput {
complexKey: String
}
The important aspect here ist that there is a difference between a "first level argument" ( Null values:When we allow explicit While it may enough for It is important to note that we should not change the current behaviour: changing it would be a very subtle runtime change, which would probably lead to bugs.
class GraphQLNullValue {
private static final NULL = new GraphQLNullValue();
private GraphQLNullValue() {
}
}This would result in:
This way we would have a consistent way how we treat But: While this would be consistent and explicit, it would be a breaking change: suddenly there could be another value in the arguments Map, which is not of the expected type. I think we must make it optional (and turned off by default), if someone really wants to distinguish between Update: See #434 (comment) for the solution |
|
@andimarek Even though I find this approach more cumbersome to use (requires checking for this special value in addition to checking for nulls), I think it is the correct approach. It's very explicit and unambiguous, and that is IMHO the most important metric for a low-level library. |
|
@kaqqao yes, I am also not totally happy with it, because if you allow Which is a breaking change, when I think about it: If someone upgrades |
|
BTW we can split this PR into 2 - the ability to specify The first has some value just in being able to do literal specifications The absence of null is valuable for the mutation reasons |
|
When I started this PR I first had the idea of a special sentinal value eg: But while explicit, its really Java unnatural. Its easier in javaScript since they have 'undefined' and 'null' values for this use case (sort of). I was thinking about it from the consumers point of view and thats the DataFetcher The complex object is going to be a Map and hence trying to work out if "bar" is present or not can be done via The proposed code would then be more like It just feels a lot less expected. Its precise but its less natural. Either way the change is a behaviour breaking change since existing code cant know that GraphQLNullValue.NULL is possible or that null handling has changed. |
|
@bbakerman I agree that it would be unnatural and in case of a complex |
|
and btw: I would prefer not to add that topic to 3.0.0 ... it is already a lot. We should aim for 4.0.0 for that change. |
|
just so that we don't forget to think about that case: this change also allows someField(value: ["Value1", null, "Value3"]) |
|
@andimarek I don't think I'm getting you about |
|
@kaqqao that is exactly the problem: It won't:
As you can see there is no way to differentiate between |
|
Have a look at : https://github.com/facebook/graphql/blob/master/spec/Section%203%20--%20Type%20System.md And the Input Coercion part of it :
The value of that entry in the result is the outcome of input coercing the original entry value according to the input coercion rules of the type declared by the input field. Following are examples of Input Object coercion for the type:
So I think for 4.0 it would be right thing to do to move towards "spec" and use the absence of the field in the map to indicate that absence and presence in the map (with possible null value) to indicate present with some value (which maybe null or not) Using a sentinel GraphqlNullValue is a mistake I think. Saving this change for 4.0 say because of the breaking runtime behavior |
|
BTW - there is minor runtime breaking behaviour in adding 'null literal' support Technically I think this is really minor since it would require some one to be accepting a enum and the word |
|
After talking with @bbakerman we came to the following solution: It is the best for the future to map "not provided" to "no key in map" and But: Legacy Option: This option will be removed in version 5. The special |
|
While the missing key vs the current key-with-null is indeed a subtle change, I don't think it's likely to cause any damage. Currently the key is always present so there's really no reason anyone would be checking for its presence (the part that is changing), and |
|
@kaqqao I agree it is a very subtle change. But especially with these changes we try to be empathic with our users. |
|
These tests document the current behaviour: d8bfa00 The first test (d8bfa00#diff-3eca2508c3f86d5d839beca2e0e520faR360) would break with the introduction of The more I think about, the more I am convinced that we don't need a legacy option flag: it is a very subtle change, but I believe it would not really break anything. ( To break something the code would need to relay on the existing of a key in a map being null. if (arguments.get("bar") != null) ...for a query |
|
This was exactly my point in the previous message. Unless the code does |
|
@kaqqao Yes, you right. Didn't want to neglect your comment ... just needed some time let that sink in. |
…proach to this change and the selectively re-instate code
…-null-value-support
|
Damn I have buggered this branch right up. I am going to throw it away and start again...with a TDD approach. And I have the right PR this time |
|
And now I see that tests have already been added.... missed that sorry. Anyway I am starting a new branch either way to make sure I am 3.0 clean |
This is an early push for demostration purposes