diff --git a/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLRequestHandler.fs b/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLRequestHandler.fs index 6e446d49..51b1b3b1 100644 --- a/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLRequestHandler.fs +++ b/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLRequestHandler.fs @@ -6,6 +6,7 @@ open System.Text.Json open System.Text.Json.Serialization open System.Threading.Tasks open Microsoft.AspNetCore.Http +open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Logging open Microsoft.Extensions.Options @@ -43,7 +44,7 @@ and [] GraphQLRequestHandler<'Root> ) = let ctx = httpContextAccessor.HttpContext - let getInputContext() = (HttpContextRequestExecutionContext ctx) :> IInputExecutionContext + let getInputContext() = ctx.RequestServices.GetRequiredService() let toResponse { DocumentId = documentId; Content = content; Metadata = metadata } = diff --git a/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs b/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs index 6d621e93..77da3743 100644 --- a/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs +++ b/src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs @@ -11,6 +11,7 @@ open System.Text.Json.Serialization open System.Threading open System.Threading.Tasks open Microsoft.AspNetCore.Http +open Microsoft.Extensions.DependencyInjection open Microsoft.Extensions.Hosting open Microsoft.Extensions.Logging open Microsoft.Extensions.Options @@ -168,7 +169,6 @@ type GraphQLWebSocketMiddleware<'Root> let sendMsg = sendMessageViaSocket serializerOptions socket let rcv () = socket |> rcvMsgViaSocket serializerOptions - let getInputContext() = (HttpContextRequestExecutionContext httpContext) :> IInputExecutionContext let sendOutput id (output : SubscriptionExecutionResult) = sendMsg (Next (id, output)) @@ -273,6 +273,7 @@ type GraphQLWebSocketMiddleware<'Root> ) else let variables = query.Variables |> Skippable.toOption + let getInputContext() = httpContext.RequestServices.GetRequiredService() let! planExecutionResult = let root = options.RootFactory httpContext options.SchemaExecutor.AsyncExecute (query.Query, getInputContext, root, ?variables = variables) diff --git a/src/FSharp.Data.GraphQL.Server.AspNetCore/RequestExecutionContext.fs b/src/FSharp.Data.GraphQL.Server.AspNetCore/RequestExecutionContext.fs index 7ffab569..34be6a9c 100644 --- a/src/FSharp.Data.GraphQL.Server.AspNetCore/RequestExecutionContext.fs +++ b/src/FSharp.Data.GraphQL.Server.AspNetCore/RequestExecutionContext.fs @@ -4,15 +4,17 @@ open System.IO open FSharp.Data.GraphQL open Microsoft.AspNetCore.Http -type HttpContextRequestExecutionContext (httpContext : HttpContext) = +type HttpContextRequestExecutionContext (httpContext : IHttpContextAccessor) = interface IInputExecutionContext with member this.GetFile (key) = - if not httpContext.Request.HasFormContentType then + let context = httpContext.HttpContext + if not context.Request.HasFormContentType then + Error "Request does not have form content type" else - let form = httpContext.Request.Form + let form = context.Request.Form match (form.Files |> Seq.vtryFind (fun f -> f.Name = key)) with | ValueSome file -> let memoryStream = new MemoryStream ()