Skip to content

Commit 6fdfb1b

Browse files
authored
Update entity-graphql.md (#1263)
* Update entity-graphql.md * Update entity-graphql.md
1 parent 7b87a5d commit 6fdfb1b

File tree

1 file changed

+17
-38
lines changed

1 file changed

+17
-38
lines changed
Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: Entity GraphQL
33
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.
4-
url: https://github.com/EntityGraphQL/EntityGraphQL
4+
url: https://entitygraphql.github.io
55
github: EntityGraphQL/EntityGraphQL
66
---
77

@@ -10,43 +10,22 @@ github: EntityGraphQL/EntityGraphQL
1010
public class Startup {
1111
public void ConfigureServices(IServiceCollection services)
1212
{
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>());
13+
services.AddDbContext<DemoContext>();
14+
// Auto build a schema from DemoContext. Alternatively you can build one from scratch
15+
services.AddGraphQLSchema<DemoContext>(options =>
16+
{
17+
// modify the schema (add/remove fields or types), add other services
18+
});
19+
}
20+
21+
public void Configure(IApplicationBuilder app, DemoContext db)
22+
{
23+
app.UseRouting();
24+
app.UseEndpoints(endpoints =>
25+
{
26+
// defaults to /graphql endpoint
27+
endpoints.MapGraphQL<DemoContext>();
28+
});
1729
}
18-
}
19-
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-
}
5130
}
5231
```

0 commit comments

Comments
 (0)