ChilliCream / ChilliCream/graphql-platform
StrawberryShake serialization of GeoJSONPointInput
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
Product
Strawberry Shake
Describe the bug
I am sending a GeoJSONPointInput to a GraphQL server for reverse geocoding. I am using a custom serializer to serialize the Position part of the input type, which has been in place and working up through 13.5.1. When upgrading to 13.7.0, my server started returning errors. I have tracked down the prerelease versions and the issue was introduced in 13.6.0-preview.33. 13.6.0-preview.32 worked.
Steps to reproduce
Using this serializer, send a GeoJSONPointInput to a GraphQL server:
public class PositionSerializer : ScalarSerializer<JsonElement, Array>
{
public PositionSerializer() : base("Position") { }
public override Array Parse(JsonElement serializedValue)
{
if (serializedValue.ValueKind != JsonValueKind.Array)
throw new ArgumentException($"expected ValueKind '{JsonValueKind.Array}', received '{serializedValue.ValueKind}", nameof(serializedValue));
if (serializedValue.GetArrayLength() == 2)
return new[] {serializedValue[0].GetDouble(), serializedValue[1].GetDouble(), 0.0};
if (serializedValue.GetArrayLength() == 3)
return new[] {serializedValue[0].GetDouble(), serializedValue[1].GetDouble(), serializedValue[2].GetDouble()};
throw new ArgumentException($"expected 2 or 3 coordinate values, received {serializedValue.GetArrayLength()}", nameof(serializedValue));
}
protected override JsonElement Format(Array runtimeValue)
{
if (runtimeValue.Length == 2)
return JsonDocument.Parse($"[{(double) runtimeValue.GetValue(0)!},{(double) runtimeValue.GetValue(1)!},0.0]").RootElement;
if (runtimeValue.Length == 3)
return JsonDocument.Parse($"[{(double) runtimeValue.GetValue(0)!},{(double) runtimeValue.GetValue(1)!},{(double) runtimeValue.GetValue(2)!}]").RootElement;
throw new ArgumentException($"expected 2 or 3 coordinate values, received {runtimeValue.Length}", nameof(runtimeValue));
}
}
Relevant log output
Xunit.Sdk.EmptyException
Assert.Empty() Failure: Collection was not empty
Collection: [ClientError { Code = null, Exception = null, Extensions = [["field"] = "GeoJSONPointInput.coordinates", ["fieldType"] = "Position"], Locations = null, Message = "Unknown", ··· }]
at GraphTest.Integration.GraphIntegrationTestBase.VerifyOperationResult[T](IOperationResult`1 result, ITestOutputHelper testOutput) in /Users/chogan/Dev/ovc/web-service/GraphTest/Integration/GraphIntegrationTestBase.cs:line 220
at GraphTest.Integration.Details.Geocode.ReverseGeocodeTests.ReverseGeocodeTest(TestCase tc) in /Users/chogan/Dev/ovc/web-service/GraphTest/Integration/Details/Geocode/ReverseGeocodeTests.cs:line 62
at Xunit.Sdk.TestInvoker`1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 285
--- End of stack trace from previous location ---
at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func`1 asyncAction) in /_/src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
Data: none
1. message:Unknown, code:
Extensions:
field: GeoJSONPointInput.coordinates
fieldType: Position
Additional Context?
13.6.0-preview.32 - Working
13.6.0-preview.33 - NOT working
My server is 13.7.0. I am using 13.7.0 for code generation. The package that appears to cause the problem is StrawberryShake.Server. The above versions where changed for that package only.
I am able to send the operation directly to the server using Postman:
query($point: GeoJSONPointInput!) {
reverseGeocode(point: $point) {
formattedAddress
}
}
{
"point": {
"type": "Point",
"coordinates": [-85.113162,41.0766406,0]
}
}
Version
13.7.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the GeoJSONPointInput request with StrawberryShake.Server 13.6.0-preview.32 and preview.33, using the PositionSerializer shown in the issue. Start with GraphIntegrationTestBase.cs line 220 and ReverseGeocodeTests.cs line 62, then compare the generated operation or serialized variables; done means the Position value is accepted without the GeoJSONPointInput.coordinates ClientError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, graphql
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100