graphql-dotnet: Byte Array sent through Variables(graphql .net client library) receive invalid_value
Description
Hi,
I’m trying to create an InputObjectGraphType/ObjectGraphType with a property of byte array. I’m using Json .NET for serialization. I’m trying to receive a byte array property to my server query field resolver but it fails with INVALID_VALUE I’d appreciate your help in understanding what am i doing wrong Thanks a lot in advance!
Steps to reproduce
I have this basic setup:
public class BytesHolder
{
public byte[] Bytes { get; set; }
}
public class OutputBytesType : ObjectGraphType<BytesHolder>
{
public OutputBytesType()
{
Field(x => x.Bytes);
}
}
public class InputBytesType : InputObjectGraphType<BytesHolder>
{
public InputBytesType()
{
Field(x => x.Bytes);
}
}
public class DemoQuery : ObjectGraphType
{
public DemoQuery()
{
Field<OutputBytesType>(
"bytes",
arguments: new QueryArguments(new QueryArgument<InputBytesType> { Name = "bytesObject" }),
resolve: context =>
{
var bytesObject = context.GetArgument<BytesHolder>("bytesObject");
return bytesObject;
}
);
}
}
I’m sending this request through a console application client
var bytesRequest = new GraphQLRequest
{
Query = @"
query BytesRequest($bytesHolder: InputBytesType) {
bytes(bytesObject: $bytesHolder) {
bytes
}
}",
Variables = new
{
bytesHolder = new BytesHolder
{
Bytes = new byte[] { 1, 2, 3, 4 }
}
}
};
var graphQLResponse = await graphQLClient.SendQueryAsync<BytesHolder>(bytesRequest);
Upon receiving the request, the server fails to parse the request (it gets to this line:
Register<string, byte>(value => byte.Parse(value, NumberFormatInfo.InvariantInfo));
instead of this line:
Register<string, byte[]>(value => Convert.FromBase64String(value)); // such a built-in conversion for string->byte[] seems useful
Expected result
The server should succeed in parsing the byte array property.
Actual result
The server fails with INVALID_VALUE due to miscalculation in the value converter
Environment
GraphQL 3.0.0, Windows 10, Asp .NET Core 3.1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (15 by maintainers)
Commits related to this issue
- Add test for #1874 — committed to graphql-dotnet/graphql-dotnet by sungam3r 3 years ago
- Add test for #1874 (#2273) — committed to graphql-dotnet/graphql-dotnet by sungam3r 3 years ago
@eyaldar So if you only supported base64 strings, then it’s easy – see #2274 . However, the
GraphTypeTypeRegistrywill not match on an array type, so you would need to specify the type manually wherever the field is defined.