Skip to content

Commit ed15e91

Browse files
committed
Extracted mapVariableValue into the VariableMapping module
1 parent 60f254f commit ed15e91

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/FSharp.Data.GraphQL.Client.DesignTime/ProvidedTypesHelper.fs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,7 @@ module internal ProvidedOperation =
322322
let buildVariablesExprFromArgs (varNames : string list) (args : Expr list) =
323323
let mapVariableExpr (name : string) (value : Expr) =
324324
let value = Expr.Coerce(value, typeof<obj>)
325-
<@@ let rec mapVariableValue (value : obj) =
326-
match value with
327-
| null -> null
328-
| :? string -> value // We need this because strings are enumerables, and we don't want to enumerate them recursively as an object
329-
| :? EnumBase as v -> v.GetValue() |> box
330-
| :? RecordBase as v -> v.ToDictionary() |> box
331-
| OptionValue v -> v |> Option.map mapVariableValue |> box
332-
| EnumerableValue v -> v |> Array.map mapVariableValue |> box
333-
| v -> v
334-
(name, mapVariableValue %%value) @@>
325+
<@@ (name, VariableMapping.mapVariableValue %%value) @@>
335326
let args =
336327
let varArgs = List.skip (args.Length - variables.Length) args
337328
(varNames, varArgs) ||> List.map2 mapVariableExpr

src/FSharp.Data.GraphQL.Client/BaseTypes.fs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,3 +459,17 @@ type OperationResultBase (rawResponse: HttpResponseMessage, responseJson : JsonV
459459
type OperationBase (query : string) =
460460
/// Gets the query string of the operation.
461461
member _.Query = query
462+
463+
module VariableMapping =
464+
465+
open FSharp.Data.GraphQL.Client.ReflectionPatterns
466+
467+
let rec mapVariableValue (value : obj) =
468+
match value with
469+
| null -> null
470+
| :? string -> value
471+
| :? EnumBase as v -> v.GetValue() |> box
472+
| :? RecordBase as v -> v.ToDictionary() |> box
473+
| OptionValue v -> v |> Option.map mapVariableValue |> box
474+
| EnumerableValue v -> v |> Array.map mapVariableValue |> box
475+
| v -> v

0 commit comments

Comments
 (0)