question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The 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:closed
  • Created 5 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelstaibcommented, Mar 23, 2019

@RaduBuciuceanu

I have opened another issue and will add comments there.

https://github.com/ChilliCream/hotchocolate/issues/647

1reaction
michaelstaibcommented, Mar 23, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Work with Schema Builder Unit - Trailhead
Use Schema Builder to create a schema for a given object model. Use Schema Builder to add a custom object to your schema....
Read more >
Schema Builder for Structured Data
Schema.dev's Schema Builder makes it as simple as point and click to generate the perfect JSON-LD structured data for dozens of Google supported...
Read more >
Design Your Own Data Model With Schema Builder
Schema Builder provides a dynamic environment for viewing and modifying all the objects and relationships in your app. This greatly simplifies the task...
Read more >
Schema Markup Builder, Tester and Deployer for Schema.org ...
Build, Test and Deploy Schema.org based Structured Data Markup - for FREE! Start with the Schema builder Chrome plugin that allows easy point...
Read more >
The Salesforce Schema Builder — What You Need to Know
Salesforce's schema builder shows Objects, fields and the relationships between them. Using it, you can add custom areas, Objects and relationships, and view ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found