juergengutsch - GraphQL.AspNetCore.Graphiql 1.0.4.59-preview
This is an implementation 'Graphiql' as a ASP.NET Core MiddleWare to easily add a UI for your GraphQL endpoint (http://github.com/graphql-dotnet/).
PM> Install-Package GraphQL.AspNetCore.Graphiql -Version 1.0.4.59-preview -Source https://www.myget.org/F/juergengutsch/api/v3/index.json
> nuget.exe install GraphQL.AspNetCore.Graphiql -Version 1.0.4.59-preview -Source https://www.myget.org/F/juergengutsch/api/v3/index.json
> dotnet add package GraphQL.AspNetCore.Graphiql --version 1.0.4.59-preview --source https://www.myget.org/F/juergengutsch/api/v3/index.json
<PackageReference Include="GraphQL.AspNetCore.Graphiql" Version="1.0.4.59-preview" />
Copy to clipboard
source https://www.myget.org/F/juergengutsch/api/v3/index.json
nuget GraphQL.AspNetCore.Graphiql ~> 1.0.4.59-preview
Copy to clipboard
> choco install GraphQL.AspNetCore.Graphiql --version 1.0.4.59-preview --source https://www.myget.org/F/juergengutsch/api/v2
Import-Module PowerShellGet
Register-PSRepository -Name "juergengutsch" -SourceLocation "https://www.myget.org/F/juergengutsch/api/v2"
Install-Module -Name "GraphQL.AspNetCore.Graphiql" -RequiredVersion "1.0.4.59-preview" -Repository "juergengutsch" -AllowPreRelease
Copy to clipboard
GraphQl.AspNetCore
The feedback about my last blog post about the GraphQL end-point in ASP.NET Core 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.
Because 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
Branches & contributing & testing
The 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.
Changes on the develop branch ("next version" branch) will be pushed as preview releases to MyGet. To see whether this branch is stable, follow the builds on AppVeyor:
Changes on the master branch ("current version" branch) will be pushed as releases to NuGet. To see whether this branch is stable, follow the builds on AppVeyor:
Usage and short documentation
NuGet
Install that package via Package Manager Console:
PM> Install-Package GraphQl.AspNetCore -Pre
Install via dotnet CLI:
dotnet add package GraphQl.AspNetCore --version 1.0.0-preview1
Using the library
You still need to configure your GraphQL schema using the graphql-dotnet library, as described in my last post.
First 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.
// Configure the default schema
services.AddGraphQl(schema =>
{
schema.SetQueryType<BooksQuery>();
schema.SetMutationType<BooksMutation>();
});
// Also register all graph types
services.AddSingleton<BooksQuery>();
services.AddSingleton<BooksMutation>();
services.AddSingleton<BookType>();
services.AddSingleton<AuthorType>();
services.AddSingleton<PublisherType>();
In the Configure
method, you add the GraphQL middleware like this:
You can use two different ways to register the GraphQlMiddleware:
app.UseGraphQl("/graphql", new GraphQlMiddlewareOptions
{
FormatOutput = true, // default
ComplexityConfiguration = new ComplexityConfiguration()); //default
});
// or like this:
app.UseGraphQl("/graph-api", options =>
{
options.SchemaName = "OtherSchema"; // only if additional schemas were registered in ConfigureServices
//options.AuthorizationPolicy = "Authenticated"; // optional
});
Personally I prefer the second way, which is more readable in my opinion.
Options
The GraphQlMiddlewareOptions
are pretty simple.
- SchemaName: This specifies the registered schema name to use. Leave
null
for the default schema. - AuthorizationPolicy: This configures the authorization policy name to apply to the GraphQL endpoint.
- FormatOutput: This property defines whether the output is prettified and indented for debugging purposes. The default is set to
true
. - ComplexityConfiguration: This property is used to customize the complexity configuration.
- 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 totrue
in the Development environment.
This 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.
GraphQL.AspNetCore.Graphiql
This 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
NuGet
There's no NuGet Package available yet. I will provide one as soon as possible.
Using the library
Open your Startup.cs
and configure the middleware in the Configure
method.
You can use two different ways to register the GraphiqlMiddleware:
app.UseGraphiql("/graphiql", new GraphQlMiddlewareOptions
{
GraphQlEndpoint = "/graphql"
});
app.UseGraphiql("/graphiql", options =>
{
options.GraphQlEndpoint = "/graphql";
});
Personally I prefer the second way, which is more readable in my opinion.
The GraphQlEndpoint needs to match the paht a GraphQL endpoint.
Options
Currently the options just have two properties:
- 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.
One more thing
I 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. Feel free to raise some issues and to create some PRs to improve this MiddleWare.
-
.NETStandard 2.0
- Microsoft.AspNetCore (>= 2.0.0)
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
- Microsoft.Extensions.Logging.Debug (>= 2.0.0)
- .NETStandard 2.0: 2.0.0.0
OwnersJürgen Gutsch |
AuthorsJürgen Gutsch |
Project URLhttps://github.com/JuergenGutsch/graphql-aspnetcore |
LicenseMIT |
TagsASP.NET Core, GraphGL, Graphiql, MiddleWare |
Info65 total downloads |
2 downloads for version 1.0.4.59-preview |
Download (7.37 KB) |
Found on the current feed only |
Package history
Version | Size | Last updated | Downloads | Mirrored? | |||
---|---|---|---|---|---|---|---|
1.1.5 | 7.86 KB | Tue, 24 Sep 2019 05:41:14 GMT | 3 | ||||
1.1.4 | 7.35 KB | Mon, 11 Mar 2019 06:51:26 GMT | 10 | ||||
1.0.4.63-preview | 7.41 KB | Tue, 02 Oct 2018 07:07:48 GMT | 4 | ||||
1.0.4.62-preview | 7.37 KB | Mon, 17 Sep 2018 09:34:17 GMT | 3 | ||||
1.0.4.61-preview | 7.37 KB | Thu, 19 Apr 2018 06:33:50 GMT | 3 | ||||
1.0.4.60-preview | 7.36 KB | Wed, 18 Apr 2018 20:31:45 GMT | 3 | ||||
1.0.4.59-preview | 7.37 KB | Thu, 12 Apr 2018 06:31:54 GMT | 2 | ||||
1.0.4.58-preview | 7.37 KB | Mon, 09 Apr 2018 06:10:52 GMT | 3 | ||||
1.0.4.57-preview | 7.37 KB | Fri, 23 Mar 2018 20:30:12 GMT | 3 | ||||
1.0.4.56-preview | 7.37 KB | Wed, 21 Feb 2018 21:36:09 GMT | 4 | ||||
1.0.4.54-preview | 7.37 KB | Wed, 21 Feb 2018 21:29:25 GMT | 3 | ||||
1.0.4.49-preview | 7.36 KB | Wed, 21 Feb 2018 20:30:21 GMT | 3 | ||||
1.0.4.47-preview | 7.36 KB | Wed, 21 Feb 2018 20:19:03 GMT | 3 | ||||
1.0.4.46-preview | 7.37 KB | Wed, 21 Feb 2018 05:50:49 GMT | 4 | ||||
1.0.4.45-preview | 7.37 KB | Thu, 21 Dec 2017 21:51:32 GMT | 3 | ||||
1.0.4.44-preview | 7.37 KB | Thu, 21 Dec 2017 21:43:00 GMT | 3 | ||||
1.0.4-preview-43 | 7.37 KB | Thu, 21 Dec 2017 21:39:53 GMT | 4 | ||||
1.0.4-preview-42-preview1-42 | 7.39 KB | Thu, 21 Dec 2017 21:36:55 GMT | 4 |