Schema Builder
See original GitHub issueThe schema builder shall provide a simpler API to create a schema. Moreover, the goal of this issue is to create feature parity between schema-first, code-first and poco driven schemas. Furthermore, we want to simplify the type initialization process and make it easier to generate dynamic types like for Prisma-style filter objects.
Last but not least the current schema declaration API shall not be broken. The goal here would be that the old schema factories use the schema builder underneath. Users can then decide which API approach they like more.
We have started with a simple interface ISchemaBuilder
public interface ISchemaBuilder
{
ISchemaBuilder Use(FieldMiddleware middleware);
ISchemaBuilder AddSource(string sourceText);
ISchemaBuilder AddType(Type type);
ISchemaBuilder AddType(INamedType type);
ISchemaBuilder AddRootType(Type type, OperationType operation);
ISchemaBuilder AddRootType(ObjectType type, OperationType operation);
ISchemaBuilder AddResolver(FieldResolver resolver);
ISchemaBuilder AddBinding(object binding);
ISchemaBuilder AddServices(IServiceProvider services);
ISchema Create();
}
Currently we have two open issues:
How shall bindings work? This ones are mainly for the schema first approach: ISchemaBuilder AddBinding(object binding);
Further, we are pondering the idea of completely removing the service provider from the schema. So, with that ISchemaBuilder AddServices(IServiceProvider services);
would be removed.
The thinking here is that the services that you associate with the schema are not scoped and are not used during execution so they are a bit confusing to the user. Moreover, do we really want dependency injection into our types or should dependency injection be restricted to resolvers and middleware components etc.
Extensions
In order to keep a small builder interface but provide more convenience we will add some extension methods on the builder like the following:
public static class SchemaBuilderExtensions
{
public static ISchemaBuilder AddQueryType(
this ISchemaBuilder builder,
Type type)
{
return builder.AddRootType(type, OperationType.Query);
}
public static ISchemaBuilder AddQueryType(
this ISchemaBuilder builder,
ObjectType queryType)
{
return builder.AddRootType(queryType, OperationType.Query);
}
public static ISchemaBuilder AddQueryType<TQuery>(
this ISchemaBuilder builder)
{
return builder.AddRootType(typeof(TQuery), OperationType.Query);
}
}
Usage
ISchema schema = SchemaBuilder.New()
.AddQueryType<Bar>()
.AddSource("")
.Use(next => context => next(context))
.Create();
Type Initialization
We have to review how we can simplify the initialization API and open this up to be extended by users. Types should be immutable once the builder creates the schema. Moreover, we want to be able to use builder services that enable the user to change defaults like how we extract the names from clr types and so on.
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (11 by maintainers)
Top GitHub Comments
@RaduBuciuceanu
I have opened another issue and will add comments there.
https://github.com/ChilliCream/hotchocolate/issues/647
This should work, at least our parser will parse that correctly. I will write a little test tonight. If it is the bug we will fix it with the upcoming patch release next week.