graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

BindRuntimeType cannot bind arrays

Open PascalSenn opened this issue 4 years ago • 3 comments

public class Query 
{
    public byte[] GetFoo() => default!;
}
//
services.AddGraphQLServer()
    .AddQueryType<Query>()
    .BindRuntimeType<byte[], ByteArrayType>()

result in

type Query {
     foo: [ByteArray!]
}

but should be

type Query {
     foo: ByteArray!
}

PascalSenn avatar Jan 12 '21 20:01 PascalSenn

Same happens with IDictionary.

class code:

public record class Settable<T>(T Value)
{
    public static implicit operator T(Settable<T> value) => value.Value;
}

public class Query
{
  public bool MyQuery(Settable<IDictionary<string, object?>?>? customFields) => { return true; }
}

hc startup code:

        builder.BindRuntimeType<IDictionary<string, object>, AnyType>();

actual:

input SettableOfIDictionaryOfStringAndObjectInput {
  value: [Any!]!
}

expected:

input SettableOfIDictionaryOfStringAndObjectInput {
  value: Any
}

Spaier avatar Mar 17 '23 22:03 Spaier

I have encountered the same issue as @Spaier on the latest 13.8.1 version where builder.BindRuntimeType<IDictionary<string, object>, AnyType>(); results in schema with value: [Any!] instead of value: Any. The resulting schema is invalid and not accepted by graphql-codegen tool to generate Typescript typings for my schema :(

vintoware avatar Feb 16 '24 17:02 vintoware

Found a solution that works for me.

In your Startup add: services.AddGraphQLServer().AddType(new AnyType())

Then in your model add this:

[GraphQLType("Any")]
public IDictionary<string, string> Value { get; set; }

It's important to provide type name using string, not typeof. Then it correctly generates schema without array: value: Any

vintoware avatar Feb 19 '24 10:02 vintoware