Skip to content

Commit 3258bf1

Browse files
authored
Merge pull request graphql#1068 from lukemurray/patch-2
update EntityGraphQL information
2 parents 48de3b1 + d6436bc commit 3258bf1

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed
Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
11
---
22
name: Entity GraphQL
3-
description: .NET Core GraphQL library. Compiles to IQueryable to easily expose a schema from an existing data model (E.g. from an Entity Framework data model)
3+
description: A GraphQL library for .NET Core. Easily expose you data model as a GraphQL API or bring together multiple data sources into a single GraphQL schema.
44
url: https://github.com/EntityGraphQL/EntityGraphQL
55
github: EntityGraphQL/EntityGraphQL
66
---
77

8+
```csharp
9+
// expose an exisiting data model with ASP.NET & EF Core
10+
public class Startup {
11+
public void ConfigureServices(IServiceCollection services)
12+
{
13+
services.AddControllers().AddNewtonsoftJson();
14+
services.AddDbContext<MyDbContext>();
15+
// Build a schema from your data model (See docs on how to extend, modify or build manually as well as merge other data sources).
16+
services.AddSingleton(SchemaBuilder.FromObject<MyDbContext>());
17+
}
18+
}
819

20+
// expose an endpoint with ASP.NET
21+
[Route("api/[controller]")]
22+
public class QueryController : Controller
23+
{
24+
private readonly MyDbContext _dbContext;
25+
private readonly SchemaProvider<MyDbContext> _schemaProvider;
26+
27+
public QueryController(MyDbContext dbContext, SchemaProvider<MyDbContext> schemaProvider)
28+
{
29+
this._dbContext = dbContext;
30+
this._schemaProvider = schemaProvider;
31+
}
32+
33+
[HttpPost]
34+
public object Post([FromBody]QueryRequest query)
35+
{
36+
try
37+
{
38+
var results = _schemaProvider.ExecuteQuery(query, _dbContext, null, null);
39+
if (results.Errors?.Count > 0)
40+
{
41+
// log error
42+
return StatusCode(StatusCodes.Status500InternalServerError, results);
43+
}
44+
return results;
45+
}
46+
catch (Exception)
47+
{
48+
return HttpStatusCode.InternalServerError;
49+
}
50+
}
51+
}
52+
```

0 commit comments

Comments
 (0)