@@ -47,6 +47,59 @@ let ``Should parse operation error fields from raw response`` () =
4747 error.Extensions.[ " retryable" ] |> equals ( box false )
4848 error.Extensions.[ " severity" ] |> equals ( box 7 )
4949
50+ [<Fact; Trait( " OperationError" , " Unit" ) >]
51+ let ``Should parse all combinations of optional operation error fields`` () =
52+ let combinations =
53+ [ for includePath in [ false ; true ] do
54+ for includeLocations in [ false ; true ] do
55+ for includeExtensions in [ false ; true ] do
56+ includePath, includeLocations, includeExtensions ]
57+
58+ for includePath, includeLocations, includeExtensions in combinations do
59+ let errorFields = ResizeArray< string>([ " \" message\" :\" unit-test combination error\" " ])
60+
61+ if includePath then
62+ errorFields.Add " \" path\" :[\" alwaysError\" ,0]"
63+
64+ if includeLocations then
65+ errorFields.Add " \" locations\" :[{\" line\" :2,\" column\" :13}]"
66+
67+ if includeExtensions then
68+ errorFields.Add " \" extensions\" :{\" code\" :\" UNIT_TEST\" ,\" retryable\" :false,\" severity\" :7}"
69+
70+ let responseJson =
71+ $""" {{"errors":[{{{String.concat "," errorFields}}}]}}"""
72+
73+ let result =
74+ OperationResultBase(
75+ rawResponse = new HttpResponseMessage(),
76+ responseJson = JsonValue.Parse responseJson,
77+ operationFields = [||],
78+ operationTypeName = " Query"
79+ )
80+
81+ result.Errors.Length |> equals 1
82+
83+ let error : FSharp.Data.GraphQL.OperationError = result.Errors.[ 0 ]
84+ error.Message |> equals " unit-test combination error"
85+
86+ if includePath then
87+ error.Path |> equals [| box " alwaysError" ; box 0 |]
88+ else
89+ error.Path |> equals [||]
90+
91+ if includeLocations then
92+ error.Locations |> equals [| { Line = 2 ; Column = 13 } |]
93+ else
94+ error.Locations |> equals [||]
95+
96+ if includeExtensions then
97+ error.Extensions.[ " code" ] |> equals ( box " UNIT_TEST" )
98+ error.Extensions.[ " retryable" ] |> equals ( box false )
99+ error.Extensions.[ " severity" ] |> equals ( box 7 )
100+ else
101+ error.Extensions |> equals Map.empty
102+
50103[<Fact; Trait( " OperationError" , " Integration" ) >]
51104let ``Should map server error extensions and locations into operation result`` () =
52105 let result = ErrorOperation.operation.Run()
0 commit comments