An open API service indexing awesome lists of open source software.

https://github.com/aeagle/graph-ql-poco

Experimental Dapper based SQL resolver for GraphQL.NET to allow building a GraphQL schema from a POCO model
https://github.com/aeagle/graph-ql-poco

dapper dotnet-core graphql graphql-net sql

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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:

```csharp
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection Orders { get; set; } = new List();
}

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

And the setup:

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

Allows the following GraphQL query:

```graphql
customers {
id
name
orders {
id
name
}
}
```

or alternatively:

```graphql
orders {
id
name
customer {
id
name
}
}
```