Skip to content

Experimental Dapper based SQL resolver for GraphQL.NET to allow building a GraphQL schema from a POCO model

License

Notifications You must be signed in to change notification settings

aeagle/graph-ql-poco

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

graph-ql-poco

An experiment with GraphQL.Net and a custom Dapper based SQL resolver which defines the GraphQL schema and queries a DB based on introspection of the model.

Given the model:

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection<Order> Orders { get; set; } = new List<Order>();
}

public class Order
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Customer Customer { get; set; }
}

And the setup:

services.SetupGraphQLSchema(
    schema => schema
        .DefaultResolver(
            new SQLResolver(
                () => new SqlConnection(
                    @"Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=GraphQLTest;Integrated Security=SSPI"
                )
            )
        )
        .Add<Customer>(x => x
            .EntityConfig(e => e.Table("Customers").Key(f => f.Id))
        )
        .Add<Order>(x => x
            .EntityConfig(e => e.Table("Orders").Key(f => f.Id))
        )
);

Allows the following GraphQL query:

customers {
  id
  name
  orders {
    id
    name
  }
}

or alternatively:

orders {
  id
  name
  customer {
    id
    name
  }
}

About

Experimental Dapper based SQL resolver for GraphQL.NET to allow building a GraphQL schema from a POCO model

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published