graphql-client icon indicating copy to clipboard operation
graphql-client copied to clipboard

Casting Error in GraphQL C# Library

Open lavanyadeepak opened this issue 1 year ago • 4 comments
trafficstars

We are facing a piquant situation using GraphQLClient's SendQueryAsync method to call Monday.com API. The line goes like this

var response = await graphQLClient.SendQueryAsync(request)

If the server returns a proper JSON it is all fine. However if the server returns a message like Complexity budget exhausted, query cost 30001 budget remaining 29984 out of 1000000 reset in 8 seconds, it throws a message like

Error converting value Complexity budget exhausted, query cost 30001 budget remaining 29984 out of 1000000 reset in 8 seconds to type GraphQL.GraphQLError. Path errors[0] line 1 position 305

How do we configure this graphqlclient to cast the string into GraphQL Error or are we missing something else?

lavanyadeepak avatar Nov 22 '23 00:11 lavanyadeepak

Hi, could you post the complete HTTP response you get when this issue occurs?

rose-a avatar Nov 22 '23 07:11 rose-a

GraphQLResponse<dynamic> response is NULL. However captured using Fiddler as below

149
{"error_code":"ComplexityException","status_code":429,"error_message":"Complexity budget exhausted, query cost 30001 budget remaining 19986 out of 1000000 reset in 3 seconds","error_data":{},"errors":["Complexity budget exhausted, query cost 30001 budget remaining 19986 out of 1000000 reset in 3 seconds"],"account_id":2213213}
0

Formatted JSON Output (for readability)

{
    "error_code": "ComplexityException",
    "status_code": 429,
    "error_message": "Complexity budget exhausted, query cost 30001 budget remaining 19986 out of 1000000 reset in 3 seconds",
    "error_data": {},
    "errors": [
        "Complexity budget exhausted, query cost 30001 budget remaining 19986 out of 1000000 reset in 3 seconds"
    ],
    "account_id": 2213213
}

lavanyadeepak avatar Nov 22 '23 08:11 lavanyadeepak

The response does not adhere to the GraphQL Spec.

The errors entry is expected to contain a list of maps, which must have at least the property message containing a description string. Thats why the deserialization fails.

It is currently not possible to use a custom GraphQLResponse type, the only way would be to clone the code and build yourself a custom version of this library.

rose-a avatar Nov 22 '23 12:11 rose-a

The response does not adhere to the GraphQL Spec.

I called this out to the OP in the monday.com community as well. monday.com refuses to acknowledge they do not follow the spec for errors as well.

codyfrisch avatar Nov 22 '23 15:11 codyfrisch