{"id":13429486,"url":"https://github.com/JosephWoodward/graphiql-dotnet","last_synced_at":"2025-03-16T03:31:42.249Z","repository":{"id":60773488,"uuid":"94582963","full_name":"josephwoodward/graphiql-dotnet","owner":"josephwoodward","description":"GraphiQL middleware for ASP.NET Core","archived":false,"fork":false,"pushed_at":"2020-03-27T19:25:35.000Z","size":722,"stargazers_count":142,"open_issues_count":14,"forks_count":27,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-02-27T23:05:39.752Z","etag":null,"topics":["csharp","dotnet-core","graphiql","graphiql-editor","graphql"],"latest_commit_sha":null,"homepage":"","language":"CSS","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/josephwoodward.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}},"created_at":"2017-06-16T21:36:23.000Z","updated_at":"2024-07-30T07:12:13.000Z","dependencies_parsed_at":"2022-10-04T15:26:04.991Z","dependency_job_id":null,"html_url":"https://github.com/josephwoodward/graphiql-dotnet","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwoodward%2Fgraphiql-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwoodward%2Fgraphiql-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwoodward%2Fgraphiql-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephwoodward%2Fgraphiql-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josephwoodward","download_url":"https://codeload.github.com/josephwoodward/graphiql-dotnet/tar.gz/refs/heads/master","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":["csharp","dotnet-core","graphiql","graphiql-editor","graphql"],"created_at":"2024-07-31T02:00:40.453Z","updated_at":"2025-03-16T03:31:41.871Z","avatar_url":"https://github.com/josephwoodward.png","language":"CSS","funding_links":[],"categories":["Frameworks, Libraries and Tools","框架, 库和工具","API"],"sub_categories":["API"],"readme":"![](https://raw.githubusercontent.com/JosephWoodward/graphiql-dotnet/master/assets/logo_128_128.png)\n\n# GraphiQL.NET\n\n![.NET Core](https://github.com/JosephWoodward/graphiql-dotnet/workflows/.NET%20Core/badge.svg)\n\nGraphiQL middleware for ASP.NET Core - try the [live demo here](http://graphql.org/swapi-graphql/).\n\n## What is GraphiQL.NET?\n\nGraphiQL.NET is a piece of .NET Core middleware that bundles graphiql into it saving you from managing additional frontend dependencies, whilst also giving you control over the routes it's avaialble on any provide you with a means of authentication. \n\nGraphiQL.NET features include:\n\n- The full GraphiQl experience\n- Customisation of GraphiQL routes\n- Authentication\n\n![GraphiQL for ASP.NET Core](https://raw.githubusercontent.com/JosephWoodward/graphiql-dotnet/master/assets/screenshot.png)\n\n\n## Setup\n\nThe GraphiQL.NET middleware can be [found on NuGet here](https://www.nuget.org/packages/graphiql/)\n\nYou can install GraphiQL.NET by copying and pasting the following command into your Package Manager Console within Visual Studio (Tools \u003e NuGet Package Manager \u003e Package Manager Console).\n\n```\nInstall-Package graphiql\n```\n\nAlternatively you can install it using the .NET Core CLI using the following command:\n\n```\ndotnet add package graphiql\n```\n\n## Getting Started\n\nOnce installed you can add GraphiQL.NET to your ASP.NET Core application by adding the `app.UseGraphiQl()` middleware to the `Configure` method within your `Startup.cs` file.\n\n**Note: Be sure to call `UseGraphiQl()` before `UseMvc()`.**\n\n```csharp\n\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)\n{\n    // Adding this makes graphiql UI available at /graphql \n    app.UseGraphiQl();\n\n    app.UseMvc();\n}\n```\n\n## Configuration\n---\n### Configure Graphiql route\n\nBy default GraphiQL lives on the `/graphql` endpoint, however this can be changed by passing your chosen path to the `app.UseGraphiQl();` entry point method:\n\n```csharp\napp.UseGraphiQl('/whatever/graphiql');\n```\n\n\n### Configure Graphql API address\n\nYou can also specify GraphiQl endpoint independent of your GraphQL API, this is especially useful if you're hosting in IIS in a virtual application (ie `myapp.com/1.0/...`) or hosting API and documentation separately.\n\n```csharp\npublic void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)\n{\n    app.UseGraphiQl(\"/graphql\", \"/v1/yourapi\");\n\n    app.UseMvc();\n}\n```\n\nNow navigating to `/graphql` will display the GraphiQL UI, but your GraphQL API will live under the `/v1/yourapi` route.\n\n### Configuration via `IServiceCollection`\n\nAlternatively you can configure the aforementioned routes via `IServiceCollection` within `ConfigureServices` or your `Startup.cs` file:\n\n```csharp\n//Startup.cs\n\npublic void ConfigureServices(IServiceCollection services)\n{\n    ...\n\n\tservices.AddGraphiQl(x =\u003e\n\t{\n\t\tx.GraphiQlPath = \"/graphiql-ui\";\n\t\tx.GraphQlApiPath = \"graphql\";\n\t});\n\n    ...\n}\n\npublic void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)\n{\n\tapp.UseGraphiQl();\n\t...\n}\n```\n\n### Configuration via `ConfigureOptions\u003cT\u003e`\n\nYou can also use the `IConfigureOptions\u003cT\u003e` interface:\n\n```csharp\n// GraphiQlTestOptionsSetup.cs\n\ninternal class GraphiQlTestOptionsSetup : IConfigureOptions\u003cGraphiQlOptions\u003e\n{\n    public void Configure(GraphiQlOptions options)\n    {\n        options.GraphiQlPath = \"/graphiql-ui\";\n        options.GraphQlApiPath = \"graphql\";\n    }\n}\n\n```\nThen you just have to register it with your Ioc Container:\n```csharp\n//Startup.cs\n\npublic void ConfigureServices(IServiceCollection services)\n{\n    ...\n    services.AddTransient\u003cIConfigureOptions\u003cGraphiQlOptions\u003e, GraphiQlTestOptionsSetup\u003e();z\n    ...\n}\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJosephWoodward%2Fgraphiql-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FJosephWoodward%2Fgraphiql-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FJosephWoodward%2Fgraphiql-dotnet/lists"}