diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 99be28f..564b5de 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -14,12 +14,13 @@ jobs:
- uses: actions/checkout@v3
- name: Setup .NET Core SDKs
- uses: actions/setup-dotnet@v2
+ uses: actions/setup-dotnet@v4
with:
dotnet-version: |
3.1.x
5.0.x
6.0.x
+ 8.0.x
- name: Restore
run: |
diff --git a/Directory.Build.props b/Directory.Build.props
index 690eac1..8d70c6f 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,11 +3,12 @@
latest
enable
+ enable
- 7.1.1
- 7.1.1
+ 7.6.0
+ 7.6.0
2.2.0
6.0.0
6.0.0
diff --git a/GraphQL.Upload.AspNetCore.sln b/GraphQL.Upload.AspNetCore.sln
index c2b48bc..c86e1bb 100644
--- a/GraphQL.Upload.AspNetCore.sln
+++ b/GraphQL.Upload.AspNetCore.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28307.329
+# Visual Studio Version 17
+VisualStudioVersion = 17.8.34309.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FileUploadSample", "samples\FileUploadSample\FileUploadSample.csproj", "{58C0B73A-2436-4F56-89E0-BD5D22E00047}"
EndProject
@@ -13,6 +13,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{237BB3B8
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{CC98F604-7F80-4718-A307-7AA63FF55361}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D65FAD1-1899-4283-B1BB-6EAC4A097AA5}"
+ ProjectSection(SolutionItems) = preProject
+ Directory.Build.props = Directory.Build.props
+ LICENSE = LICENSE
+ README.md = README.md
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
diff --git a/README.md b/README.md
index b01049c..a2b8c6e 100644
--- a/README.md
+++ b/README.md
@@ -16,19 +16,20 @@ Preview versions from the develop branch are available via [GitHub Packages](htt
Register the middleware in your Startup.cs.
-This middleware implementation **only** parses multipart requests. That's why we're using additional middleware ([graphql-dotnet/server](https://github.com/graphql-dotnet/server)) to handle other request types.
+This middleware inherits from `GraphQLHttpMiddleware` and as such supports all of the base functionality provied by `GraphQL.Server.Transports.AspNetCore`.
+
```csharp
public void ConfigureServices(IServiceCollection services)
{
- services.AddSingleton()
- .AddGraphQLUpload()
- .AddGraphQL();
+ services.AddGraphQL(b => b
+ .AddSchema()
+ .AddSystemTextJson()
+ .AddGraphQLUpload());
}
public void Configure(IApplicationBuilder app)
{
- app.UseGraphQLUpload()
- .UseGraphQL();
+ app.UseGraphQLUpload();
}
```
diff --git a/samples/FileUploadSample/FileUploadSample.csproj b/samples/FileUploadSample/FileUploadSample.csproj
index 758daee..ba09785 100644
--- a/samples/FileUploadSample/FileUploadSample.csproj
+++ b/samples/FileUploadSample/FileUploadSample.csproj
@@ -2,6 +2,7 @@
net6.0
+ false
diff --git a/samples/FileUploadSample/Program.cs b/samples/FileUploadSample/Program.cs
index ed170b2..ca44c7e 100644
--- a/samples/FileUploadSample/Program.cs
+++ b/samples/FileUploadSample/Program.cs
@@ -1,17 +1,37 @@
-using Microsoft.AspNetCore;
+using FileUploadSample;
+using GraphQL;
+using GraphQL.Types;
-namespace FileUploadSample
+var builder = WebApplication.CreateBuilder(args);
+
+builder.Services.AddSingleton();
+
+builder.Services.AddGraphQL(builder => builder
+ .AddSchema()
+ .AddGraphTypes()
+ .AddGraphQLUpload()
+ .AddErrorInfoProvider(opt => opt.ExposeExceptionDetails = true)
+ .AddSystemTextJson());
+
+builder.Services.AddCors();
+
+
+var app = builder.Build();
+
+if (app.Environment.IsDevelopment())
{
- public class Program
- {
- public static void Main(string[] args)
- {
- CreateWebHostBuilder(args).Build().Run();
- }
-
- public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
- WebHost.CreateDefaultBuilder(args)
- .UseKestrel()
- .UseStartup();
- }
+ app.UseDeveloperExceptionPage();
}
+
+app.UseStaticFiles();
+
+app.UseCors(b => b
+ .AllowAnyOrigin()
+ .AllowAnyMethod()
+ .AllowAnyHeader());
+
+// register the middleware
+app.UseGraphQLUpload();
+app.UseGraphQLPlayground("/");
+
+await app.RunAsync();
diff --git a/samples/FileUploadSample/Startup.cs b/samples/FileUploadSample/Startup.cs
deleted file mode 100644
index 6b3b5ce..0000000
--- a/samples/FileUploadSample/Startup.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using GraphQL;
-using GraphQL.Types;
-
-namespace FileUploadSample
-{
- public class Startup
- {
- public void ConfigureServices(IServiceCollection services)
- {
- services.AddSingleton();
- services.AddSingleton();
-
- services.AddGraphQLUpload();
- services.AddGraphQL(builder => builder
- .AddGraphTypes()
- .AddErrorInfoProvider(opt => opt.ExposeExceptionDetails = true)
- .AddSystemTextJson());
-
- services.AddCors();
- }
-
- public void Configure(IApplicationBuilder app, IHostEnvironment env)
- {
- if (env.IsDevelopment())
- {
- app.UseDeveloperExceptionPage();
- }
-
- app.UseStaticFiles();
-
- app.UseCors(b => b
- .AllowAnyOrigin()
- .AllowAnyMethod()
- .AllowAnyHeader());
-
- // register the middleware that can handle multipart requests first
- app.UseGraphQLUpload();
-
- app.UseGraphQL();
- app.UseGraphQLPlayground("/");
- }
- }
-}
diff --git a/src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs b/src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs
index 88d00a8..0860b2c 100644
--- a/src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs
+++ b/src/GraphQL.Upload.AspNetCore/ApplicationBuilderExtensions.cs
@@ -2,71 +2,48 @@
using GraphQL.Upload.AspNetCore;
using Microsoft.AspNetCore.Http;
-namespace Microsoft.AspNetCore.Builder
+namespace Microsoft.AspNetCore.Builder;
+
+///
+/// Extension methods for adding to an application.
+///
+public static class ApplicationBuilderExtensions
{
///
- /// Extension methods for adding to an application.
+ /// Adds the to handle file uploads in GraphQL requests.
///
- public static class ApplicationBuilderExtensions
+ /// The implementation of to use
+ /// The application builder
+ /// The path to the GraphQL endpoint which defaults to '/graphql'
+ /// The received as parameter
+ public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, string path = "/graphql", Action? configureOptions = null)
+ where TSchema : ISchema
{
- ///
- /// Adds the to handle file uploads in GraphQL requests.
- ///
- /// The implementation of to use
- /// The application builder
- /// The path to the GraphQL endpoint which defaults to '/graphql'
- /// The received as parameter
- public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, string path = "/graphql")
- where TSchema : ISchema
- {
- return builder.UseGraphQLUpload(new PathString(path));
- }
-
- ///
- /// Adds the to handle file uploads in GraphQL requests.
- ///
- /// The implementation of to use
- /// The application builder
- /// The path to the GraphQL endpoint
- /// The received as parameter>
- public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, PathString path)
- where TSchema : ISchema
- {
- return builder.UseGraphQLUpload(path, new GraphQLUploadOptions());
- }
+ return builder.UseGraphQLUpload(new PathString(path), configureOptions);
+ }
- ///
- /// Adds the to handle file uploads in GraphQL requests.
- ///
- /// The implementation of to use
- /// The application builder
- /// The path to the GraphQL endpoint
- /// A delegate that is used to configure the , which are passed to the
- /// The received as parameter>
- public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, PathString path, Action configureOptions)
- where TSchema : ISchema
- {
- var options = new GraphQLUploadOptions();
- configureOptions(options);
+ ///
+ /// Adds the to handle file uploads in GraphQL requests.
+ ///
+ /// The implementation of to use
+ /// The application builder
+ /// The path to the GraphQL endpoint
+ /// A delegate that is used to configure the , which are passed to the
+ /// The received as parameter>
+ public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, PathString path, Action? configureOptions = null)
+ where TSchema : ISchema
+ {
+ var options = new GraphQLUploadOptions();
+ configureOptions?.Invoke(options);
- return builder.UseGraphQLUpload(path, options);
- }
+ return builder.UseGraphQL>(path, options);
+ }
- ///
- /// Adds the to handle file uploads in GraphQL requests.
- ///
- /// The implementation of to use
- /// The application builder
- /// The path to the GraphQL endpoint
- /// The options used to configure the
- /// The received as parameter>
- public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, PathString path, GraphQLUploadOptions options)
- where TSchema : ISchema
- {
- if (options is null)
- throw new ArgumentNullException(nameof(options));
+ ///
+ public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, string path = "/graphql", Action? configureOptions = null)
+ => UseGraphQLUpload(builder, path, configureOptions);
- return builder.UseMiddleware>(options, path);
- }
- }
+ ///
+ public static IApplicationBuilder UseGraphQLUpload(this IApplicationBuilder builder, PathString path, Action? configureOptions = null)
+ => UseGraphQLUpload(builder, path, configureOptions);
}
\ No newline at end of file
diff --git a/src/GraphQL.Upload.AspNetCore/BadMapPathError.cs b/src/GraphQL.Upload.AspNetCore/BadMapPathError.cs
new file mode 100644
index 0000000..be23632
--- /dev/null
+++ b/src/GraphQL.Upload.AspNetCore/BadMapPathError.cs
@@ -0,0 +1,18 @@
+using System.Net;
+
+namespace GraphQL.Upload.AspNetCore;
+
+///
+/// Represents an error when an invalid map path is provided in a GraphQL file upload request.
+///
+public class BadMapPathError : GraphQLUploadError
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The inner exception, if any, that caused the bad map path error.
+ public BadMapPathError(Exception? innerException = null)
+ : base("Invalid map path." + (innerException != null ? " " + innerException.Message : null), HttpStatusCode.BadRequest, innerException)
+ {
+ }
+}
diff --git a/src/GraphQL.Upload.AspNetCore/FileSizeExceededError.cs b/src/GraphQL.Upload.AspNetCore/FileSizeExceededError.cs
new file mode 100644
index 0000000..b3c951a
--- /dev/null
+++ b/src/GraphQL.Upload.AspNetCore/FileSizeExceededError.cs
@@ -0,0 +1,17 @@
+using System.Net;
+
+namespace GraphQL.Upload.AspNetCore;
+
+///
+/// Represents an error when a file exceeds the allowed size limit in a GraphQL upload.
+///
+public class FileSizeExceededError : GraphQLUploadError
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public FileSizeExceededError()
+ : base("File size limit exceeded.", HttpStatusCode.RequestEntityTooLarge)
+ {
+ }
+}
diff --git a/src/GraphQL.Upload.AspNetCore/GraphQL.Upload.AspNetCore.csproj b/src/GraphQL.Upload.AspNetCore/GraphQL.Upload.AspNetCore.csproj
index 5cbf798..a594ffa 100644
--- a/src/GraphQL.Upload.AspNetCore/GraphQL.Upload.AspNetCore.csproj
+++ b/src/GraphQL.Upload.AspNetCore/GraphQL.Upload.AspNetCore.csproj
@@ -1,24 +1,24 @@
- netstandard2.0;netstandard2.1;net6.0;
- 3.0.3
+ netstandard2.0;netcoreapp3.1
+ 4.0.0
Jannik Lassahn
https://github.com/JannikLassahn/graphql-dotnet-upload
MIT
+ README.md
https://github.com/JannikLassahn/graphql-dotnet-upload
Middleware and an Upload scalar to add support for GraphQL multipart requests for ASP.NET Core
ASP.NET Core, GraphQL, File Upload
+ embedded
-
-
-
-
-
-
+
+
+
+
diff --git a/src/GraphQL.Upload.AspNetCore/GraphQLBuilderExtensions.cs b/src/GraphQL.Upload.AspNetCore/GraphQLBuilderExtensions.cs
new file mode 100644
index 0000000..82e58b3
--- /dev/null
+++ b/src/GraphQL.Upload.AspNetCore/GraphQLBuilderExtensions.cs
@@ -0,0 +1,21 @@
+using GraphQL.DI;
+using GraphQL.Upload.AspNetCore;
+
+namespace GraphQL;
+
+///
+/// Provides extension methods for setting up GraphQL file upload support in an application.
+///
+public static class GraphQLUploadExtensions
+{
+ ///
+ /// Registers within the dependency injection framework
+ /// as a singleton for use within a GraphQL schema.
+ ///
+ public static IGraphQLBuilder AddGraphQLUpload(this IGraphQLBuilder builder)
+ {
+ builder.Services.Register(ServiceLifetime.Singleton);
+
+ return builder;
+ }
+}
diff --git a/src/GraphQL.Upload.AspNetCore/GraphQLUploadError.cs b/src/GraphQL.Upload.AspNetCore/GraphQLUploadError.cs
new file mode 100644
index 0000000..4800160
--- /dev/null
+++ b/src/GraphQL.Upload.AspNetCore/GraphQLUploadError.cs
@@ -0,0 +1,26 @@
+using System.Net;
+
+namespace GraphQL.Upload.AspNetCore;
+
+///
+/// Represents errors related to GraphQL file uploads.
+///
+public class GraphQLUploadError : ExecutionError
+{
+ ///
+ /// Gets the HTTP status code associated with the error.
+ ///
+ public HttpStatusCode HttpStatusCode { get; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The error message.
+ /// The HTTP status code (defaults to BadRequest).
+ /// The inner exception, if any.
+ public GraphQLUploadError(string message, HttpStatusCode statusCode = HttpStatusCode.BadRequest, Exception? innerException = null)
+ : base(message, innerException)
+ {
+ HttpStatusCode = statusCode;
+ }
+}
diff --git a/src/GraphQL.Upload.AspNetCore/GraphQLUploadFileMap.cs b/src/GraphQL.Upload.AspNetCore/GraphQLUploadFileMap.cs
deleted file mode 100644
index b46aaa0..0000000
--- a/src/GraphQL.Upload.AspNetCore/GraphQLUploadFileMap.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using Microsoft.AspNetCore.Http;
-
-namespace GraphQL.Upload.AspNetCore
-{
- public class GraphQLUploadFileMap
- {
- public List