Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed `error FS3511: This state machine is not statically compilable.…
Browse files Browse the repository at this point in the history
… A resumable code invocation at`

See dotnet/fsharp#12839
Juri committed Sep 4, 2022

Verified

This commit was signed with the committer’s verified signature.
sandy081 Sandeep Somavarapu
1 parent 4e3c237 commit 476c88c
Showing 2 changed files with 45 additions and 44 deletions.
75 changes: 38 additions & 37 deletions tests/FSharp.Data.GraphQL.IntegrationTests.Server/HttpHandlers.fs
Original file line number Diff line number Diff line change
@@ -103,25 +103,27 @@ module HttpHandlers =
ms
match getMultipartRequestBoundary ctx.Request with
| Some boundary ->
use ms = copyBodyToMemory(ctx.Request)
let reader = MultipartReader(boundary, ms)
let request = reader |> MultipartRequest.read |> Async.AwaitTask |> Async.RunSynchronously
let results =
request.Operations
|> List.map (fun op ->
let result =
match op.Variables with
| Some variables ->
let variables = parseVariables Schema.schema (parseVariableDefinitions op.Query) variables
Schema.executor.AsyncExecute(op.Query, variables = variables, data = root)
| None -> Schema.executor.AsyncExecute(op.Query, data = root)
result |> Async.RunSynchronously |> addRequestType "Multipart")
match results with
| [ result ] ->
return! okWithStr (json result) next ctx
| results ->
let result = JArray.FromObject(List.map json results).ToString()
return! okWithStr result next ctx
return! task {
use ms = copyBodyToMemory(ctx.Request)
let reader = MultipartReader(boundary, ms)
let! request = reader |> MultipartRequest.read ctx.RequestAborted
let results =
request.Operations
|> List.map (fun op ->
let result =
match op.Variables with
| Some variables ->
let variables = parseVariables Schema.schema (parseVariableDefinitions op.Query) variables
Schema.executor.AsyncExecute(op.Query, variables = variables, data = root)
| None -> Schema.executor.AsyncExecute(op.Query, data = root)
result |> Async.RunSynchronously |> addRequestType "Multipart")
match results with
| [ result ] ->
return! okWithStr (json result) next ctx
| results ->
let result = JArray.FromObject(List.map json results).ToString()
return! okWithStr result next ctx
}
| None ->
return! badRequest (text "Invalid multipart request header: missing boundary value.") next ctx
else
@@ -138,24 +140,23 @@ module HttpHandlers =
| :? string as query -> Some (query, getVariables (parseVariableDefinitions query) data)
| _ -> failwith "Failure deserializing repsonse. Could not read query - it is not stringified in request."
else None)
match request with
| Some (query, Some variables) ->
printfn "Received query: %s" query
printfn "Received variables: %A" variables
let query = removeWhitespacesAndLineBreaks query
let result = Schema.executor.AsyncExecute(query, root, variables) |> Async.RunSynchronously |> addRequestType "Classic"
printfn "Result metadata: %A" result.Metadata
return! okWithStr (json result) next ctx
| Some (query, None) ->
printfn "Received query: %s" query
let query = removeWhitespacesAndLineBreaks query
let result = Schema.executor.AsyncExecute(query) |> Async.RunSynchronously |> addRequestType "Classic"
printfn "Result metadata: %A" result.Metadata
return! okWithStr (json result) next ctx
| None ->
let result = Schema.executor.AsyncExecute(Introspection.IntrospectionQuery) |> Async.RunSynchronously |> addRequestType "Classic"
printfn "Result metadata: %A" result.Metadata
return! okWithStr (json result) next ctx
let! result = task {
match request with
| Some (query, Some variables) ->
printfn "Received query: %s" query
printfn "Received variables: %A" variables
let query = removeWhitespacesAndLineBreaks query
return! Schema.executor.AsyncExecute(query, root, variables)
| Some (query, None) ->
printfn "Received query: %s" query
let query = removeWhitespacesAndLineBreaks query
return! Schema.executor.AsyncExecute(query)
| None ->
return! Schema.executor.AsyncExecute(Introspection.IntrospectionQuery)
}
let result = result |> addRequestType "Classic"
printfn "Result metadata: %A" result.Metadata
return! okWithStr (json result) next ctx
}

let webApp : HttpHandler =
Original file line number Diff line number Diff line change
@@ -119,12 +119,12 @@ module MultipartRequest =
| operations -> operations |> List.mapi (fun ix operation -> mapOperation (Some ix) operation)

/// Reads a GraphQL multipart request from a MultipartReader.
let read (reader : MultipartReader) =
async {
let read cancellationToken (reader : MultipartReader) =
task {
let mutable section : GraphQLMultipartSection option = None
let readNextSection () =
async {
let! next = reader.ReadNextSectionAsync() |> Async.AwaitTask
task {
let! next = reader.ReadNextSectionAsync cancellationToken
section <- GraphQLMultipartSection.FromSection(next)
}
let mutable operations : string = null
@@ -134,7 +134,7 @@ module MultipartRequest =
while not section.IsNone do
match section.Value with
| Form section ->
let! value = section.GetValueAsync() |> Async.AwaitTask
let! value = section.GetValueAsync()
match section.Name with
| "operations" ->
operations <- value
@@ -145,7 +145,7 @@ module MultipartRequest =
| _ -> failwithf "Error reading multipart request. Unexpected section name \"%s\"." section.Name
| File section ->
let stream = new System.IO.MemoryStream(4096)
do! section.FileStream.CopyToAsync(stream) |> Async.AwaitTask
do! section.FileStream.CopyToAsync(stream, cancellationToken) |> Async.AwaitTask
stream.Position <- 0L
let value = { Name = section.FileName; ContentType = section.Section.ContentType; Content = stream }
files.Add(section.Name, value)
@@ -156,4 +156,4 @@ module MultipartRequest =
| :? JObject as op -> [ op.ToObject<Operation>(jsonSerializer) ]
| _ -> failwith "Unexpected operations value."
return { Operations = parseOperations operations map files }
} |> Async.StartAsTask
}

0 comments on commit 476c88c

Please sign in to comment.