private static IApplicationBuilder UsePlaygroundSettingsMiddleware( this IApplicationBuilder applicationBuilder, PlaygroundOptions options) { return(applicationBuilder.Map( options.Path.Add(new PathString("/settings.js")), app => app.UseMiddleware <SettingsMiddleware>(options))); }
// ReSharper disable once SuggestBaseTypeForParameter public FormatController( IWebHostEnvironment webHostEnvironment, ILogger <FormatController> logger, IOptions <PlaygroundOptions> options) { this.webHostEnvironment = webHostEnvironment; this.logger = logger; this.options = options.Value; }
public void SubscriptionPath_Set_To_Empty_ArgumentException() { // arrange var options = new PlaygroundOptions(); // act Action action = () => options.SubscriptionPath = default; // act Assert.Throws <ArgumentException>(action); }
public void SetGraphQLEndpoint() { // arrange var options = new PlaygroundOptions(); // act options.GraphQLEndpoint = new Uri("https://localhost:5000/graphql"); // act Assert.Equal("https://localhost:5000/graphql", options.GraphQLEndpoint.AbsoluteUri); }
public void Default_Values() { // arrange // act var options = new PlaygroundOptions(); // act Assert.Equal("/playground", options.Path); Assert.Equal("/", options.QueryPath); Assert.Equal("/", options.SubscriptionPath); }
public void SetPath() { // arrange var options = new PlaygroundOptions(); // act options.Path = new PathString("/foo"); // act Assert.Equal("/foo", options.Path.ToString()); Assert.Equal("/", options.QueryPath.ToString()); Assert.Equal("/", options.SubscriptionPath.ToString()); }
public void SetQueryPath() { // arrange var options = new PlaygroundOptions(); // act options.QueryPath = "/foo"; // act Assert.Equal("/foo/playground", options.Path); Assert.Equal("/foo", options.QueryPath); Assert.Equal("/foo", options.SubscriptionPath); }
public void GraphQLEndpoint_Set_To_Null_Or_Invalid_Exceptions() { // arrange var options = new PlaygroundOptions(); // act Action invalidUriAction = () => options.GraphQLEndpoint = new Uri("not a uri"); Action nullUriAction = () => options.GraphQLEndpoint = new Uri(null); // act Assert.Throws <UriFormatException>(invalidUriAction); Assert.Throws <ArgumentNullException>(nullUriAction); }
public static IApplicationBuilder UsePlayground( this IApplicationBuilder applicationBuilder, PlaygroundOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } return(applicationBuilder .UsePlaygroundSettingsMiddleware(options) .UsePlaygroundFileServer(options.Path)); }
public async Task Default_Values() { // arrange var options = new PlaygroundOptions(); TestServer server = CreateServer(options); string settingsUri = "/playground/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task Disable_Subscriptions() { // arrange var options = new PlaygroundOptions(); options.EnableSubscription = false; TestServer server = CreateServer(options); string settingsUri = "/playground/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task SetQueryPath() { // arrange var options = new PlaygroundOptions(); options.QueryPath = "/foo"; TestServer server = CreateServer(options); string settingsUri = "/foo/playground/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task SetGraphQLEndpointWithSubscriptions() { // arrange var options = new PlaygroundOptions(); options.Path = "/bar"; options.GraphQLEndpoint = new Uri("https://microsoft.com/graphql"); TestServer server = CreateServer(options); string settingsUri = "/bar/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task SetGraphQLEndpoint() { // arrange var options = new PlaygroundOptions(); options.EnableSubscription = false; options.Path = "/foo-bar"; options.GraphQLEndpoint = new Uri("https://hotchocolate.io/graphql"); TestServer server = CreateServer(options); string settingsUri = "/foo-bar/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public SettingsMiddleware( RequestDelegate next, PlaygroundOptions 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(); }
// ReSharper disable once UnusedParameter.Local public PlaygroundTenantMiddleware(RequestDelegate next, IOspService ospService, PlaygroundOptions options) { _ospService = ospService; _options = options ?? throw new ArgumentNullException(nameof(options)); }
public PlaygroundPageModel(string graphQlEndPoint, PlaygroundOptions options) { _graphQlEndPoint = graphQlEndPoint; _options = options; }
/// <summary> /// Add the Playground 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="PlaygroundMiddleware"/>. 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 PlaygroundEndpointConventionBuilder MapGraphQLPlayground(this IEndpointRouteBuilder endpoints, PlaygroundOptions options, string pattern = "ui/playground") { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware <PlaygroundMiddleware>(options ?? new PlaygroundOptions()).Build(); return(new PlaygroundEndpointConventionBuilder(endpoints.MapGet(pattern, requestDelegate).WithDisplayName("GraphQL Playground"))); }
private TestServer CreateServer(PlaygroundOptions options) { return(ServerFactory.Create( services => services.AddStarWars(), app => app.UseGraphQL().UsePlayground(options))); }
public PlaygroundMiddleware(RequestDelegate next, PlaygroundOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> Adds middleware for GraphQL Playground 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="PlaygroundMiddleware"/>. If not set, then the default values will be used. </param> /// <param name="path">The path to the GraphQL Playground endpoint which defaults to '/ui/playground'</param> /// <returns> The reference to provided <paramref name="app"/> instance. </returns> public static IApplicationBuilder UseGraphQLPlayground(this IApplicationBuilder app, PlaygroundOptions options, string path = "/ui/playground") { return(app.UseWhen( context => context.Request.Path.StartsWithSegments(path, out var remaining) && string.IsNullOrEmpty(remaining), b => b.UseMiddleware <PlaygroundMiddleware>(options ?? new PlaygroundOptions()))); }
public PlaygroundPageModel(PlaygroundOptions options) { _options = options; }