Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -43,7 +44,7 @@ and [<AbstractClass>] GraphQLRequestHandler<'Root>
) =

let ctx = httpContextAccessor.HttpContext
let getInputContext() = (HttpContextRequestExecutionContext ctx) :> IInputExecutionContext
let getInputContext() = ctx.RequestServices.GetRequiredService<IInputExecutionContext>()

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -273,6 +273,7 @@ type GraphQLWebSocketMiddleware<'Root>
)
else
let variables = query.Variables |> Skippable.toOption
let getInputContext() = httpContext.RequestServices.GetRequiredService<IInputExecutionContext>()
let! planExecutionResult =
let root = options.RootFactory httpContext
options.SchemaExecutor.AsyncExecute (query.Query, getInputContext, root, ?variables = variables)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
Expand Down