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
- Host: GitHub
- URL: https://github.com/aeagle/graph-ql-poco
- Owner: aeagle
- License: mit
- Created: 2021-02-20T21:58:42.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-21T20:44:18.000Z (over 4 years ago)
- Last Synced: 2025-01-11T16:21:16.130Z (5 months ago)
- Topics: dapper, dotnet-core, graphql, graphql-net, sql
- Language: C#
- Homepage:
- Size: 33.2 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
}
}
```