Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<PackageReference Update="System.Diagnostics.DiagnosticSource" Version="$(SystemVersion)" />
<PackageReference Update="System.Formats.Asn1" Version="$(SystemVersion)" />
<PackageReference Update="System.Management" Version="6.*" />
<PackageReference Update="System.Memory" Version="4.6.*" />
<PackageReference Update="System.Reactive" Version="6.*" NoWarn="NU1608" />
<PackageReference Update="System.Text.Json" Version="$(SystemVersion)" />
<PackageReference Update="System.Text.RegularExpressions" Version="4.3.1" />
Expand Down
13 changes: 7 additions & 6 deletions src/FSharp.Data.GraphQL.Client/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ open System.Security.Cryptography
/// Extensions for types used by the GraphQL client library.
[<AutoOpen>]
module internal Extensions =

let private changeFirstChar mapping (s : string) =
let span = s.AsSpan()
let c = mapping span[0]
if c = span[0] then s else string c + span.Slice(1).ToString()

type String with
/// Returns the input string with the first character in upper case.
member this.FirstCharUpper() =
this.Substring(0, 1).ToUpperInvariant() + this.Substring(1)

/// Returns the input string with the first character in lower case.
member this.FirstCharLower() =
this.Substring(0, 1).ToLowerInvariant() + this.Substring(1)
member this.FirstCharUpper () = changeFirstChar Char.ToUpperInvariant this

member this.MD5Hash() =
Encoding.UTF8.GetBytes(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Memory" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/FSharp.Data.GraphQL.Client/GraphQLClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.Collections.Generic
open System.Collections.Immutable
open System.Net.Http
open System.Text
open System.Text.Json
open System.Threading
open System.Threading.Tasks

Expand Down Expand Up @@ -131,7 +132,7 @@ module GraphQLClient =
| :? IDictionary<string, obj> as x ->
x
|> Seq.collect (fun kvp ->
tryMapFileVariable (name + "." + (kvp.Key.FirstCharLower ()), kvp.Value)
tryMapFileVariable (name + "." + JsonNamingPolicy.CamelCase.ConvertName kvp.Key, kvp.Value)
|> Option.defaultValue [||])
|> Array.ofSeq
|> Some
Expand Down
5 changes: 3 additions & 2 deletions src/FSharp.Data.GraphQL.Client/Serialization.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open System.Collections.Generic
open System.Diagnostics
open System.Globalization
open System.Reflection
open System.Text.Json
open Microsoft.FSharp.Reflection
open FSharp.Data.GraphQL
open FSharp.Data.GraphQL.Client.ReflectionPatterns
Expand Down Expand Up @@ -176,7 +177,7 @@ module Serialization =
| :? Upload as u -> JsonValue.String u.Name
| :? IDictionary<string, obj> as items ->
items
|> Seq.map (fun (KeyValue (k, v)) -> k.FirstCharLower(), toJsonValue v)
|> Seq.map (fun (KeyValue (k, v)) -> JsonNamingPolicy.CamelCase.ConvertName k, toJsonValue v)
|> Seq.toArray
|> JsonValue.Record
| EnumerableValue items ->
Expand All @@ -187,7 +188,7 @@ module Serialization =
| EnumValue x -> JsonValue.String x
| _ ->
let props = t.GetProperties(BindingFlags.Public ||| BindingFlags.Instance)
let items = props |> Array.map (fun p -> (p.Name.FirstCharLower(), p.GetValue(x) |> toJsonValue))
let items = props |> Array.map (fun p -> (JsonNamingPolicy.CamelCase.ConvertName p.Name, p.GetValue(x) |> toJsonValue))
JsonValue.Record items)

let serializeRecord (x : obj) =
Expand Down
Loading