diff --git a/src/content/code/language-support/c-net/server/entity-graphql.md b/src/content/code/language-support/c-net/server/entity-graphql.md index 32f4b27e28..d7d391c19e 100644 --- a/src/content/code/language-support/c-net/server/entity-graphql.md +++ b/src/content/code/language-support/c-net/server/entity-graphql.md @@ -1,7 +1,7 @@ --- name: Entity GraphQL 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. -url: https://github.com/EntityGraphQL/EntityGraphQL +url: https://entitygraphql.github.io github: EntityGraphQL/EntityGraphQL --- @@ -10,43 +10,22 @@ github: EntityGraphQL/EntityGraphQL public class Startup { public void ConfigureServices(IServiceCollection services) { - services.AddControllers().AddNewtonsoftJson(); - services.AddDbContext(); - // Build a schema from your data model (See docs on how to extend, modify or build manually as well as merge other data sources). - services.AddSingleton(SchemaBuilder.FromObject()); + services.AddDbContext(); + // Auto build a schema from DemoContext. Alternatively you can build one from scratch + services.AddGraphQLSchema(options => + { + // modify the schema (add/remove fields or types), add other services + }); + } + + public void Configure(IApplicationBuilder app, DemoContext db) + { + app.UseRouting(); + app.UseEndpoints(endpoints => + { + // defaults to /graphql endpoint + endpoints.MapGraphQL(); + }); } -} - -// expose an endpoint with ASP.NET -[Route("api/[controller]")] -public class QueryController : Controller -{ - private readonly MyDbContext _dbContext; - private readonly SchemaProvider _schemaProvider; - - public QueryController(MyDbContext dbContext, SchemaProvider schemaProvider) - { - this._dbContext = dbContext; - this._schemaProvider = schemaProvider; - } - - [HttpPost] - public object Post([FromBody]QueryRequest query) - { - try - { - var results = _schemaProvider.ExecuteQuery(query, _dbContext, null, null); - if (results.Errors?.Count > 0) - { - // log error - return StatusCode(StatusCodes.Status500InternalServerError, results); - } - return results; - } - catch (Exception) - { - return HttpStatusCode.InternalServerError; - } - } } ```