• Stars
    star
    142
  • Rank 257,310 (Top 6 %)
  • Language
    CSS
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

GraphiQL middleware for ASP.NET Core

GraphiQL.NET

.NET Core

GraphiQL middleware for ASP.NET Core - try the live demo here.

What is GraphiQL.NET?

GraphiQL.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.

GraphiQL.NET features include:

  • The full GraphiQl experience
  • Customisation of GraphiQL routes
  • Authentication

GraphiQL for ASP.NET Core

Setup

The GraphiQL.NET middleware can be found on NuGet here

You can install GraphiQL.NET by copying and pasting the following command into your Package Manager Console within Visual Studio (Tools > NuGet Package Manager > Package Manager Console).

Install-Package graphiql

Alternatively you can install it using the .NET Core CLI using the following command:

dotnet add package graphiql

Getting Started

Once 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.

Note: Be sure to call UseGraphiQl() before UseMvc().

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // Adding this makes graphiql UI available at /graphql 
    app.UseGraphiQl();

    app.UseMvc();
}

Configuration


Configure Graphiql route

By default GraphiQL lives on the /graphql endpoint, however this can be changed by passing your chosen path to the app.UseGraphiQl(); entry point method:

app.UseGraphiQl('/whatever/graphiql');

Configure Graphql API address

You 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.

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseGraphiQl("/graphql", "/v1/yourapi");

    app.UseMvc();
}

Now navigating to /graphql will display the GraphiQL UI, but your GraphQL API will live under the /v1/yourapi route.

Configuration via IServiceCollection

Alternatively you can configure the aforementioned routes via IServiceCollection within ConfigureServices or your Startup.cs file:

//Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...

	services.AddGraphiQl(x =>
	{
		x.GraphiQlPath = "/graphiql-ui";
		x.GraphQlApiPath = "graphql";
	});

    ...
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
	app.UseGraphiQl();
	...
}

Configuration via ConfigureOptions<T>

You can also use the IConfigureOptions<T> interface:

// GraphiQlTestOptionsSetup.cs

internal class GraphiQlTestOptionsSetup : IConfigureOptions<GraphiQlOptions>
{
    public void Configure(GraphiQlOptions options)
    {
        options.GraphiQlPath = "/graphiql-ui";
        options.GraphQlApiPath = "graphql";
    }
}

Then you just have to register it with your Ioc Container:

//Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddTransient<IConfigureOptions<GraphiQlOptions>, GraphiQlTestOptionsSetup>();z
    ...
}
---

More Repositories

1

GlobalExceptionHandlerDotNet

Exception handling as a convention in the ASP.NET Core request pipeline
C#
267
star
2

Serilog-Sinks-Loki

A Serilog Sink for Loki, Grafana's new Prometheus inspired log aggregator
C#
126
star
3

VSCodeILViewer

A Visual Studio Code C# IL (Intermediate Language) Viewer
C#
93
star
4

Angular2PianoNoteTrainingGame

Angular 2 based piano note training game
TypeScript
83
star
5

DotNetInstallSdkGlobalTool

Global tool to make installing .NET version that little bit easier
C#
16
star
6

gin-errorhandling

Go
10
star
7

SlugityDotNet

Simple class library to sanitize text and turn it into a search engine friendly URL
C#
9
star
8

RouteUrlRedirector

ASP.NET Core MVC Middleware for redirecting old paths to new paths using either 301 or 302 redirects
C#
9
star
9

CKFinderJcrop

CKFinder plugin of a much needed image cropping feature using the JQuery based JCrop
JavaScript
5
star
10

tftp-server

A TFTP Server written in Go
Go
4
star
11

httpclient-interception-go

Go
3
star
12

chaosproxy

A simple means of introducing chaos into your infrastructure for Windows, Mac and Linux.
Go
2
star
13

git-hotspot

Go
2
star
14

TrafficCop

Simple rules based traffic manager for ASP.NET MVC
C#
2
star
15

SeleniumGridDotNetCore

C#
1
star
16

OpenApiApprovalTesting

C#
1
star
17

otelnats

1
star
18

NServiceBusPlayground

Heard lots of interesting things about NServiceBus so want to have a play
C#
1
star
19

BlazorDemo

C#
1
star
20

RazorPlayground

C#
1
star
21

WorldsSmallestViolin

Lunchtime Android project perfect for winding friends up.
Java
1
star
22

ExceptionRerouter

A simple exception rerouting library for ASP.NET MVC.
C#
1
star
23

AzureAdTemp

C#
1
star
24

HttpLogger

Go
1
star
25

NetworkProgrammingInGo

Go
1
star
26

TypeScriptSpaceShooter

A really simple Javascript based game I've been working on during lunchtime using TypeScript.
JavaScript
1
star