Skip to content

Commit 8c34550

Browse files
committed
Skip populating Nullable fields with nulls
1 parent 8cb230d commit 8c34550

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,19 @@ let rec internal compileByType
112112
{ new Reflection.ParameterInfo() with
113113
member _.Name = f.Name
114114
member _.ParameterType = f.TypeDef.Type
115-
member _.Attributes = Reflection.ParameterAttributes.Optional
115+
member _.Attributes =
116+
match f.TypeDef with
117+
| Nullable _ -> Reflection.ParameterAttributes.Optional
118+
| _ -> Reflection.ParameterAttributes.None
116119
}
117120
|]
118121
let constructor (args:obj[]) =
119122
let o = Activator.CreateInstance(objtype)
120123
let dict = o :?> IDictionary<string, obj>
121124
for fld,arg in Seq.zip objDef.Fields args do
122-
dict.Add(fld.Name, arg)
125+
match arg, fld.TypeDef with
126+
| null, Nullable _ -> () // skip populating Nullable fields with nulls
127+
| _, _ -> dict.Add(fld.Name, arg)
123128
box o
124129
constructor, parameterInfos
125130
else

0 commit comments

Comments
 (0)