Matti MK
09/12/2022, 9:59 AMerrors
field.
Looking at the handling of the errors field I can see the following:
1. errors
is nullable
2. errors.extension
is nullable
3. extension
might, or might not, contain the 401 code
To me this seems quite confusing and I guess means writing something like so to see if server returned 401:
result.errors?.any { err -> err.extensions?.get("code") == "Unauthorized" }
Using the dataAssertNoErrors
as suggested by client docs doesn’t really seem suitable as it effectively just turns all the possible errors into a string.
I feel that I must be missing something here, so would be great to know if I’ve gone off the tracks 😄?bod
09/12/2022, 10:07 AMdataAssertNoErrors
is a shortcut that can be useful when you don't really care about the type of error. Otherwise use .errors
as you do in your snippet.Matti MK
09/13/2022, 4:06 AMMatti MK
09/13/2022, 4:09 AM"property": "a_property_name",
"children": [
{
"property": "a_sub_property_name",
"children": [],
"constraints": {
"isNotEmpty": "a_sub_property_name should not be empty",
"minLength": "a_sub_property_name must be longer than or equal to 5 characters",
"maxLength": "a_sub_property_name must be shorter than or equal to 100 characters"
}
bod
09/13/2022, 7:24 AMMatti MK
09/13/2022, 8:23 AMconstraints
property comes from https://github.com/typestack/class-validator actually, but nonetheless, it’s more or less the same data structure for the default Apollo errors.
To give an example: I have a Mutation with 10 fields, each. with their own constraints. I am wondering what are the options to handle the errors properly? As per your above message, I guess at least one way to do it is to parse the error manually from the extensions
.
I guess another option is to write custom errors on the backend side?Matti MK
09/13/2022, 8:24 AMMatti MK
09/13/2022, 8:26 AMextensions: Map<String, Any?>?
Matti MK
09/13/2022, 8:29 AMbod
09/13/2022, 8:34 AMerrors
, since it's not part of the schema, no parsers can be automatically generated to ease decoding on the client side.
Another way to see it is that the schema could be changed to return, for instance, an Union type of either your result, or an Error type which is defined in the schema. That way you would get a generated parser.
But 1/ I'm not really sure this is to be recommended - that could complexify your queries (now you need to deal with polymorphism / fragments)
2/ you'd still need to check the errors
at the call site (so now you have 3 cases: network error / GraphQL error / your domain error via this union
3/ In your specific case it looks like the error format is of a 'tree' structure. That won't help writing the queries 😅