This repository has been archived by the owner on Aug 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
IApplicationBuilderExtensions.cs
93 lines (90 loc) · 3.13 KB
/
IApplicationBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
//using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Options;
namespace GraphQL.Middleware
{
/// <summary>
/// Extension methods for using GraphiQL with <see cref="IApplicationBuilder" />.
/// </summary>
public static class IApplicationBuilderExtensions
{
/// <summary>
/// Uses GraphiQL with the specified options.
/// </summary>
/// <param name="app">
/// The application builder.
/// </param>
/// <param name="options">
/// The options for the GraphiQL middleware.
/// </param>
/// <returns>
/// The modified application builder.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="app" /> or <paramref name="options" /> is null.
/// </exception>
public static IApplicationBuilder UseGraphQL(this IApplicationBuilder app , GraphQLOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<GraphQLMiddleware>(Options.Create(options));
}
/// <summary>
/// Uses GraphiQL with default options.
/// </summary>
/// <param name="app">
/// The application builder.
/// </param>
/// <returns>
/// The modified application builder.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="app" /> is null.
/// </exception>
public static IApplicationBuilder UseGraphiQL(this IApplicationBuilder app)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMiddleware<GraphiQLMiddleware>();
}
/// <summary>
/// Uses GraphiQL with the specified options.
/// </summary>
/// <param name="app">
/// The application builder.
/// </param>
/// <param name="options">
/// The options for the GraphiQL middleware.
/// </param>
/// <returns>
/// The modified application builder.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown if <paramref name="app" /> or <paramref name="options" /> is null.
/// </exception>
public static IApplicationBuilder UseGraphiQL(this IApplicationBuilder app , GraphiQLOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<GraphiQLMiddleware>(Options.Create(options));
}
}
}