1

We have a GraphQL mutation with a byte array (Blob) field. How can I use tools like Insomnia or GraphQL playground to send byte array data to test the API?

mutation {
  saveSomething(something: {
    contentByteArray: [97, 110, 103, 101, 108, 111]
  }) {
    content
  }
}
angelokh
  • 9,426
  • 9
  • 69
  • 139

1 Answers1

0

You can send data like that, however I understand that GraphQL sends a List of bytes rather than an array. In C# such a field (I'm uploading a photo) would be described as

Field<ListGraphType<ByteGraphType>>("photo");

and would need to be converted back into an array in order to be saved to the database e.g.


IDictionary<string, object> dicPlayer = (IDictionary<string, object>)context.Arguments["input"];
...

if (dicPlayer.ContainsKey("photo")) {
    if (dicPlayer["photo"] == null) {
        playerInput.Photo = null;
    } else {
        List<byte> lstB = new List<byte>();
        foreach (var objB in (List<object>)dicPlayer["photo"]) {
            byte b = (byte)objB;
            lstB.Add(b);
        }
        byte[] arrB = lstB.ToArray();
        playerInput.Photo = arrB;
    }
}