Skip to content

Commit 21ddd51

Browse files
pkesexperiandri
authored andcommitted
Skip populating Nullable fields with nulls
1 parent 552a3d1 commit 21ddd51

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,19 @@ let rec internal compileByType (inputObjectPath: FieldPath) (inputSource : Input
9696
{ new Reflection.ParameterInfo() with
9797
member _.Name = f.Name
9898
member _.ParameterType = f.TypeDef.Type
99-
member _.Attributes = Reflection.ParameterAttributes.Optional
99+
member _.Attributes =
100+
match f.TypeDef with
101+
| Nullable _ -> Reflection.ParameterAttributes.Optional
102+
| _ -> Reflection.ParameterAttributes.None
100103
}
101104
|]
102105
let constructor (args:obj[]) =
103106
let o = Activator.CreateInstance(objtype)
104107
let dict = o :?> IDictionary<string, obj>
105108
for fld,arg in Seq.zip objDef.Fields args do
106-
dict.Add(fld.Name, arg)
109+
match arg, fld.TypeDef with
110+
| null, Nullable _ -> () // skip populating Nullable fields with nulls
111+
| _, _ -> dict.Add(fld.Name, arg)
107112
box o
108113
constructor, parameterInfos
109114
else

0 commit comments

Comments
 (0)