ChilliCream / graphql-platform

Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Banana Cake Pop the awesome Monaco based GraphQL IDE.
https://chillicream.com
MIT License
5.26k stars 745 forks source link

Strawberry Shake fails to parse long ints #1457

Closed freever closed 3 years ago

freever commented 4 years ago

As an experiment I enabled tracing using TracingPreference = TracingPreference.Always in my SchemaBuilder. I didn't join the dots initially but this caused Strawberry Shake to break. My generated ResultParser started failing with

"UNEXPECTED_ERROR": "One of the identified items was in an invalid format."

The stack trace ended as follows:

at System.Text.Json.JsonElement.GetInt32()\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseLeaf(JsonElement value)\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseValue(JsonElement obj)\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseObject(JsonElement obj)\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseValue(JsonElement obj)\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseObject(JsonElement obj)\r\n at StrawberryShake.Http.JsonResultParserBase1.TryParseExtensions(JsonElement parent, IReadOnlyDictionary2& extensions)\r\n at StrawberryShake.Http.JsonResultParserBase1.ParseInternal(JsonDocument document, IOperationResultBuilder resultBuilder)\r\n at StrawberryShake.Http.JsonResultParserBase`1.d__16.MoveNext()\r\n

I moved the base class code into my generated parser to debug, and found that there was an Extensions dictionary in the Json result which was added by the tracing configuration and which was failing to be parsed because some of the numeric values were too big to be parsed into integers.

For example:

ValueKind = Object : "{"tracing":{"version":1,"startTime":"2020-02-07T14:31:57.8719625Z","endTime":"2020-02-07T14:32:04.3834097Z","duration":6511447200,"parsing":{"startOffset":45400,"duration":373700},"validation":{"startOffset":432400,"duration":9700},"execution":{"resolvers":[{"path":["ChallengesConnection"],"parentType":"QueryType","fieldName":"ChallengesConnection","returnType":"ChallengeConnection","startOffset":703800,"duration":6509610100},

...threw an exception when trying to convert Duration into an integer.

Line 256 of JsonResultParserBase should probably use GetInt64() instead of GetInt32()...?

michaelstaib commented 3 years ago

We have reimplemented the parsers and this should not be a problem any longer.