diff --git a/src/dotnet-gqlgen/Generator.cs b/src/dotnet-gqlgen/Generator.cs index 6a50c43..eaaaf97 100644 --- a/src/dotnet-gqlgen/Generator.cs +++ b/src/dotnet-gqlgen/Generator.cs @@ -23,6 +23,18 @@ public class GeneratorOptions public bool NoGeneratedTimestamp { get; set; } public bool ConvertToUnixLineEnding { get; set; } = true; } + + public class ModelType + { + public string Namespace { get; set; } + public string SchemaFile { get; set; } + public Dictionary Types { get; set; } + public Dictionary> Enums { get; set; } + public TypeInfo Mutation { get; set; } + public string CmdArgs { get; set; } + public string Usings { get; set; } + public bool NoGeneratedTimestamp { get; set; } + } public static class Generator { @@ -101,7 +113,7 @@ public static async Task Generate(GeneratorOptions options) var allTypes = typeInfo.Types.Concat(typeInfo.Inputs).ToDictionary(k => k.Key, v => v.Value); - string resultTypes = await engine.CompileRenderAsync("resultTypes.cshtml", new + string resultTypes = await engine.CompileRenderAsync("resultTypes.cshtml", new ModelType { Namespace = options.Namespace, SchemaFile = options.Source, @@ -110,12 +122,12 @@ public static async Task Generate(GeneratorOptions options) Mutation = typeInfo.Mutation, CmdArgs = $"-n {options.Namespace} -c {options.ClientClassName} -m {options.ScalarMapping} -u {options.Usings.Replace("\n", "\\n")}", Usings = options.Usings, - options.NoGeneratedTimestamp + NoGeneratedTimestamp = options.NoGeneratedTimestamp }); Directory.CreateDirectory(options.OutputDir); await NormalizeAndWriteIfChanged($"{options.OutputDir}/GeneratedResultTypes.cs", resultTypes, options.ConvertToUnixLineEnding); - string queryTypes = await engine.CompileRenderAsync("queryTypes.cshtml", new + string queryTypes = await engine.CompileRenderAsync("queryTypes.cshtml", new ModelType { Namespace = options.Namespace, SchemaFile = options.Source, @@ -123,7 +135,7 @@ public static async Task Generate(GeneratorOptions options) Mutation = typeInfo.Mutation, CmdArgs = $"-n {options.Namespace} -c {options.ClientClassName} -m {options.ScalarMapping} -u {options.Usings.Replace("\n", "\\n")}", Usings = options.Usings, - options.NoGeneratedTimestamp + NoGeneratedTimestamp = options.NoGeneratedTimestamp }); Directory.CreateDirectory(options.OutputDir); await NormalizeAndWriteIfChanged($"{options.OutputDir}/GeneratedQueryTypes.cs", queryTypes, options.ConvertToUnixLineEnding); diff --git a/src/dotnet-gqlgen/dotnet-gqlgen.csproj b/src/dotnet-gqlgen/dotnet-gqlgen.csproj index f127d2b..ea2af15 100644 --- a/src/dotnet-gqlgen/dotnet-gqlgen.csproj +++ b/src/dotnet-gqlgen/dotnet-gqlgen.csproj @@ -4,7 +4,7 @@ netstandard2.1 dotnet_gqlgen true - 0.6.5 + 0.7.5 diff --git a/src/dotnet-gqlgen/queryTypes.cshtml b/src/dotnet-gqlgen/queryTypes.cshtml index 6385d2d..b8307f6 100644 --- a/src/dotnet-gqlgen/queryTypes.cshtml +++ b/src/dotnet-gqlgen/queryTypes.cshtml @@ -1,6 +1,7 @@ @{ DisableEncoding = true; } +@model ModelType @using System.IO @using dotnet_gqlgen; @@ -22,7 +23,7 @@ using DotNetGqlClient; namespace @Model.Namespace { -@foreach(var gqlType in Model.Types.Values) +@foreach(var gqlType in Model.Types.Values.OrderBy(t => t.QueryName, StringComparer.Ordinal)) { if (!string.IsNullOrEmpty(gqlType.Description)) { @@ -33,7 +34,7 @@ namespace @Model.Namespace @:public abstract class @gqlType.QueryName : @gqlType.Name @:{ -@foreach(var field in gqlType.Fields) +@foreach(var field in gqlType.Fields.OrderBy(f => f.Name, StringComparer.Ordinal)) { @if (!field.ShouldBeProperty && !gqlType.IsInput) { diff --git a/src/dotnet-gqlgen/resultTypes.cshtml b/src/dotnet-gqlgen/resultTypes.cshtml index 98daf8a..a877948 100644 --- a/src/dotnet-gqlgen/resultTypes.cshtml +++ b/src/dotnet-gqlgen/resultTypes.cshtml @@ -1,6 +1,7 @@ @{ DisableEncoding = true; } +@model ModelType @using System.IO @using dotnet_gqlgen; @@ -22,10 +23,10 @@ using DotNetGqlClient; namespace @Model.Namespace { -@foreach(var kvp in Model.Enums) +@foreach(var kvp in Model.Enums.OrderBy(e => e.Key, StringComparer.Ordinal)) { @:public enum @kvp.Key { - @foreach(var field in kvp.Value) + @foreach(var field in kvp.Value.OrderBy(t => t.Name, StringComparer.Ordinal)) { @:[GqlFieldName("@field.Name")] @:@field.DotNetName, @@ -33,7 +34,7 @@ namespace @Model.Namespace @:} } -@foreach(var gqlType in Model.Types.Values) +@foreach(var gqlType in Model.Types.Values.OrderBy(t => t.Name, StringComparer.Ordinal)) { if (!string.IsNullOrEmpty(gqlType.Description)) { @@ -44,7 +45,7 @@ namespace @Model.Namespace @* We make interfaces as classes for now *@ @:public class @gqlType.Name @:{ -@foreach(var field in gqlType.Fields) +@foreach(var field in gqlType.Fields.OrderBy(f => f.Name, StringComparer.Ordinal)) { @if (field.ShouldBeProperty || gqlType.IsInput) {