Skip to content

Commit

Permalink
Miscellaneous API fixes (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 authored Apr 14, 2022
1 parent d073023 commit 97ea840
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GraphQL.AspNetCore3;
namespace GraphQL.AspNetCore3.Errors;

/// <summary>
/// Represents a validation error indicating that the requested operation is not valid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ public static GraphQLEndpointConventionBuilder MapGraphQL<TSchema>(this IEndpoin
/// <summary>
/// Add the GraphQL middleware to the HTTP request pipeline for the specified schema.
/// </summary>
/// <typeparam name="TSchema">The implementation of <see cref="ISchema"/> to use</typeparam>
/// <typeparam name="TMiddleware">Custom middleware inherited from <see cref="GraphQLHttpMiddleware{TSchema}"/></typeparam>
/// <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="pattern">The route pattern.</param>
/// <param name="args">The arguments to pass to the middleware type instance's constructor.</param>
/// <returns>The <see cref="IApplicationBuilder"/> received as parameter</returns>
public static GraphQLEndpointConventionBuilder MapGraphQL<TSchema, TMiddleware>(this IEndpointRouteBuilder endpoints, string pattern = "graphql")
where TSchema : ISchema
where TMiddleware : GraphQLHttpMiddleware<TSchema>
public static GraphQLEndpointConventionBuilder MapGraphQL<TMiddleware>(this IEndpointRouteBuilder endpoints, string pattern = "graphql", params object[] args)
where TMiddleware : GraphQLHttpMiddleware
{
var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware<TMiddleware>().Build();
var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware<TMiddleware>(args).Build();
return new GraphQLEndpointConventionBuilder(endpoints.Map(pattern, requestDelegate).WithDisplayName("GraphQL"));
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/GraphQL.AspNetCore3/GraphQLHttpMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma warning disable CA1716 // Identifiers should not match keywords

using System.Security.Claims;
using System.Security.Principal;
using Microsoft.AspNetCore.Authorization;

namespace GraphQL.AspNetCore3;
Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL.AspNetCore3/HttpPostValidationRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace GraphQL.AspNetCore3;
/// <summary>
/// Validates that HTTP POST requests do not execute subscriptions.
/// </summary>
public class HttpPostValidationRule : IValidationRule
public sealed class HttpPostValidationRule : IValidationRule
{
/// <inheritdoc/>
public ValueTask<INodeVisitor?> ValidateAsync(ValidationContext context)
Expand Down
15 changes: 7 additions & 8 deletions src/Tests.ApiApprovals/GraphQL.AspNetCore3.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ namespace GraphQL.AspNetCore3
public static GraphQL.AspNetCore3.GraphQLEndpointConventionBuilder MapGraphQL(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern = "graphql", System.Action<GraphQL.AspNetCore3.GraphQLHttpMiddlewareOptions>? configureMiddleware = null) { }
public static GraphQL.AspNetCore3.GraphQLEndpointConventionBuilder MapGraphQL<TSchema>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern = "graphql", System.Action<GraphQL.AspNetCore3.GraphQLHttpMiddlewareOptions>? configureMiddleware = null)
where TSchema : GraphQL.Types.ISchema { }
public static GraphQL.AspNetCore3.GraphQLEndpointConventionBuilder MapGraphQL<TSchema, TMiddleware>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern = "graphql")
where TSchema : GraphQL.Types.ISchema
where TMiddleware : GraphQL.AspNetCore3.GraphQLHttpMiddleware<TSchema> { }
public static GraphQL.AspNetCore3.GraphQLEndpointConventionBuilder MapGraphQL<TMiddleware>(this Microsoft.AspNetCore.Routing.IEndpointRouteBuilder endpoints, string pattern = "graphql", params object[] args)
where TMiddleware : GraphQL.AspNetCore3.GraphQLHttpMiddleware { }
}
public abstract class GraphQLHttpMiddleware
{
Expand Down Expand Up @@ -157,11 +156,7 @@ namespace GraphQL.AspNetCore3
public HttpGetValidationRule() { }
public System.Threading.Tasks.ValueTask<GraphQL.Validation.INodeVisitor?> ValidateAsync(GraphQL.Validation.ValidationContext context) { }
}
public class HttpMethodValidationError : GraphQL.Validation.ValidationError
{
public HttpMethodValidationError(GraphQLParser.ROM originalQuery, GraphQLParser.AST.ASTNode node, string message) { }
}
public class HttpPostValidationRule : GraphQL.Validation.IValidationRule
public sealed class HttpPostValidationRule : GraphQL.Validation.IValidationRule
{
public HttpPostValidationRule() { }
public System.Threading.Tasks.ValueTask<GraphQL.Validation.INodeVisitor?> ValidateAsync(GraphQL.Validation.ValidationContext context) { }
Expand Down Expand Up @@ -199,6 +194,10 @@ namespace GraphQL.AspNetCore3.Errors
{
public BatchedRequestsNotSupportedError() { }
}
public class HttpMethodValidationError : GraphQL.Validation.ValidationError
{
public HttpMethodValidationError(GraphQLParser.ROM originalQuery, GraphQLParser.AST.ASTNode node, string message) { }
}
public class InvalidContentTypeError : GraphQL.AspNetCore3.Errors.RequestError
{
public InvalidContentTypeError() { }
Expand Down
9 changes: 3 additions & 6 deletions src/Tests/BuilderMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,19 @@ public async Task Basic_PathString_WithSchema()
[Fact]
public async Task SpecificMiddleware()
{
_hostBuilder.ConfigureServices(services => services.AddSingleton<GraphQLHttpMiddlewareOptions>());
_hostBuilder.Configure(app => {
app.UseWebSockets();
app.UseGraphQL<GraphQLHttpMiddleware<ISchema>>("/graphql");
app.UseGraphQL<GraphQLHttpMiddleware<ISchema>>("/graphql", new GraphQLHttpMiddlewareOptions());
});
await VerifyAsync();
}

[Fact]
public async Task SpecificMiddleware_PathString()
{
_hostBuilder.ConfigureServices(services => services.AddSingleton<GraphQLHttpMiddlewareOptions>());
_hostBuilder.Configure(app => {
app.UseWebSockets();
app.UseGraphQL<GraphQLHttpMiddleware<ISchema>>(new PathString("/graphql"));
app.UseGraphQL<GraphQLHttpMiddleware<ISchema>>(new PathString("/graphql"), new GraphQLHttpMiddlewareOptions());
});
await VerifyAsync();
}
Expand Down Expand Up @@ -165,12 +163,11 @@ public async Task EndpointRouting_WithSchema()
public async Task EndpointRouting_WithMiddleware()
{
_hostBuilder.ConfigureServices(services => services.AddRouting());
_hostBuilder.ConfigureServices(services => services.AddSingleton<GraphQLHttpMiddlewareOptions>());
_hostBuilder.Configure(app => {
app.UseWebSockets();
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapGraphQL<ISchema, GraphQLHttpMiddleware<ISchema>>("graphql");
endpoints.MapGraphQL<GraphQLHttpMiddleware<ISchema>>("graphql", new GraphQLHttpMiddlewareOptions());
});
});
await VerifyAsync();
Expand Down

0 comments on commit 97ea840

Please sign in to comment.