From e4d792a7911f5716f1b6b6427485c93d5af9edf7 Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Tue, 20 Jul 2021 22:22:23 +1000 Subject: [PATCH 1/2] update EntityGraphQL information --- .../c-net/server/entity-graphql.md | 46 ++++++++++++++++++- 1 file changed, 45 insertions(+), 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 be3cc954b3..07cbd74c6c 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,8 +1,52 @@ --- name: Entity GraphQL -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) +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/lukemurray/EntityGraphQL github: lukemurray/EntityGraphQL --- +```csharp +// expose an exisiting data model with ASP.NET & EF Core +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()); + } +} +// 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 174614e9c2040b8f9634d381291cdbbade5f171f Mon Sep 17 00:00:00 2001 From: Luke Murray Date: Sat, 24 Jul 2021 14:38:42 +1000 Subject: [PATCH 2/2] update URL --- .../code/language-support/c-net/server/entity-graphql.md | 4 ++-- 1 file changed, 2 insertions(+), 2 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 07cbd74c6c..32f4b27e28 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,8 +1,8 @@ --- 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/lukemurray/EntityGraphQL -github: lukemurray/EntityGraphQL +url: https://github.com/EntityGraphQL/EntityGraphQL +github: EntityGraphQL/EntityGraphQL --- ```csharp