Skip to content

Commit 050b68f

Browse files
author
Viktor Tochonov
committed
Fixed IInputExecutionContext resolution
1 parent 6e93306 commit 050b68f

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLRequestHandler.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ open System.Text.Json
66
open System.Text.Json.Serialization
77
open System.Threading.Tasks
88
open Microsoft.AspNetCore.Http
9+
open Microsoft.Extensions.DependencyInjection
910
open Microsoft.Extensions.Logging
1011
open Microsoft.Extensions.Options
1112

@@ -43,7 +44,7 @@ and [<AbstractClass>] GraphQLRequestHandler<'Root>
4344
) =
4445

4546
let ctx = httpContextAccessor.HttpContext
46-
let getInputContext() = (HttpContextRequestExecutionContext ctx) :> IInputExecutionContext
47+
let getInputContext() = ctx.RequestServices.GetRequiredService<IInputExecutionContext>()
4748

4849
let toResponse { DocumentId = documentId; Content = content; Metadata = metadata } =
4950

src/FSharp.Data.GraphQL.Server.AspNetCore/GraphQLWebsocketMiddleware.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ open System.Text.Json.Serialization
1111
open System.Threading
1212
open System.Threading.Tasks
1313
open Microsoft.AspNetCore.Http
14+
open Microsoft.Extensions.DependencyInjection
1415
open Microsoft.Extensions.Hosting
1516
open Microsoft.Extensions.Logging
1617
open Microsoft.Extensions.Options
@@ -168,7 +169,6 @@ type GraphQLWebSocketMiddleware<'Root>
168169

169170
let sendMsg = sendMessageViaSocket serializerOptions socket
170171
let rcv () = socket |> rcvMsgViaSocket serializerOptions
171-
let getInputContext() = (HttpContextRequestExecutionContext httpContext) :> IInputExecutionContext
172172

173173
let sendOutput id (output : SubscriptionExecutionResult) =
174174
sendMsg (Next (id, output))
@@ -273,6 +273,7 @@ type GraphQLWebSocketMiddleware<'Root>
273273
)
274274
else
275275
let variables = query.Variables |> Skippable.toOption
276+
let getInputContext() = httpContext.RequestServices.GetRequiredService<IInputExecutionContext>()
276277
let! planExecutionResult =
277278
let root = options.RootFactory httpContext
278279
options.SchemaExecutor.AsyncExecute (query.Query, getInputContext, root, ?variables = variables)

src/FSharp.Data.GraphQL.Server.AspNetCore/RequestExecutionContext.fs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ open System.IO
44
open FSharp.Data.GraphQL
55
open Microsoft.AspNetCore.Http
66

7-
type HttpContextRequestExecutionContext (httpContext : HttpContext) =
7+
type HttpContextRequestExecutionContext (httpContext : IHttpContextAccessor) =
88

99
interface IInputExecutionContext with
1010

1111
member this.GetFile (key) =
12-
if not httpContext.Request.HasFormContentType then
12+
let context = httpContext.HttpContext
13+
if not context.Request.HasFormContentType then
1314
Error "Request does not have form content type"
1415
else
15-
let form = httpContext.Request.Form
16+
let form = context.Request.Form
1617
match (form.Files |> Seq.vtryFind (fun f -> f.Name = key)) with
1718
| ValueSome file ->
1819
let memoryStream = new MemoryStream ()

0 commit comments

Comments
 (0)