Skip to content

Commit 4844839

Browse files
Thoriumxperiandri
andauthored
Added type information to error matching (#543)
Co-authored-by: Andrii Chebukin <[email protected]>
1 parent f88cab6 commit 4844839

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/FSharp.Data.GraphQL.Server/Values.fs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,10 @@ let rec internal compileByType
141141
if ReflectionHelper.isAssignableWithUnwrap inputType paramType then
142142
allParameters.Add (struct (ValueSome field, param))
143143
else
144-
// TODO: Consider improving by specifying type mismatches
145-
typeMismatchParameters.Add param.Name |> ignore
144+
let expectedType = inputDef.Type.ToString ()
145+
let actualType = paramType.ToString ()
146+
typeMismatchParameters.Add (struct (param.Name, expectedType, actualType))
147+
|> ignore
146148
| None ->
147149
if
148150
ReflectionHelper.isParameterSkippable param
@@ -172,10 +174,20 @@ let rec internal compileByType
172174
$"Input object %s{objDef.Name} refers to type '%O{objType}', but skippable '%s{``params``}' GraphQL fields and constructor parameters do not match"
173175
InvalidInputTypeException (message, skippableMismatchParameters.ToImmutableHashSet ())
174176
if typeMismatchParameters.Any () then
177+
178+
let typeMismatchParameterNames = HashSet ()
179+
180+
let details =
181+
typeMismatchParameters
182+
|> Seq.map (fun struct (name, expected, actual) ->
183+
typeMismatchParameterNames.Add name |> ignore
184+
$"Parameter '%s{name}': expected '%s{expected}', got %s{actual}")
185+
|> String.concat "; "
186+
175187
let message =
176188
let ``params`` = String.Join ("', '", typeMismatchParameters)
177-
$"Input object %s{objDef.Name} refers to type '%O{objType}', but GraphQL fields '%s{``params``}' have different types than constructor parameters"
178-
InvalidInputTypeException (message, typeMismatchParameters.ToImmutableHashSet ())
189+
$"Input object %s{objDef.Name} refers to type '%O{objType}', but GraphQL fields '%s{``params``}' have different types than constructor parameters: {details}"
190+
InvalidInputTypeException (message, typeMismatchParameterNames.ToImmutableHashSet ())
179191
]
180192
match exceptions with
181193
| [] -> ()

0 commit comments

Comments
 (0)