/// <summary> /// Enables a GraphiQLServer using the specified settings /// </summary> /// <param name="applicationBuilder"></param> /// <param name="settings">The settings of the Middleware</param> /// <returns></returns> public static IApplicationBuilder UseGraphiQLServer(this IApplicationBuilder applicationBuilder, GraphiQLOptions settings) { if (settings == null) { settings = new GraphiQLOptions(); } applicationBuilder.UseMiddleware <GraphiQLMiddleware>(settings); return(applicationBuilder); }
public void SubscriptionPath_Set_To_Empty_ArgumentException() { // arrange var options = new GraphiQLOptions(); // act Action action = () => options.SubscriptionPath = default; // act Assert.Throws <ArgumentException>(action); }
public void Default_Values() { // arrange // act var options = new GraphiQLOptions(); // act Assert.Equal("/graphiql", options.Path); Assert.Equal("/", options.QueryPath); Assert.Equal("/", options.SubscriptionPath); }
private static IApplicationBuilder UseGraphiQLSettingsMiddleware( this IApplicationBuilder applicationBuilder, GraphiQLOptions options) { return(applicationBuilder.Map( options.Path.Add(new PathString("/settings.js")), #if ASPNETCLASSIC app => app.Use <SettingsMiddleware>(options))); #else app => app.UseMiddleware <SettingsMiddleware>(options)); #endif }
public void SetPath() { // arrange var options = new GraphiQLOptions(); // act options.Path = new PathString("/foo"); // act Assert.Equal("/foo", options.Path.ToString()); Assert.Equal("/", options.QueryPath.ToString()); Assert.Equal("/", options.SubscriptionPath.ToString()); }
public static IApplicationBuilder UseGraphiQL( this IApplicationBuilder applicationBuilder, GraphiQLOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } return(applicationBuilder .UseGraphiQLSettingsMiddleware(options) .UseGraphiQLFileServer(options.Path)); }
public void SetQueryPath() { // arrange var options = new GraphiQLOptions(); // act options.QueryPath = "/foo"; // act Assert.Equal("/foo/graphiql", options.Path); Assert.Equal("/foo", options.QueryPath); Assert.Equal("/foo", options.SubscriptionPath); }
public async Task Default_Values() { // arrange var options = new GraphiQLOptions(); TestServer server = CreateServer(options); string settingsUri = "/graphiql/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public void SetQueryPath_Then_SetSubscriptionPath() { // arrange var options = new GraphiQLOptions(); // act options.QueryPath = new PathString("/foo"); options.SubscriptionPath = new PathString("/bar"); // act Assert.Equal("/foo/graphiql", options.Path.ToString()); Assert.Equal("/foo", options.QueryPath.ToString()); Assert.Equal("/bar", options.SubscriptionPath.ToString()); }
public async Task SetQueryPath() { // arrange var options = new GraphiQLOptions(); options.QueryPath = new PathString("/foo"); TestServer server = CreateServer(options); string settingsUri = "/foo/graphiql/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task Disable_Subscriptions() { // arrange var options = new GraphiQLOptions(); options.EnableSubscription = false; TestServer server = CreateServer(options); string settingsUri = "/graphiql/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public SettingsMiddleware( RequestDelegate next, GraphiQLOptions options) #if ASPNETCLASSIC : base(next) #endif { #if !ASPNETCLASSIC Next = next; #endif _options = options ?? throw new ArgumentNullException(nameof(options)); Uri uiPath = UriFromPath(options.Path); Uri queryPath = UriFromPath(options.QueryPath); Uri subscriptionPath = UriFromPath(options.SubscriptionPath); _queryPath = uiPath.MakeRelativeUri(queryPath).ToString(); _subscriptionPath = uiPath.MakeRelativeUri(subscriptionPath) .ToString(); }
/// <summary> /// Enables a GraphiQLServer using the specified settings /// </summary> /// <param name="applicationBuilder"></param> /// <param name="settings">The settings of the Middleware</param> /// <returns></returns> public static IApplicationBuilder UseGraphiQLServer(this IApplicationBuilder applicationBuilder, GraphiQLOptions settings) { if (settings == null) { throw new ArgumentNullException(nameof(settings)); } applicationBuilder.UseMiddleware <GraphiQLMiddleware>(settings); return(applicationBuilder); }
public GraphiQLMiddleware(RequestDelegate next, GraphiQLOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> /// Add the GraphiQL middleware to the HTTP request pipeline /// </summary> /// <param name="endpoints">Defines a contract for a route builder in an application. A route builder specifies the routes for an application.</param> /// <param name="options">Options to customize <see cref="GraphiQLMiddleware"/>. If not set, then the default values will be used.</param> /// <param name="pattern">The route pattern.</param> /// <returns>The <see cref="IApplicationBuilder"/> received as parameter</returns> public static GraphiQLEndpointConventionBuilder MapGraphQLGraphiQL(this IEndpointRouteBuilder endpoints, GraphiQLOptions options, string pattern = "ui/graphiql") { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware <GraphiQLMiddleware>(options ?? new GraphiQLOptions()).Build(); return(new GraphiQLEndpointConventionBuilder(endpoints.MapGet(pattern, requestDelegate).WithDisplayName("GraphiQL"))); }
public GraphiQLPageModel(GraphiQLOptions options) { _options = options; }
private TestServer CreateServer(GraphiQLOptions options) { return(ServerFactory.Create( services => services.AddStarWars(), (app, sp) => app.UseGraphQL(sp).UseGraphiQL(options))); }
/// <summary> Adds middleware for GraphiQL using the specified options. </summary> /// <param name="app"> <see cref="IApplicationBuilder"/> to configure an application's request pipeline. </param> /// <param name="options"> Options to customize <see cref="GraphiQLMiddleware"/>. If not set, then the default values will be used. </param> /// <param name="path">The path to the GraphiQL endpoint which defaults to '/ui/graphiql'</param> /// <returns> The reference to provided <paramref name="app"/> instance. </returns> public static IApplicationBuilder UseGraphQLGraphiQL(this IApplicationBuilder app, GraphiQLOptions options, string path = "/ui/graphiql") { return(app.UseWhen( context => context.Request.Path.StartsWithSegments(path, out var remaining) && string.IsNullOrEmpty(remaining), b => b.UseMiddleware <GraphiQLMiddleware>(options ?? new GraphiQLOptions()))); }
public GraphiQLPageModel(GraphiQLOptions settings) { this.settings = settings; }
/// <summary> Adds middleware for GraphiQL using the specified options. </summary> /// <param name="applicationBuilder"> <see cref="IApplicationBuilder"/> to configure an application's request pipeline. </param> /// <param name="options"> Options to customize <see cref="GraphiQLMiddleware"/>. If not set, then the default values will be used. </param> /// <returns> The reference to provided <paramref name="app"/> instance. </returns> public static IApplicationBuilder UseGraphiQLServer(this IApplicationBuilder applicationBuilder, GraphiQLOptions options = null) => applicationBuilder.UseMiddleware <GraphiQLMiddleware>(options ?? new GraphiQLOptions());