{"id":13429481,"url":"https://github.com/JuergenGutsch/graphql-aspnetcore","last_synced_at":"2025-03-16T03:31:39.202Z","repository":{"id":39617542,"uuid":"94973363","full_name":"JuergenGutsch/graphql-aspnetcore","owner":"JuergenGutsch","description":"ASP.NET Core MiddleWare to create a GraphQL end-point","archived":true,"fork":false,"pushed_at":"2023-04-28T19:42:33.000Z","size":4256,"stargazers_count":183,"open_issues_count":7,"forks_count":31,"subscribers_count":5,"default_branch":"develop","last_synced_at":"2025-03-07T03:48:31.476Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JuergenGutsch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-21T07:00:26.000Z","updated_at":"2024-04-07T09:05:42.000Z","dependencies_parsed_at":"2024-06-19T06:14:30.854Z","dependency_job_id":"14f55335-018d-438d-9659-9a6ccbe93cba","html_url":"https://github.com/JuergenGutsch/graphql-aspnetcore","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuergenGutsch%2Fgraphql-aspnetcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuergenGutsch%2Fgraphql-aspnetcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuergenGutsch%2Fgraphql-aspnetcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JuergenGutsch%2Fgraphql-aspnetcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JuergenGutsch","download_url":"https://codeload.github.com/JuergenGutsch/graphql-aspnetcore/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822310,"owners_count":20353496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:00:40.332Z","updated_at":"2025-03-16T03:31:38.864Z","avatar_url":"https://github.com/JuergenGutsch.png","language":"C#","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","API"],"sub_categories":["API"],"readme":"# GraphQl.AspNetCore\n\n\u003e This repo is outdated. See [https://github.com/graphql-dotnet](https://github.com/graphql-dotnet) to use a really good GraphQL library for .NET\n\nThe feedback about [my last blog post about the GraphQL end-point in ASP.NET Core](http://asp.net-hacker.rocks/2017/05/29/graphql-and-aspnetcore.html) was amazing. That post was mentioned on reddit, many times shared on twitter, lInked on http://asp.net and - I'm pretty glad about that - it was mentioned in the ASP.NET Community Standup.\n\nBecause of that and because GraphQL is really awesome, I decided to make the GraphQL MiddleWare available as a NuGet package. I did some small improvements to make this MiddleWare more configurable and more easy to use in the `Startup.cs`\n\n# Branches \u0026 contributing \u0026 testing\n\nThe **master** branch is the stable branch and I don't axcept PRs to that branch. To contribute, please create PRs based on the **develop** branch. To play around with the latest changes, please also use the **develop** branch. \n\nChanges on the **develop** branch (\"next version\" branch) will be pushed as preview releases to [MyGet](https://www.myget.org/feed/juergengutsch/package/nuget/GraphQl.AspNetCore). To see whether this branch is stable, follow the builds on AppVeyor:\n[![Build status](https://ci.appveyor.com/api/projects/status/vxe22mwm1l2gw3b4/branch/develop?svg=true)](https://ci.appveyor.com/project/JuergenGutsch/graphql-aspnetcore/branch/develop)\n\nChanges on the **master** branch (\"current version\" branch) will be pushed as releases to [NuGet](https://www.nuget.org/packages/GraphQl.AspNetCore). To see whether this branch is stable, follow the builds on AppVeyor:\n[![Build status](https://ci.appveyor.com/api/projects/status/vxe22mwm1l2gw3b4/branch/master?svg=true)](https://ci.appveyor.com/project/JuergenGutsch/graphql-aspnetcore/branch/master)\n\n# Usage and short documentation\n\n## NuGet\nPreview builds on [MyGet](https://www.myget.org/feed/juergengutsch/package/nuget/GraphQl.AspNetCore) and release builds on [NuGet](https://www.nuget.org/packages/GraphQl.AspNetCore).\n\nInstall that package via Package Manager Console:\n\n~~~ powershell\nPM\u003e Install-Package GraphQl.AspNetCore\n~~~\n\nInstall via dotnet CLI:\n\n~~~ shell\ndotnet add package GraphQl.AspNetCore\n~~~\n\n## Using the library\n\nYou still need to configure your GraphQL schema using the graphql-dotnet library, as [described in my last post](http://asp.net-hacker.rocks/2017/05/29/graphql-and-aspnetcore.html). \n\nFirst configure your schema(s) in the `ConfigureServices` method in `Startup.cs`. Make sure all referenced graph types are registered as well so they can be resolved from the container.\n\n```csharp\n// Configure the default schema\nservices.AddGraphQl(schema =\u003e\n{\n    schema.SetQueryType\u003cBooksQuery\u003e();\n    schema.SetMutationType\u003cBooksMutation\u003e();\n});\n\n// Also register all graph types\nservices.AddSingleton\u003cBooksQuery\u003e();\nservices.AddSingleton\u003cBooksMutation\u003e();\nservices.AddSingleton\u003cBookType\u003e();\nservices.AddSingleton\u003cAuthorType\u003e();\nservices.AddSingleton\u003cPublisherType\u003e();\n// ... more types if needed\n```\n\nIn the `Configure` method, you add the GraphQL middleware like this:\n\nYou can use different ways to register the GraphQlMiddleware:\n\n```csharp\n// the simplest form to use GraphQl. defaults to '/graphql' with default options\napp.UseGraphQl();\n\n// or specify options only (default path)\napp.UseGraphQl(new GraphQlMiddlewareOptions\n{\n    FormatOutput = true, // default\n    ComplexityConfiguration = new ComplexityConfiguration()); //default\n});\n\napp.UseGraphQl(options =\u003e\n{\n    options.EnableMetrics = true;\n});\n\n// or specify path and options\n\napp.UseGraphQl(\"/graphql\", new GraphQlMiddlewareOptions\n{\n    FormatOutput = true, // default\n    ComplexityConfiguration = new ComplexityConfiguration()); //default\n});\n\n// or like this:\n\napp.UseGraphQl(\"/graph-api\", options =\u003e\n{\n    options.SchemaName = \"OtherSchema\"; // only if additional schemas were registered in ConfigureServices\n    //options.AuthorizationPolicy = \"Authenticated\"; // optional\n});\n```\n\nPersonally I prefer the second way, which is more readable in my opinion.\n\n## Options\n\nThe `GraphQlMiddlewareOptions` are pretty simple.\n\n* SchemaName: This specifies the registered schema name to use. Leave `null` for the default schema.\n* AuthorizationPolicy: This configures the authorization policy name to apply to the GraphQL endpoint.\n* FormatOutput: This property defines whether the output is prettified and indented for debugging purposes. The default is set to `true`.\n* ComplexityConfiguration: This property is used to customize the complexity configuration.\n* ExposeExceptions: This property controls whether exception details such as stack traces should be returned to clients. This defaults to `false` and should only be set to `true` in the Development environment.\n* EnableMetrics: Enable metrics defaults to `false`. See [GraphQL .net client documentation](https://github.com/graphql-dotnet/graphql-dotnet/blob/master/docs/src/learn.md#metrics) how to create a stats report.\n\nThis should be enough for the first time. If needed it is possible to expose the Newtonsoft.JSON settings, which are used in GraphQL library later on.\n\n# GraphQL.AspNetCore.Graphiql\n\nThis library provides a middleware to add a GraphiQL UI to your GraphQL endpoint. To learn more about it and the way I created it, read the blog post about it: [GraphiQL for ASP.NET Core](http://asp.net-hacker.rocks/2017/10/26/graphicl.html)\n\n## NuGet\n\nPreview builds on [MyGet](https://www.myget.org/feed/juergengutsch/package/nuget/GraphQl.AspNetCore.Graphiql) and release builds on [NuGet](https://www.nuget.org/packages/GraphQl.AspNetCore.Graphiql).\n\nInstall that package via Package Manager Console:\n\n```powershell\nPM\u003e Install-Package GraphQl.AspNetCore.Graphiql\n```\n\nInstall via dotnet CLI:\n\n```shell\ndotnet add package GraphQl.AspNetCore.Graphiql\n```\n\n## Using the library\n\nOpen your `Startup.cs` and configure the middleware in the `Configure` method.\n\nYou can use two different ways to register the GraphiqlMiddleware:\n\n```csharp\napp.UseGraphiql(\"/graphiql\", new GraphQlMiddlewareOptions\n{\n    GraphQlEndpoint = \"/graphql\"\n});\n\n\napp.UseGraphiql(\"/graphiql\", options =\u003e\n{\n    options.GraphQlEndpoint = \"/graphql\";\n});\n```\n\nPersonally I prefer the second way, which is more readable in my opinion.\n\nThe GraphQlEndpoint needs to match the path a GraphQL endpoint.\n\n## Options\n\nCurrently the options just have two properties:\n\n* GraphQlEndpoint: This is the path of your GraphQL end-point, configured with the GraphQlMiddleware. In theory it could be any possible path or URL that provides an GraphQL endpoint. Until now, I just tested it with the GraphQlMiddleware.\n\n# One more thing\n\nI would be happy, if you try this library and get me some feedback about it. A demo application to quickly start playing around with it, is [available here on GitHub](https://github.com/JuergenGutsch/graphql-aspnetcore/tree/develop/GraphQlDemo). Feel free to raise some issues and to create some PRs to improve this MiddleWare.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJuergenGutsch%2Fgraphql-aspnetcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJuergenGutsch%2Fgraphql-aspnetcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJuergenGutsch%2Fgraphql-aspnetcore/lists"}