Skip to content

Commit d80b77c

Browse files
Andrii Chebukinxperiandri
authored andcommitted
Added constants for F# optional type names
1 parent dbdcaeb commit d80b77c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,13 @@ module internal Gen =
130130

131131
module internal ReflectionHelper =
132132

133+
let [<Literal>] OptionTypeName = "Microsoft.FSharp.Core.FSharpOption`1"
134+
let [<Literal>] ValueOptionTypeName = "Microsoft.FSharp.Core.FSharpValueOption`1"
135+
133136
let isParameterOptional (p: ParameterInfo) =
134137
p.IsOptional
135-
|| p.ParameterType.FullName.StartsWith "Microsoft.FSharp.Core.FSharpOption`1"
136-
|| p.ParameterType.FullName.StartsWith "Microsoft.FSharp.Core.FSharpValueOption`1"
138+
|| p.ParameterType.FullName.StartsWith OptionTypeName
139+
|| p.ParameterType.FullName.StartsWith ValueOptionTypeName
137140

138141
let isPrameterMandatory = not << isParameterOptional
139142

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ open FSharp.Data.GraphQL
2020

2121
let private wrapOptionalNone (outputType: Type) (inputType: Type) =
2222
if inputType.Name <> outputType.Name then
23-
if outputType.FullName.StartsWith "Microsoft.FSharp.Core.FSharpValueOption`1" then
23+
if outputType.FullName.StartsWith ReflectionHelper.ValueOptionTypeName then
2424
let _, valuenone, _ = ReflectionHelper.vOptionOfType outputType.GenericTypeArguments[0]
2525
valuenone
2626
elif outputType.IsValueType then
@@ -35,12 +35,12 @@ let private wrapOptional (outputType: Type) value=
3535
| value ->
3636
let inputType = value.GetType()
3737
if inputType.Name <> outputType.Name then
38-
let expectedType = outputType.GenericTypeArguments[0]
39-
if outputType.FullName.StartsWith "Microsoft.FSharp.Core.FSharpOption`1" && expectedType.IsAssignableFrom inputType then
40-
let some, _, _ = ReflectionHelper.optionOfType outputType.GenericTypeArguments[0]
38+
let expectedOutputType = outputType.GenericTypeArguments[0]
39+
if outputType.FullName.StartsWith ReflectionHelper.OptionTypeName && expectedOutputType.IsAssignableFrom inputType then
40+
let some, _, _ = ReflectionHelper.optionOfType expectedOutputType
4141
some value
42-
elif outputType.FullName.StartsWith "Microsoft.FSharp.Core.FSharpValueOption`1" && expectedType.IsAssignableFrom inputType then
43-
let valuesome, _, _ = ReflectionHelper.vOptionOfType outputType.GenericTypeArguments[0]
42+
elif outputType.FullName.StartsWith ReflectionHelper.ValueOptionTypeName && expectedOutputType.IsAssignableFrom inputType then
43+
let valuesome, _, _ = ReflectionHelper.vOptionOfType expectedOutputType
4444
valuesome value
4545
else
4646
value

0 commit comments

Comments
 (0)