Skip to content

Commit 9cc357d

Browse files
committed
fall back scalers to strings where there isn't a well known alternative
1 parent e2755ec commit 9cc357d

File tree

10 files changed

+100371
-96
lines changed

10 files changed

+100371
-96
lines changed

Tocsoft.GraphQLCodeGen.Cli/CodeGeneratorSettingsLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ private SimpleSourceFile Load(string path, CodeGeneratorSettingsLoaderDefaults s
235235

236236
if (string.IsNullOrWhiteSpace(file.Format))
237237
{
238-
file.Format = settings.Format;
238+
file.Format = settings.Format ?? "cs";
239239
}
240240
}
241241

Tocsoft.GraphQLCodeGen.Cli/TemplateEngine.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,16 @@ public TemplateEngine(IEnumerable<string> templates, IDictionary<string, string>
8080

8181
HandlebarsBlockHelper ifTemplateHelper = (output, options, context, args) =>
8282
{
83-
var val = this.engine.Compile("{{> " + args[0].ToString() + "}}")((object)context)?.ToString()?.Trim();
84-
var isSet = !string.IsNullOrWhiteSpace(val);
85-
86-
if (args.Length > 1)
83+
var isSet = false;
84+
if (registerTemplates.Contains(args[0].ToString(), StringComparer.OrdinalIgnoreCase)) // need to check if its case insenative
8785
{
88-
isSet = val.Equals(args[1]?.ToString());
86+
var val = this.engine.Compile("{{> " + args[0].ToString() + "}}")((object)context)?.ToString()?.Trim();
87+
isSet = !string.IsNullOrWhiteSpace(val);
88+
89+
if (args.Length > 1)
90+
{
91+
isSet = val.Equals(args[1]?.ToString());
92+
}
8993
}
9094

9195
if (isSet)
@@ -131,9 +135,15 @@ public TemplateEngine(IEnumerable<string> templates, IDictionary<string, string>
131135

132136
foreach (var a in templateArguments)
133137
{
134-
this.engine.RegisterTemplate(a.Key, a.Value);
138+
this.RegisterTemplate(a.Key, a.Value);
135139
}
136140
}
141+
List<string> registerTemplates = new List<string>();
142+
private void RegisterTemplate(string templateName, string template)
143+
{
144+
registerTemplates.Add(template);
145+
this.engine.RegisterTemplate(templateName, template);
146+
}
137147

138148

139149
private class NullEncoder : ITextEncoder
@@ -205,7 +215,7 @@ private void RegisterTemplate(StringBuilder sb, string currentTemplateName)
205215
}
206216
else
207217
{
208-
this.engine.RegisterTemplate(currentTemplateName, sb.ToString().TrimEnd());
218+
this.RegisterTemplate(currentTemplateName, sb.ToString().TrimEnd());
209219
}
210220
sb.Clear();
211221
}

Tocsoft.GraphQLCodeGen.Cli/Templates/cs/CSharp.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ namespace {{Namespace}}
307307
{{~/each~}}
308308

309309
{{!# TypeReference}}
310-
{{~#if IsScaler}}{{ > (concat 'TypeReference_' TypeName) }}
310+
{{~#if IsScaler}}
311+
{{~ifTemplate (concat 'TypeReference_' TypeName)~}}
312+
{{ > (concat 'TypeReference_' TypeName) }}
313+
{{~else~}}
314+
{{ > (concat 'TypeReference_String') }}
315+
{{~/ifTemplate~}}
311316
{{~else~}}
312317
{{~#if IsEnum~}}
313318
{{> RenderTypeReference name=TypeName prefix=true fixCase=true isValueType=true isCollection=IsCollection nullable=CanValueBeNull }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Tocsoft.GraphQLCodeGen.Cli;
5+
6+
namespace Tocsoft.GraphQLCodeGen.Tests
7+
{
8+
public class FakeLogger : ILogger
9+
{
10+
public bool HasErrors => logs?.Any(c => c.IsError) == true;
11+
public bool HasMessages => logs?.Any() == true;
12+
13+
private List<LogEntry> logs = new List<LogEntry>();
14+
15+
public IEnumerable<string> ErrorMessages => logs?.Where(x => x.IsError).Select(x => x.Message).ToArray() ?? Array.Empty<string>();
16+
17+
public void Error(string str)
18+
{
19+
logs = logs ?? new List<LogEntry>();
20+
var msg = new LogEntry(str, true);
21+
logs.Add(msg);
22+
}
23+
24+
public void Message(string str)
25+
{
26+
logs = logs ?? new List<LogEntry>();
27+
logs.Add(new LogEntry(str, false));
28+
}
29+
30+
public struct LogEntry
31+
{
32+
public LogEntry(string message, bool isError)
33+
{
34+
Message = message;
35+
IsError = isError;
36+
}
37+
public string Message { get; }
38+
public bool IsError { get; }
39+
}
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
query($repository:String!, $owner:String!, $tag:String!) {
3+
repository(name:$repository, owner:$owner){
4+
ref(qualifiedName: $tag){
5+
name
6+
target{
7+
... on Commit {
8+
history(first:100){
9+
nodes{
10+
id,
11+
oid,
12+
message
13+
}
14+
}
15+
}
16+
}
17+
}}
18+
}

0 commit comments

Comments
 (0)