Closed
Description
Describe the bug
Successful messages contain an empty array errors
property, while error messages contain a null data
property.
{
"data": {
"users": {
"name": "stream user"
}
},
"errors": []
}
{
"data": {
"users": null
},
"errors": [
{
"message": "some field error from handler",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"users"
],
"extensions": "some additional string"
}
]
}
To Reproduce
Run the warp_subscriptions example
Expected behavior
Succesful messages should contain only data
. Error messages should contain only errors
.
Additional context
Introduced by #721
Activity
ccbrown commentedon Aug 2, 2020
This isn't (entirely) a bug. The result of executing a GraphQL operation is not binary "success" or "error". You can have data present and have errors. In fact, the spec requires that the
data
key is always present if execution occurs (as opposed to an error happening during parsing or validation, in which case a different message type is sent back altogether).It probably makes sense to omit the empty errors array in your first example, and just emit this:
But your second example is correct, and removing the
data
key would violate the spec.ccbrown commentedon Aug 2, 2020
PR to omit empty errors from serialization: #732
The spec does say:
It says "should" and not "must", so clients should be fine either way, but it's definitely worth changing.
mihai-dinculescu commentedon Aug 2, 2020
That looks like an inconsistency in the spec. Just above that, under Response Format, the spec takes a more prescriptive approach:
mihai-dinculescu commentedon Aug 2, 2020
The caveat here is if the operation started executing or not.
Data spec
Response Format spec is even more prescriptive
ccbrown commentedon Aug 2, 2020
The message type this issue is about is only used if execution has started. If execution has not started, an entirely different message type is used (which does not contain a "data" field). That's the difference between the graphql-ws "data" and "error" messages:
juniper/juniper_graphql_ws/src/server_message.rs
Lines 109 to 123 in 6788ef2
ccbrown commentedon Aug 2, 2020
Looks like you're right about the success case. That fix has been merged though, so I think we're now 100% spec compliant. Let me know if anything else looks off.
mihai-dinculescu commentedon Aug 2, 2020
Right! I've got the two confused. All good!