@@ -394,40 +394,66 @@ let ``Execution when querying returns unique document id with response`` () =
394
394
| response -> fail $" Expected a 'Direct' GQLResponse but got\n {response}"
395
395
396
396
type InnerNullableTest = { Kaboom : string }
397
- type NullableTest = { Inner : InnerNullableTest }
397
+ type NullableTest = {
398
+ Inner : InnerNullableTest
399
+ InnerPartialSuccess : InnerNullableTest
400
+ }
398
401
399
402
[<Fact>]
400
403
let ``Execution handles errors : properly propagates errors`` () =
401
- let InnerObj =
404
+ let InnerObjType =
402
405
Define.Object< InnerNullableTest>(
403
406
" Inner" , [
404
407
Define.Field( " kaboom" , StringType, fun _ x -> x.Kaboom)
405
408
])
409
+ let InnerPartialSuccessObjType =
410
+ let resolvePartialSuccess ( ctx : ResolveFieldContext ) ( _ : InnerNullableTest ) =
411
+ ctx.AddError { new IGQLError with member _.Message = " Some non-critical error" }
412
+ " Success"
413
+ Define.Object< InnerNullableTest>(
414
+ " InnerPartialSuccess" , [
415
+ Define.Field( " kaboom" , StringType, resolvePartialSuccess)
416
+ ])
406
417
let schema =
407
418
Schema( Define.Object< NullableTest>(
408
- " Type" , [
409
- Define.Field( " inner" , Nullable InnerObj, fun _ x -> Some x.Inner)
410
- ]))
419
+ " Type" , [
420
+ Define.Field( " inner" , Nullable InnerObjType, fun _ x -> Some x.Inner)
421
+ Define.Field( " partialSuccess" , Nullable InnerPartialSuccessObjType, fun _ x -> Some x.InnerPartialSuccess)
422
+ ]))
411
423
let expectedData =
412
424
NameValueLookup.ofList [
413
425
" inner" , null
426
+ " partialSuccess" , NameValueLookup.ofList [
427
+ " kaboom" , " Success"
428
+ ]
414
429
]
415
430
let expectedErrors = [
416
431
GQLProblemDetails.CreateWithKind ( " Non-Null field kaboom resolved as a null!" , Execution, [ box " inner" ; " kaboom" ])
432
+ GQLProblemDetails.CreateWithKind ( " Some non-critical error" , Execution, [ box " partialSuccess" ; " kaboom" ])
417
433
]
418
- let result = sync <| Executor( schema) .AsyncExecute( " query Example { inner { kaboom } }" , { Inner = { Kaboom = null } })
434
+ let result =
435
+ let variables = { Inner = { Kaboom = null }; InnerPartialSuccess = { Kaboom = " Success" } }
436
+ sync <| Executor( schema) .AsyncExecute( " query Example { inner { kaboom } partialSuccess { kaboom } }" , variables)
419
437
ensureDirect result <| fun data errors ->
420
438
result.DocumentId |> notEquals Unchecked.defaultof< int>
421
439
data |> equals ( upcast expectedData)
422
440
errors |> equals expectedErrors
423
441
442
+ // TODO: Add other tests with possible error cases
443
+ // 1. Add additional error and raise an exception in a nullable GraphQL field resolver
444
+ // 2. Add additional error and return None from a nullable GraphQL field resolver
445
+ // 3. Add additional error and raise an exception in a non-nullable GraphQL field resolver
446
+ // 4. Add additional error and return null from a non-nullable GraphQL field resolver
447
+ // Covered // 5.1. Add additional error and return value from a non-nullable GraphQL field resolver
448
+ // 5.2. Add additional error and raise an exception in a non-nullable GraphQL field resolver
449
+
424
450
[<Fact>]
425
451
let ``Execution handles errors : exceptions`` () =
426
452
let schema =
427
453
Schema( Define.Object< unit>(
428
- " Type" , [
429
- Define.Field( " a" , StringType, fun _ _ -> failwith " Resolver Error!" )
430
- ]))
454
+ " Type" , [
455
+ Define.Field( " a" , StringType, fun _ _ -> failwith " Resolver Error!" )
456
+ ]))
431
457
let expectedError = GQLProblemDetails.CreateWithKind ( " Resolver Error!" , Execution, [ box " a" ])
432
458
let result = sync <| Executor( schema) .AsyncExecute( " query Test { a }" , ())
433
459
ensureRequestError result <| fun [ error ] -> error |> equals expectedError
0 commit comments