Skip to content

ReadBody fails when variables are provided #48

@rhysgodfrey

Description

@rhysgodfrey

Describe the bug

When calling ReadBody in the RequestReader if the body includes some variables then an exception is thrown.

The exception that is thrown is:

System.Text.Json.JsonException : The JSON value could not be converted to System.Collections.Generic.IEnumerable`1[Newtonsoft.Json.Linq.JToken]. Path: $.variables | LineNumber: 0 | BytePositionInLine: 82.

Stack Trace:

ThrowHelper.ThrowJsonException_DeserializeUnableToConvertValue(Type propertyType)
    JsonPropertyInfoNotNullable`4.OnReadEnumerable(ReadStack& state, Utf8JsonReader& reader)
    JsonPropertyInfo.ReadEnumerable(JsonTokenType tokenType, ReadStack& state, Utf8JsonReader& reader)
    JsonPropertyInfo.Read(JsonTokenType tokenType, ReadStack& state, Utf8JsonReader& reader)
    JsonSerializer.ReadCore(JsonSerializerOptions options, Utf8JsonReader& reader, ReadStack& readStack)
    JsonSerializer.ReadCore(JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan`1 buffer, JsonSerializerOptions options, ReadStack& readStack)
    JsonSerializer.ReadAsync[TValue](Stream utf8Json, Type returnType, JsonSerializerOptions options, CancellationToken cancellationToken)
    RequestReader.ReadBody(Stream stream, CancellationToken cancellation) line 55
    RequestReaderTests.Parse(String chars) line 46
    RequestReaderTests.Parse(String chars) line 47
    --- End of stack trace from previous location where exception was thrown ---

Minimal Repro

The issue can be reproduced with the following test:

    [Fact]
    public Task ParsingWithVariables()
    {
        return Parse("{\"query\":\"{\\n  noAttachment\\n  {\\n    argument\\n  }\\n}\",\"variables\":{\"key\":\"value\"},\"operationName\":\"theOperation\"}");
    }

See rhysgodfrey@c3f6796

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions