From 059ea376025d8cb3ef9e620314c77e5fea2aa3d5 Mon Sep 17 00:00:00 2001 From: Rickard Redler Date: Thu, 18 Sep 2025 22:30:33 +0200 Subject: [PATCH 1/2] Refactor GraphClient constructor to add an overload for optional includeDeprecated parameter. Clean up whitespace in GraphClient and ClientGenerator files for improved readability. Update project file to enable TransformOnBuild to avoid forgetting to do that. --- src/Linq2GraphQL.Client/GraphClient.cs | 10 +++++++--- src/Linq2GraphQL.Generator/ClientGenerator.cs | 4 ++-- .../Linq2GraphQL.Generator.csproj | 1 + 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Linq2GraphQL.Client/GraphClient.cs b/src/Linq2GraphQL.Client/GraphClient.cs index d3e0e294..68a551df 100644 --- a/src/Linq2GraphQL.Client/GraphClient.cs +++ b/src/Linq2GraphQL.Client/GraphClient.cs @@ -1,6 +1,5 @@ using System.Text.Json; using System.Text.Json.Serialization; -using Linq2GraphQL.Client.Converters; using Linq2GraphQL.Client.Schema; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.DependencyInjection; @@ -14,6 +13,11 @@ public class GraphClient private readonly IOptions options; private readonly bool includeDeprecated; + public GraphClient(HttpClient httpClient, IOptions options, IServiceProvider provider) + : this(httpClient, options, provider, false) + { + } + public GraphClient(HttpClient httpClient, IOptions options, IServiceProvider provider, bool includeDeprecated = false) { this.options = options; @@ -38,7 +42,7 @@ public GraphClient(HttpClient httpClient, IOptions options, public SubscriptionProtocol SubscriptionProtocol => options.Value.SubscriptionProtocol; public HttpClient HttpClient { get; } public JsonSerializerOptions SerializerOptions { get; } - + public Func> WSConnectionInitPayload => options.Value.WSConnectionInitPayload; private string GetSubscriptionUrl() @@ -85,7 +89,7 @@ public async Task GetSchemaForSafeModeAsync() query = Helpers.SchemaQuery; } - var graphRequest = new GraphQLRequest { Query = query }; + var graphRequest = new GraphQLRequest { Query = query }; return await executor.ExecuteRequestAsync("__schema", graphRequest); }); } diff --git a/src/Linq2GraphQL.Generator/ClientGenerator.cs b/src/Linq2GraphQL.Generator/ClientGenerator.cs index 9fe195ec..b6adf451 100644 --- a/src/Linq2GraphQL.Generator/ClientGenerator.cs +++ b/src/Linq2GraphQL.Generator/ClientGenerator.cs @@ -52,7 +52,7 @@ public async Task> GenerateAsync(Uri uri, string authToken = nul query = General.IntrospectionQuery; } - using var response = await httpClient.PostAsJsonAsync(uri, new { query = query }); + using var response = await httpClient.PostAsJsonAsync(uri, new { query = query }); if (!response.IsSuccessStatusCode) { throw new Exception( @@ -106,7 +106,7 @@ public List Generate(string schemaJson) var classInterfacesList = schema.GetClassTypes()?.Where(e => e.HasInterfaces) ?.SelectMany(i => i.Interfaces?.ToDictionary(e => i.Name, e => e.Name))?.ToList() ?? new List>(); - + var interfaces = schema.GetInterfaces(); if (interfaces != null) { diff --git a/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj b/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj index 10fbf8b9..8474319f 100644 --- a/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj +++ b/src/Linq2GraphQL.Generator/Linq2GraphQL.Generator.csproj @@ -6,6 +6,7 @@ enable true Linq2GraphQL + true Joakim Dangården, Magnus Ahlberg Linq2GraphQL From b918f8244c738fdb1bacb98eeae3d6f2902704f4 Mon Sep 17 00:00:00 2001 From: Rickard Redler Date: Fri, 3 Oct 2025 20:26:44 +0200 Subject: [PATCH 2/2] Added support for newer HCL that does not set descriptions for scalar types. --- .../Templates/Scalars/ScalarTemplate.cs | 6 +++--- .../Templates/Scalars/ScalarTemplate.tt | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs index 2c78fa4f..d47349c1 100644 --- a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs +++ b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.cs @@ -37,10 +37,10 @@ public virtual string TransformText() #line default #line hidden this.Write(";\r\n\r\n /// \r\n /// "); - + #line 13 "C:\Data\Linq2GraphQL.Client-1\src\Linq2GraphQL.Generator\Templates\Scalars\ScalarTemplate.tt" - this.Write(this.ToStringHelper.ToStringWithCulture(scalarType.SummaryDescription)); - + this.Write(this.ToStringHelper.ToStringWithCulture(scalarType.SummaryDescription ?? $"Represents the {scalarType.Name} scalar type")); + #line default #line hidden this.Write("\r\n /// \r\n [JsonConverter(typeof(CustomScalarConverter<"); diff --git a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.tt b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.tt index b9753998..d3d34702 100644 --- a/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.tt +++ b/src/Linq2GraphQL.Generator/Templates/Scalars/ScalarTemplate.tt @@ -10,7 +10,7 @@ using System.Text.Json.Serialization; namespace <#= namespaceName #>; /// - /// <#= scalarType.SummaryDescription #> + /// <#= scalarType.SummaryDescription ?? $"Represents the {scalarType.ScalarTypeName} scalar type" #> /// [JsonConverter(typeof(CustomScalarConverter<<#= className #>>))] public partial class <#= className #> : CustomScalar {} \ No newline at end of file