Closed onionhammer closed 4 months ago
I'm not able to reproduce this issue if I change Dictionary<string, JsonElement>?
to Dictionary<string, JsonElement?>?
and post the following mutation:
mutation {
takeFlexibleInput(test: { extensionData: [{ key: "x", value: null }] }) {
extensionData {
key
value
}
}
}
Am I missing something?
@glen-84 JsonElement can represent null
JSON as a valid value, so just because JsonElement
is NOT null, doesnt mean that the JSON is NOT null.
In other words, Dictionary<string, JsonElement>
(non-null JsonElement) should have no trouble binding to { key: "x", value: null }
; null
would just be the equivalent of a JsonElement with ValueKind of Null
There is no map semantic in GraphQL ... the dictionary is just a list to Hot Chocolate. Also I would not expose dictionaries like that... rather expose the map itself as JsonType and get a cleaner schema. I am closing this issue.
@michaelstaib it's not me that's choosing JsonExtensionData as a dictionary. Not sure if I understand your explanation... also the whole dictionary/list/map thing is completely besides the point; the point is that a non-null JsonElement can result a null
value on the client. If you declare it not null
by giving it a bang(!) you're essentially lying to the typescript compiler
Is there an existing issue for this?
Product
Hot Chocolate
Describe the bug
JsonElement
and other types that utilize it allow fornull
values on the .NET side;for example:
However, in HotChocolate by default, JsonElement becomes a non-null JsonType scalar.
yields a schema like
Which does not allow for null values within the extension data, meaning any valid
null
JSON value will turn into a hot chocolate validation error.Steps to reproduce
null
in the list of values, i.e.{ "myField": null }
Relevant log output
No response
Additional Context?
Other things I tried:
Decorating ExtensionData with JsonElement? fails because .NET's JsonSerializer doesnt accept that, it gives: "".ExtensionData' is invalid. It must implement 'IDictionary<string, JsonElement>' or 'IDictionary<string, object>', or be 'JsonObject'.""
.BindRuntimeType<IDictionary<string, JsonElement>, JsonType>()
gives an array of non-null JSON values, which will not serialize well to a dictionary, also it is still non-null onlyWorkaround:
Perhaps create a custom json 'dictionary' scalar?
Version
13.5.1