Skip to content

How to use GeoJSONPointTypeData with Strawberryshake (or any scalar representing an array) #6261

Closed Answered by RobTF
RobTF asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, engaging the grey matter I found a solution - simply sidestep the issue by using a custom class which wraps a collection of the value.

e.g.

In some .cs file.

public class Position : Collection<double> { }

public class PositionSerializer : ScalarSerializer<JsonElement, Position>
{
    public PositionSerializer() : base("Position") {}

    public override Position Parse(JsonElement serializedValue)
        => serializedValue.Deserialize<Position>() ?? throw new InvalidOperationException();

    protected override JsonElement Format(Position runtimeValue)
        => System.Text.Json.JsonSerializer.SerializeToElement(runtimeValue);
}

In schema.extensions.graphql

extend scalar Position
    

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by RobTF
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant