Skip to content

Commit 9e9873a

Browse files
committed
Update DI and serialization logic for GraphQL client
Replaces singleton registration in DI with keyed singleton for better service resolution. Updates `JsonSerializerOptions` initialization to simplified syntax and removes unnecessary properties. Refines error-handling logic in query execution and adjusts template to support keyed service injection.
1 parent 02ddff2 commit 9e9873a

4 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/Linq2GraphQL.Client/GraphClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ public GraphClient(HttpClient httpClient, IOptions<GraphClientOptions> options,
2222

2323
HttpClient = httpClient;
2424

25-
SerializerOptions = new JsonSerializerOptions
25+
SerializerOptions = new()
2626
{
2727
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
28-
WriteIndented = true
28+
Converters = { }
2929
};
3030

3131
SubscriptionUrl = GetSubscriptionUrl();

src/Linq2GraphQL.Client/QueryExecutor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public T ProcessResponse(string con, string name, string query)
4040
throw new GraphQueryExecutionException(errors, query);
4141
}
4242

43-
var hasData = document.RootElement.TryGetProperty(dataPathPropertyName, out var dataElement);
44-
var hasResult = dataElement.TryGetProperty(name, out var resultElement);
43+
document.RootElement.TryGetProperty(dataPathPropertyName, out var dataElement);
44+
dataElement.TryGetProperty(name, out var resultElement);
4545

4646
if (resultElement.ValueKind == JsonValueKind.Null)
4747
{

src/Linq2GraphQL.Generator/Templates/Client/ClientTemplate.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace <#= namespaceName #>;
99

1010
public class <#= name #>
1111
{
12-
public <#= name #>(HttpClient httpClient, IOptions<GraphClientOptions> options, IServiceProvider provider)
12+
public <#= name #>(HttpClient httpClient, [FromKeyedServices("<#= name #>")]IOptions<GraphClientOptions> options, IServiceProvider provider)
1313
{
1414
var client = new GraphClient(httpClient, options, provider);
1515
<# if (includeQuery) { #>

test/Linq2GraphQL.TestClient/Generated/Client/SampleClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ private static IGraphClientBuilder<SampleClient> GraphClientBuilder(IServiceColl
2626
GraphClientOptions graphClientOptions)
2727
{
2828
var opts = Options.Create(graphClientOptions);
29-
services.AddSingleton(opts);
29+
services.AddKeyedSingleton(opts, ClientName);
3030
services.AddMemoryCache();
3131
return new ClientBuilder<SampleClient>(ClientName, services);
3232
}

0 commit comments

Comments
 (0)