Skip to content

Commit bf56d00

Browse files
committed
Refactor GraphQLClient to use default options for JSON serialization and update documentation in GraphQLRequestOptions
1 parent 6318a1d commit bf56d00

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

GraphQLSharp/Client/GraphQLClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private async Task<GraphQLResponse<T>> ExecuteCoreAsync<T>(GraphQLRequest reques
6262
GraphQLResponse<T> res;
6363
try
6464
{
65-
res = await httpResponseMsg.Content.ReadFromJsonAsync<GraphQLResponse<T>>(Serializer.Options, cancellationToken);
65+
res = await httpResponseMsg.Content.ReadFromJsonAsync<GraphQLResponse<T>>(_defaultOptions.JsonSerializerOptions ?? options.JsonSerializerOptions ?? Serializer.Options, cancellationToken);
6666
if (res == null)
6767
throw new GraphQLException(request, httpResponse, $"Failed to deserialize null GraphQL response. Request: {request}");
6868
}
@@ -93,7 +93,7 @@ private HttpRequestMessage CreateHttpRequest(GraphQLRequest request, GraphQLRequ
9393
{
9494
Method = HttpMethod.Post,
9595
RequestUri = uri,
96-
Content = JsonContent.Create(request, options: Serializer.Options),
96+
Content = JsonContent.Create(request, options: _defaultOptions.JsonSerializerOptions ?? options.JsonSerializerOptions ?? Serializer.Options),
9797
};
9898

9999
requestMessage.Headers.UserAgent.Add(_defaultUserAgent);

GraphQLSharp/Client/GraphQLRequestOptions.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net.Http.Headers;
2+
using System.Text.Json;
23

34
namespace GraphQLSharp;
45

@@ -18,20 +19,25 @@ public class GraphQLRequestOptions
1819
public Uri Uri { get; set; }
1920

2021
/// <summary>
21-
/// HttpClient to be used/
22+
/// An (optional) custom HttpClient to be used for sending requests.
2223
/// If null, a default shared HttpClient is used
2324
/// If set, you control the lifetime of the HttpClient.
2425
/// </summary>
2526
public HttpClient HttpClient { get; set; }
2627

2728
/// <summary>
28-
/// A configuration callback to modify the HttpRequestHeaders before sending the request.
29+
/// An (optional) configuration callback to modify the HttpRequestHeaders before sending the request.
2930
/// This can be used to set custom headers, authentication tokens, etc.
3031
/// </summary>
3132
public Action<HttpRequestHeaders> ConfigureHttpRequestHeaders { get; set; }
3233

3334
/// <summary>
34-
/// Interceptor to be used for this request.
35+
/// An (optional) JSON serializer options to be used for serializing and deserializing GraphQL requests and responses.
36+
/// </summary>
37+
public JsonSerializerOptions JsonSerializerOptions { get; set; }
38+
39+
/// <summary>
40+
/// An (optional) Interceptor to be used for this request.
3541
/// </summary>
3642
public IInterceptor Interceptor { get; set; }
3743
}

0 commit comments

Comments
 (0)