Add response error graphql properties#308
Conversation
| }, | ||
| "code": { | ||
| "type": "string", | ||
| "description": "Error code from GraphQL extensions", |
There was a problem hiding this comment.
💬 suggestion: IMO, mentioning GraphQL extensions can be a bit confusing here because it requires to be aware of this concept of the GraphQL spec, and it could easily be misunderstood with the extension concept we have at SDK level.
I think we could:
- Not mention it at all,
"Error code" - Not mention GraphQL extension,
"Error code (used by some providers)"
There was a problem hiding this comment.
Sounds good ! I would prefer the second one as it is not always present. (to inform customers why it's not there)
| "path": { | ||
| "type": "array", | ||
| "description": "Path to the field that caused the error", | ||
| "items": { |
There was a problem hiding this comment.
@rgaignault Question.
What does this path mean? Is it ok that it is an array of either strings or numbers? Are you sure everything is correct here?
Asking because for Android our json parser generator fails to process this and I want to know if I need to fix it (add support of oneOf(primitive types)).
There was a problem hiding this comment.
Hey @aleksandr-gringauz ! Based on the spec, that's what I have : https://github.com/graphql/graphql-spec/blob/main/spec/Section%207%20--%20Response.md.
The value for a response path must be a list of path segments. Path segments that represent field response name must be strings, and path segments that represent list indices must be 0-indexed integers.
Also based on the examples it's either integer or string. Do you see an other way of declaring this ?
There was a problem hiding this comment.
Thanks for the reply @rgaignault!
Do you see an other way of declaring this ?
For me the following option will work. Checked it in dd-sdk-android.
"path": {
"type": "array",
"description": "Path to the field that caused the error",
"items": {
"oneOf": [
{
"type": "object",
"title": "String",
"required": ["segment"],
"properties": {
"segment": {
"type": "string"
}
}
},
{
"type": "object",
"title": "Integer",
"required": ["segment"],
"properties": {
"segment": {
"type": "integer"
}
}
}
]
},
"readOnly": true
}
There was a problem hiding this comment.
The problem with Kotlin is that we don't have String | Integer like typescript. We only have sealed classes, for example:
sealed interface Path {
data class String(val segment: String): Path
data class Integer(val segment: Int): Path
}
If I were to try to implement String | Integer I would have to generate something like:
sealed interface StringOrInt {
data class String(val segment: String): StringOrInt
data class Integer(val segment: Int): StringOrInt
}
And if oneOf(string|int) occurs multiple times in the schema, I would have to make different StringOrInt for them or somehow reuse a common one.
It all requires some work on the generator which I would like to avoid if possible.
There was a problem hiding this comment.
Discussed with @maxep about how they do on iOS. I might implement similar solution on Android, but need more time to think.
For now, no action is needed from your side. Thanks!
Add new properties for the following support for graphql response tracking.
Note : The code property is not native but taken from the extension field and move at the top level. As we would like to query directly :
@resource.[…].errors.code:xxx. It is present in the spec as a field in the extension part, so it could be manually added by the customers but also some libraries such as Apollo directly provide it in the response. (see Documentation)See the spec for more informations about the graphql response format : GraphQL Spec