Skip to content

Commit

Permalink
passed in graphQL path into middleware (#9)
Browse files Browse the repository at this point in the history
* passed in graphQL path into middleware

* used Path.StartsWithSegments to check /graphql

Co-authored-by: Lydon Chandra <lydonch@gmail.com>
  • Loading branch information
2 people authored and JannikLassahn committed Sep 3, 2020
1 parent 6039f5c commit ab16ffe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IApplicationBuilder UseGraphQLUpload<TSchema>(this IApplicationBui
if (options is null)
throw new ArgumentNullException(nameof(options));

return builder.UseMiddleware<GraphQLUploadMiddleware<TSchema>>(options);
return builder.UseMiddleware<GraphQLUploadMiddleware<TSchema>>(options, path);
}
}
}
9 changes: 6 additions & 3 deletions src/GraphQL.Upload.AspNetCore/GraphQLUploadMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@ public class GraphQLUploadMiddleware<TSchema>
private readonly RequestDelegate _next;
private readonly GraphQLUploadOptions _options;
private readonly GraphQLUploadRequestDeserializer _requestDeserializer;

private readonly string _graphQLPath;
public GraphQLUploadMiddleware(ILogger<GraphQLUploadMiddleware<TSchema>> logger, RequestDelegate next,
GraphQLUploadOptions options, GraphQLUploadRequestDeserializer requestDeserializer)
GraphQLUploadOptions options, PathString path, GraphQLUploadRequestDeserializer requestDeserializer)
{
_logger = logger;
_next = next ?? throw new ArgumentNullException(nameof(next));
_options = options;
_requestDeserializer = requestDeserializer;
_graphQLPath = path;
}

public async Task InvokeAsync(HttpContext context)
{
if (!context.Request.HasFormContentType)
if (!context.Request.HasFormContentType
|| !context.Request.Path.StartsWithSegments( _graphQLPath ))
{
// not graphql path, eg. Form Authentication, skip this middleware
await _next(context);
return;
}
Expand Down

0 comments on commit ab16ffe

Please sign in to comment.