graphql-dotnet / graphql-client

A GraphQL Client for .NET Standard
MIT License
619 stars 131 forks source link

Casting Error in GraphQL C# Library #600

Open lavanyadeepak opened 9 months ago

lavanyadeepak commented 9 months ago

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?

rose-a commented 9 months ago

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

lavanyadeepak commented 9 months ago

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
}
rose-a commented 9 months ago

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.

codyfrisch commented 9 months ago

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.