-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bad API behaviour results in uncaught errors #94
Comments
While I love the simplicity of this tool, it would be great to add in some kind of custom error checker - we might be able to do this by attaching a callback into the generated GraphQL client at runtime? That would at least serve as a perfect place to inject our code: member _.UpdateItemAsync(input: UpdateItem.InputVariables) =
task {
let query = """
mutation UpdateItem($BoardId: ID!, $ItemId: ID!, $ColumnValues: JSON!) {
update_item: change_multiple_column_values(board_id: $BoardId, item_id: $ItemId, column_values: $ColumnValues) {
id,
name
}
}
"""
let inputJson = JsonConvert.SerializeObject({ query = query; variables = Some input }, settings)
let! response = httpClient.PostAsync(url, new StringContent(inputJson, Encoding.UTF8, "application/json"))
let! responseContent = Async.AwaitTask(response.Content.ReadAsStreamAsync())
use sr = new StreamReader(responseContent)
use tr = new JsonTextReader(sr)
let responseJson = serializer.Deserialize<JObject>(tr)
match response.IsSuccessStatusCode with
| true ->
// *************
// HERE <--- call some optional callback to add validation/error checking based on the remote API's behavior.
// *************
let errorsReturned =
responseJson.ContainsKey "errors"
&& responseJson.["errors"].Type = JTokenType.Array
&& responseJson.["errors"].HasValues
if errorsReturned then
let response = responseJson.ToObject<GraphqlErrorResponse>(serializer)
return Error response.errors
else
let response = responseJson.ToObject<GraphqlSuccessResponse<UpdateItem.Query>>(serializer)
return Ok response.data
| errorStatus ->
let response = responseJson.ToObject<GraphqlErrorResponse>(serializer)
return Error response.errors
} |
Hi @varon it is very unfortunate that errors returned by a GraphQL API are not typed anywhere 😞 I've added one configuration point called Although we could extend this via configuration so that There is one possible extension point though, the generated clients accept a custom {
"error_code": "ColumnValueException",
"status_code": 200,
"error_message": "This status label doesn\u0027t exist, possible statuses are: {0: Working on it, 1: Done, 2: Stuck, 3: Started}",
"error_data": {
"column_value": "{\"label\"\u003d\u003e\"Bottling\"}",
"column_id": "status"
}
} into: {
"errors": [{ "error_code": "...", "status_code": 200, "error_message": "..." }]
} Then using the custom error type you can tell the serializer to handle things like |
Another solution is changing code generation so that it accepts a simpler interception transform without having to customize the |
Thanks for the prompt and detailed responses, @Zaid-Ajaj. Monday.com has a fairly horrendous API, it's far from anything that's decent. Their dates for instance are encoded as nested, escaped JSON strings with separate fields for dates and times (WTF!). Will go the HttpClient route, but would be good to have that work via a more elegant mechanism in the future. Would still love to have some kind of custom validator |
That sounds horrible 😞 sorry to hear that. It is probably an API that is auto-generated from from their data source as is.
If you do find a solution, can you post it here? Then I can add a section to the documentation |
An incorrect query to the Monday.com GraphQL API results in the following error:
This returns status code 200, and bypasses all error detection in the code for the success path, because it's looking for only the key
"errors"
- perhaps we can expand this via config? Any ideas on how to handle that?Thanks for making such a great tool.
The text was updated successfully, but these errors were encountered: