Simplify checking if a response contains any GraphQL errors
For my use case, I want to fail if the GraphQL response contains any errors, I don't want to ignore partial failures.
In order to determine if a GraphQL response contains any errors, currently one needs to either check the response.original_hash for errors, or traverse the entire response tree to see if any node has errors associated with it.
The simplest solution to this could be to add the parameter all = true to include all errors in the top level response.errors:
Response.new(
result,
data: definition.new(data, Errors.new(errors, ["data"])),
errors: Errors.new(errors, all = true),
extensions: extensions
)
however, I suppose that would break some existing uses, depending on how people use response.errors.
A backwards compatible, but less elegant solution is to add an additional field on Response that provides all errors:
Response.new(
result,
data: definition.new(data, Errors.new(errors, ["data"])),
errors: Errors.new(errors),
all_errors: Errors.new(errors, all = true),
extensions: extensions
)
For now, I worked around it using original_hash:
errors = response.original_hash["errors"]
unless errors.nil? || errors.empty? then
# deal with errors
end