Skip to content

Commit 1a04300

Browse files
Copilotxperiandri
andcommitted
Migrate client JSON serialization from JsonValue.fs to System.Text.Json
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/f2373ad8-e1ad-4cd6-8854-dc45f7e71e0c Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 24902f1 commit 1a04300

7 files changed

Lines changed: 485 additions & 343 deletions

File tree

src/FSharp.Data.GraphQL.Client.DesignTime/FSharp.Data.GraphQL.Client.DesignTime.fsproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ExcludeAssets>contentFiles;runtime</ExcludeAssets>
2121
</PackageReference>
2222
<PackageReference Include="FSharp.TypeProviders.SDK" VersionOverride="8.1.0" />
23+
<PackageReference Include="FSharp.SystemTextJson" />
2324
<PackageReference Include="FsToolkit.ErrorHandling" />
2425
<PackageReference Include="FParsec" />
2526
<PackageReference Include="Microsoft.Extensions.Http">
@@ -29,8 +30,6 @@
2930

3031
<ItemGroup>
3132
<Compile Include="..\FSharp.Data.GraphQL.Client\MimeTypes.fs" />
32-
<Compile Include="..\FSharp.Data.GraphQL.Client\TextConversions.fs" />
33-
<Compile Include="..\FSharp.Data.GraphQL.Client\JsonValue.fs" />
3433
<Compile Include="..\FSharp.Data.GraphQL.Client\Extensions.fs" />
3534
<Compile Include="..\FSharp.Data.GraphQL.Client\Schema.fs" />
3635
<Compile Include="..\FSharp.Data.GraphQL.Client\ReflectionPatterns.fs" />

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,9 @@ module internal ProvidedOperation =
409409
then Tracer.runAndMeasureExecutionTime "Ran a multipart GraphQL query request" (fun _ -> GraphQLClient.sendMultipartRequest context.Connection request)
410410
else Tracer.runAndMeasureExecutionTime "Ran a GraphQL query request" (fun _ -> GraphQLClient.sendRequest context.Connection request)
411411
let responseString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult()
412-
let responseJson = Tracer.runAndMeasureExecutionTime "Parsed a GraphQL response to a JsonValue" (fun _ -> JsonValue.Parse responseString)
413412
// If the user does not provide a context, we should dispose the default one after running the query
414413
if isDefaultContext then (context :> IDisposable).Dispose()
415-
OperationResultBase(response, responseJson, %%operationFieldsExpr, operationTypeName) @@>
414+
new OperationResultBase(response, responseString, %%operationFieldsExpr, operationTypeName) @@>
416415
let methodParameters = overloadParameters |> List.map (fun struct (name, _, t) -> ProvidedParameter(name, t, ?optionalValue = if isOption t then Some null else None))
417416
let methodDef = ProvidedMethod("Run", methodParameters, operationResultDef, invoker)
418417
methodDef.AddXmlDoc("Executes the operation on the server and fetch its results.")
@@ -457,17 +456,16 @@ module internal ProvidedOperation =
457456
then Tracer.asyncRunAndMeasureExecutionTime "Ran a multipart GraphQL query request asynchronously" (fun _ -> GraphQLClient.sendMultipartRequestAsync ct context.Connection request |> Async.AwaitTask)
458457
else Tracer.asyncRunAndMeasureExecutionTime "Ran a GraphQL query request asynchronously" (fun _ -> GraphQLClient.sendRequestAsync ct context.Connection request |> Async.AwaitTask)
459458
let! responseString = response.Content.ReadAsStringAsync() |> Async.AwaitTask
460-
let responseJson = Tracer.runAndMeasureExecutionTime "Parsed a GraphQL response to a JsonValue" (fun _ -> JsonValue.Parse responseString)
461459
// If the user does not provide a context, we should dispose the default one after running the query
462460
if isDefaultContext then (context :> IDisposable).Dispose()
463-
return OperationResultBase(response, responseJson, %%operationFieldsExpr, operationTypeName)
461+
return new OperationResultBase(response, responseString, %%operationFieldsExpr, operationTypeName)
464462
} @@>
465463
let methodParameters = overloadParameters |> List.map (fun struct (name, _, t) -> ProvidedParameter(name, t, ?optionalValue = if isOption t then Some null else None))
466464
let methodDef = ProvidedMethod("AsyncRun", methodParameters, TypeMapping.makeAsync operationResultDef, invoker)
467465
methodDef.AddXmlDoc("Executes the operation asynchronously on the server and fetch its results.")
468466
upcast methodDef)
469467
let parseResultDef =
470-
let invoker (args : Expr list) = <@@ OperationResultBase(%%args.[1], JsonValue.Parse %%args.[2], %%operationFieldsExpr, operationTypeName) @@>
468+
let invoker (args : Expr list) = <@@ new OperationResultBase(%%args.[1], %%args.[2], %%operationFieldsExpr, operationTypeName) @@>
471469
let parameters = [
472470
ProvidedParameter("rawResponse", typeof<HttpResponseMessage>)
473471
ProvidedParameter("responseJson", typeof<string>)

0 commit comments

Comments
 (0)