From 3930b92996737c5a603a5f866a584fee4a63c748 Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Sun, 21 Aug 2022 20:39:12 +1000 Subject: [PATCH 1/2] Update entity-graphql.md --- .../c-net/server/entity-graphql.md | 53 ++++++------------- 1 file changed, 16 insertions(+), 37 deletions(-) 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..3207239655 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 @@ -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; - } - } } ``` From e5e050c9b5eae260a24a2cd93fa9b758ffb0d307 Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Sun, 21 Aug 2022 20:41:40 +1000 Subject: [PATCH 2/2] Update entity-graphql.md --- .../code/language-support/c-net/server/entity-graphql.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3207239655..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 ---