GraphQL.Server.Ui.Voyager
8.3.3
dotnet add package GraphQL.Server.Ui.Voyager --version 8.3.3
NuGet\Install-Package GraphQL.Server.Ui.Voyager -Version 8.3.3
<PackageReference Include="GraphQL.Server.Ui.Voyager" Version="8.3.3" />
<PackageVersion Include="GraphQL.Server.Ui.Voyager" Version="8.3.3" />
<PackageReference Include="GraphQL.Server.Ui.Voyager" />
paket add GraphQL.Server.Ui.Voyager --version 8.3.3
#r "nuget: GraphQL.Server.Ui.Voyager, 8.3.3"
#:package GraphQL.Server.Ui.Voyager@8.3.3
#addin nuget:?package=GraphQL.Server.Ui.Voyager&version=8.3.3
#tool nuget:?package=GraphQL.Server.Ui.Voyager&version=8.3.3
ASP.NET Core GraphQL Server driven by GraphQL.NET
GraphQL ASP.NET Core server on top of GraphQL.NET. HTTP transport compatible with the GraphQL over HTTP draft specification. WebSocket transport compatible with both subscriptions-transport-ws and graphql-ws subscription protocols. The transport format of all messages is supposed to be JSON.
Provides the following packages:
You can install the latest stable versions via NuGet. Also you can get all preview versions from GitHub Packages. Note that GitHub requires authentication to consume the feed. See more information here.
| ⚠️ When upgrading from prior versions, please remove references to these old packages ⚠️ |
|---|
| GraphQL.Server.Core |
| GraphQL.Server.Authentication.AspNetCore |
| GraphQL.Server.Transports.AspNetCore.NewtonsoftJson |
| GraphQL.Server.Transports.AspNetCore.SystemTextJson |
| GraphQL.Server.Transports.Subscriptions.Abstractions |
| GraphQL.Server.Transports.Subscriptions.WebSockets |
| GraphQL.Server.Transports.WebSocktes |
Description
This package is designed for ASP.NET Core (2.1 through 9.0) to facilitate easy set-up of GraphQL requests
over HTTP. The code is designed to be used as middleware within the ASP.NET Core pipeline,
serving GET, POST or WebSocket requests. GET requests process requests from the query string.
POST requests can be in the form of JSON requests, form submissions, or raw GraphQL strings.
Form submissions either accepts query, operationName, variables and extensions parameters,
or operations and map parameters along with file uploads as defined in the
GraphQL multipart request spec.
WebSocket requests can use the graphql-ws or graphql-transport-ws WebSocket sub-protocol,
as defined in the apollographql/subscriptions-transport-ws
and enisdenjo/graphql-ws repositories, respectively.
The middleware can be configured through the IApplicationBuilder or IEndpointRouteBuilder
builder interfaces. Alternatively, route handlers (such as MapGet and MapPost) can return
a GraphQLExecutionHttpResult for direct GraphQL execution, or ExecutionResultHttpResult for
returning pre-executed GraphQL responses. Similarly, GraphQLExecutionActionResult
and ExecutionResultActionResult classes can be used to return GraphQL responses from
controller actions.
Authorization is also supported with the included AuthorizationValidationRule. It will
scan GraphQL documents and validate that the schema and all referenced output graph types, fields of
output graph types, and query arguments meet the specified policy and/or roles held by the
authenticated user within the ASP.NET Core authorization framework. It does not validate
any policies or roles specified for input graph types, fields of input graph types, or
directives. It skips validations for fields or fragments that are marked with the @skip or
@include directives.
Migration from older version
Configuration
Typical configuration with HTTP middleware
First add either the GraphQL.Server.All nuget package or the GraphQL.Server.Transports.AspNetCore
nuget package to your application. Referencing the "all" package will include the UI middleware
packages. These packages depend on GraphQL version 8.2.1 or later.
Then update your Program.cs or Startup.cs to configure GraphQL, registering the schema
and the serialization engine as a minimum. Configure WebSockets and GraphQL in the HTTP
pipeline by calling UseWebSockets and UseGraphQL at the appropriate point.
Finally, you may also include some UI middleware for easy testing of your GraphQL endpoint
by calling UseGraphQLGraphiQL or a similar method at the appropriate point.
Below is a complete sample of a .NET 6 console app that hosts a GraphQL endpoint at
http://localhost:5000/graphql:
Project file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GraphQL.Server.All" Version="7.0.0" />
</ItemGroup>
</Project>
Program.cs file
using GraphQL;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGraphQL(b => b
.AddAutoSchema<Query>() // schema
.AddSystemTextJson()); // serializer
var app = builder.Build();
app.UseDeveloperExceptionPage();
app.UseWebSockets();
app.UseGraphQL("/graphql"); // url to host GraphQL endpoint
app.UseGraphQLGraphiQL(
"/", // url to host GraphiQL at
new GraphQL.Server.Ui.GraphiQL.GraphiQLOptions
{
GraphQLEndPoint = "/graphql", // url of GraphQL endpoint
SubscriptionsEndPoint = "/graphql", // url of GraphQL endpoint
});
await app.RunAsync();
Schema
public class Query
{
public static string Hero() => "Luke Skywalker";
}
Sample request url
http://localhost:5000/graphql?query={hero}
Sample response
{"data":{"hero":"Luke Skywalker"}}
Basic options
By default, the middleware will be installed with these configurable options:
- GET, POST, and WebSocket requests are all enabled
- Form content types are disabled, and cross-site request forgery (CSRF) protection is enabled
- There are no authentication or authorization requirements
- The default response content type is
application/graphql-response+json - The middleware will use the default schema instance
To configure these options, pass a confiuguration delegate to the UseGraphQL
method as demonstrated below:
app.UseGraphQL("/graphql", opts => {
opts.ReadFormOnPost = true;
});
Configuration of these options and more are further described below in this document.
Configuration with endpoint routing
To use endpoint routing, call MapGraphQL from inside the endpoint configuration
builder rather than