Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/dotnet-gqlgen/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, TypeInfo> Types { get; set; }
public Dictionary<string, List<EnumInfo>> 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
{
Expand Down Expand Up @@ -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,
Expand All @@ -110,20 +122,20 @@ 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,
Types = allTypes,
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);
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet-gqlgen/dotnet-gqlgen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>dotnet_gqlgen</RootNamespace>
<PreserveCompilationContext>true</PreserveCompilationContext>
<PackageVersion>0.6.5</PackageVersion>
<PackageVersion>0.7.5</PackageVersion>
</PropertyGroup>

<PropertyGroup>
Expand Down
5 changes: 3 additions & 2 deletions src/dotnet-gqlgen/queryTypes.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@{
DisableEncoding = true;
}
@model ModelType
@using System.IO
@using dotnet_gqlgen;

Expand All @@ -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))
{
Expand All @@ -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)
{
Expand Down
9 changes: 5 additions & 4 deletions src/dotnet-gqlgen/resultTypes.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@{
DisableEncoding = true;
}
@model ModelType
@using System.IO
@using dotnet_gqlgen;

Expand All @@ -22,18 +23,18 @@ 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,
}
@:}
}

@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))
{
Expand All @@ -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)
{
Expand Down
Loading