graphql-platform
graphql-platform copied to clipboard
BindRuntimeType cannot bind arrays
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!
}
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
}
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 :(
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