Skip to content

Commit 443718a

Browse files
committed
allow configuring the generation timeout via msbuild properties
1 parent 8f0d16a commit 443718a

11 files changed

Lines changed: 53 additions & 27 deletions

File tree

Samples/ClientSample/Client/DllIntrospection/gqlsettings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

Samples/ClientSample/Client/DllIntrospection/single.gql

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#! schema:../../GraphQLApiSample/GraphQLApiSample/bin/Debug/netcoreapp1.0/GraphQLApiSample.dll
2+
#! output: Client.cs
3+
#! class: Sample.Client.GitHub.Tmp
4+
5+
query {
6+
viewer {
7+
name
8+
}
9+
}

Samples/ClientSample/Sample.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<OutputType>Exe</OutputType>
66
<TargetFramework>netcoreapp2.0</TargetFramework>
77
<RunGraphQLCodeGen>true</RunGraphQLCodeGen>
8+
<GraphQLCodeGenTimeOut>10000</GraphQLCodeGenTimeOut>
89
</PropertyGroup>
910

1011
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

Tocsoft.GraphQLCodeGen.Cli/CodeGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public async Task<bool> GenerateAsync()
6767

6868
Models.ViewModel model = new Models.ViewModel(doc, this.settings);
6969

70-
string fileResult = new TemplateEngine(this.settings.Templates).Generate(model);
70+
string fileResult = new TemplateEngine(this.settings.Templates, logger).Generate(model);
7171

7272
Directory.CreateDirectory(Path.GetDirectoryName(this.settings.OutputPath));
7373
File.WriteAllText(this.settings.OutputPath, fileResult);

Tocsoft.GraphQLCodeGen.Cli/RelectionHelpers/GraphQLConventionsRequestHandlerBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ internal class GraphQLConventionsRequestHandlerBuilder
1717
public GraphQLConventionsRequestHandlerBuilder( Assembly conventionsAssembly)
1818
{
1919
var allTypes = conventionsAssembly.AllLoadableTypes();
20-
var builderType = allTypes.Single(x=>x.FullName == "GraphQL.Conventions.Web.RequestHandler+RequestHandlerBuilder");
21-
var rootHandler = allTypes.Single(x => x.FullName == "GraphQL.Conventions.Web.RequestHandler");
20+
var builderType = allTypes.SingleOrDefault(x=>x.FullName == "GraphQL.Conventions.Web.RequestHandler+RequestHandlerBuilder");
21+
var rootHandler = allTypes.SingleOrDefault(x => x.FullName == "GraphQL.Conventions.Web.RequestHandler");
2222
var newBuidlerMethod = rootHandler.GetMethod("New");
2323

2424
this.builder = newBuidlerMethod.Invoke(null, new object[0]);

Tocsoft.GraphQLCodeGen.Cli/TemplateEngine.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
using System.IO;
66
using System.Reflection;
77
using System.Linq;
8+
using Tocsoft.GraphQLCodeGen.Cli;
9+
using System.Text.RegularExpressions;
810

911
namespace Tocsoft.GraphQLCodeGen
1012
{
1113
public class TemplateEngine
1214
{
15+
private readonly ILogger logger;
1316
private IHandlebars engine;
1417

15-
public TemplateEngine(IEnumerable<string> templates)
18+
public TemplateEngine(IEnumerable<string> templates, ILogger logger)
1619
{
17-
20+
this.logger = logger;
1821
this.engine = HandlebarsDotNet.Handlebars.Create(new HandlebarsConfiguration
1922
{
2023
ThrowOnUnresolvedBindingExpression = true
@@ -79,8 +82,17 @@ public string Encode(string value)
7982

8083
public string Generate(object model)
8184
{
82-
Func<object, string> template = this.engine.Compile("{{> Main}}");
83-
return template.Invoke(model);
85+
try
86+
{
87+
Func<object, string> template = this.engine.Compile("{{> Main}}");
88+
return template.Invoke(model);
89+
}
90+
catch (Exception ex)
91+
{
92+
logger.Error(ex.ToString());
93+
//throw ex;
94+
return "";
95+
}
8496
}
8597

8698

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ namespace {{Namespace}}
152152
{{!# TypeReference_DateTime}}
153153
{{~> RenderTypeReference name='DateTime' isValueType=true fixCase=false isCollection=IsCollection nullable=CanValueBeNull }}
154154

155+
{{!# TypeReference_GUID}}
156+
{{~> RenderTypeReference name='Guid' isValueType=true fixCase=false isCollection=IsCollection nullable=CanValueBeNull }}
157+
155158
{{!# RenderTypeReference}}
156159
{{~#if isCollection }}IEnumerable<{{/if~}}
157160
{{#if fixCase}}{{pascalCase name}}{{/if}}{{#unless fixCase}}{{name}}{{/unless}}

Tocsoft.GraphQLCodeGen.MsBuild/GenerateGraphQLClient.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class GenerateGraphQLClient : Task
2424
[Required]
2525
public string IntermediateOutputDirectory { get; set; }
2626

27+
[Required]
28+
public string Timeout { get; set; }
29+
2730
[Output]
2831
public ITaskItem[] GeneratedCompile { get; set; }
2932

@@ -78,7 +81,22 @@ public override bool Execute()
7881
RedirectStandardOutput = true,
7982
RedirectStandardError = true
8083
});
81-
process.WaitForExit(5000);
84+
85+
Debugger.Launch();
86+
// default timeout of 5 seconds
87+
int timeout = 5000;
88+
if (!int.TryParse(this.Timeout, out timeout))
89+
{
90+
timeout = 5000;
91+
}
92+
93+
// min timeout of 5 seconds
94+
if (timeout < 5000)
95+
{
96+
timeout = 5000;
97+
}
98+
99+
process.WaitForExit(timeout);
82100
if (!process.HasExited)
83101
{
84102
process.Kill();

Tocsoft.GraphQLCodeGen.MsBuild/build/Tocsoft.GraphQLCodeGen.MsBuild.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<GraphQLCodeGenAssembly>$(GraphQLCodeGenAssemblyFolder)\Tocsoft.GraphQLCodeGen.MsBuild.dll</GraphQLCodeGenAssembly>
99
<RunGraphQLCodeGen Condition="'$(RunGraphQLCodeGen)' == ''">true</RunGraphQLCodeGen>
10+
<GraphQLCodeGenTimeOut Condition="'$(GraphQLCodeGenTimeOut)' == ''">5000</GraphQLCodeGenTimeOut>
1011
</PropertyGroup>
1112

1213
<ItemDefinitionGroup>

0 commit comments

Comments
 (0)