Skip to content

Commit

Permalink
Fixed deffered tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xperiandri committed Feb 14, 2024
1 parent a141691 commit aa491bd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/FSharp.Data.GraphQL.Server/Execution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ and private streamed (options : BufferedStreamOptions) (innerDef : OutputDef) (c
|> Array.mapi resolveItem
|> Observable.ofAsyncValSeq
|> buffer
ResolverResult.defered (KeyValuePair (info.Identifier, null)) stream |> AsyncVal.wrap
ResolverResult.defered (KeyValuePair (info.Identifier, box [])) stream |> AsyncVal.wrap
| _ -> raise <| GQLMessageException (ErrorMessages.expectedEnumerableValue ctx.ExecutionInfo.Identifier (value.GetType()))

and private live (ctx : ResolveFieldContext) (path : FieldPath) (parent : obj) (value : obj) =
Expand Down Expand Up @@ -511,18 +511,21 @@ and private executeResolvers (ctx : ResolveFieldContext) (path : FieldPath) (par
| Ok None when ctx.ExecutionInfo.IsNullable -> return Ok (KeyValuePair(name, null), None, [])
| Error errs -> return Error errs
| Ok None -> return Error (nullResolverError name path ctx)
| Ok (Some v) -> return! onSuccess ctx path parent v
| Ok (Some v) ->
match! onSuccess ctx path parent v with
| Ok (kvp, _, _) when not ctx.ExecutionInfo.IsNullable && kvp.Value = null -> return Error (nullResolverError name path ctx)
| result -> return result
}

match info.Kind, returnDef with
| ResolveDeferred innerInfo, _ when innerInfo.IsNullable -> // We can only defer nullable fields
deferred
|> resolveWith { ctx with ExecutionInfo = { innerInfo with IsNullable = false } }
|> resolveWith { ctx with ExecutionInfo = innerInfo }
| ResolveDeferred innerInfo, _ ->
raiseErrors <| deferredNullableError (innerInfo.Identifier) (innerInfo.ReturnDef.ToString()) path ctx
| ResolveStreamed (innerInfo, mode), HasList innerDef -> // We can only stream lists
streamed mode innerDef
|> resolveWith { ctx with ExecutionInfo = innerInfo; }
|> resolveWith { ctx with ExecutionInfo = innerInfo }
| ResolveStreamed (innerInfo, _), _ ->
raiseErrors <| streamListError innerInfo.Identifier (returnDef.ToString()) path ctx
| ResolveLive innerInfo, _ ->
Expand Down
12 changes: 6 additions & 6 deletions tests/FSharp.Data.GraphQL.Tests/AbstractionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ let ``Execute handles execution of abstract types: isTypeOf is used to resolve r
empty errors
data |> equals (upcast expected)

[<Fact(Skip = "Not implemented")>]
[<Fact>]
let ``Execute handles execution of abstract types: not specified Interface types produce error`` () =
let query =
"""{
Expand All @@ -130,7 +130,7 @@ let ``Execute handles execution of abstract types: not specified Interface types

let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query)
ensureRequestError result <| fun [ petsError ] ->
petsError |> ensureValidationError "Field 'pets' does not allow nulls and list values." [ "pets"; "0" ]
petsError |> ensureExecutionError "Non-Null field pets resolved as a null!" [ "pets"; 1 ]

let query =
"""{
Expand All @@ -144,7 +144,7 @@ let ``Execute handles execution of abstract types: not specified Interface types

let result = sync <| schemaWithInterface.Value.AsyncExecute (parse query)
ensureRequestError result <| fun [ petsError ] ->
petsError |> ensureValidationError "Field 'pets' does not allow nulls and list values." [ "pets"; "0" ]
petsError |> ensureExecutionError "Non-Null field pets resolved as a null!" [ "pets"; 0 ]

[<Fact>]
let ``Execute handles execution of abstract types: not specified Interface types must be filtered out if they allow null`` () =
Expand Down Expand Up @@ -322,7 +322,7 @@ let ``Execute handles execution of abstract types: isTypeOf is used to resolve r
empty errors
data |> equals (upcast expected)

[<Fact(Skip = "Not implemented")>]
[<Fact>]
let ``Execute handles execution of abstract types: not specified Union types produce error`` () =
let query =
"""{
Expand All @@ -336,7 +336,7 @@ let ``Execute handles execution of abstract types: not specified Union types pro

let result = sync <| schemaWithUnion.Value.AsyncExecute (parse query)
ensureRequestError result <| fun [ petsError ] ->
petsError |> ensureValidationError "Field 'pets' does not allow nulls and list values." [ "pets"; "0" ]
petsError |> ensureExecutionError "Non-Null field pets resolved as a null!" [ "pets"; 1 ]

let query =
"""{
Expand All @@ -350,7 +350,7 @@ let ``Execute handles execution of abstract types: not specified Union types pro

let result = sync <| schemaWithUnion.Value.AsyncExecute (parse query)
ensureRequestError result <| fun [ petsError ] ->
petsError |> ensureValidationError "Field 'pets' does not allow nulls and list values." [ "pets"; "0" ]
petsError |> ensureExecutionError "Non-Null field pets resolved as a null!" [ "pets"; 0 ]

[<Fact>]
let ``Execute handles execution of abstract types: not specified Union types must be filtered out`` () =
Expand Down

0 comments on commit aa491bd

Please sign in to comment.