This sample project shows how to register a custom response writer that will inspect an object's fields and discard any that have a null
value.
Program.cs
shows how to register the custom response writerNullSupressingResponseWriter.cs
shows how to skip null fields
Sample Query:
query {
donutWithName: retrieveDonut(name: "glazed"){
id
name
shape
}
# 'name' will be null and the response writer will supress it
donutWithoutName : retrieveDonut(name: null){
id
name
shape
}
}
Response:
{
"data": {
"donutWithName": {
"id": 3,
"name": "glazed",
"shape": "round"
},
"donutWithoutName": {
"id": 3,
"shape": "round"
}
}
}
Note: I don't believe this is a spec compliant implementation. The user requested a nullable field that produced a valid null
value, yet it was not returned. The query is also indeterminate since the structure of the output varies based on field values and not the query text as provided.