Skip to content

Commit

Permalink
Fix DateTimeOffset as Variable
Browse files Browse the repository at this point in the history
  • Loading branch information
LordJZ committed Apr 6, 2020
1 parent a0ae8ec commit 28d3a6b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Octokit.GraphQL.Core/Core/Syntax/VariableDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public static string ToTypeName(Type type, bool isNullable)
{
name = "Boolean";
}
else if (type == typeof(DateTimeOffset))
{
name = "DateTime";
}
else if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
{
var inner = ToTypeName(type.GenericTypeArguments[0], false);
Expand Down
22 changes: 21 additions & 1 deletion Octokit.GraphQL.IntegrationTests/Queries/ViewerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Octokit.GraphQL.Core;
using Octokit.GraphQL.IntegrationTests.Utilities;
Expand Down Expand Up @@ -78,5 +80,23 @@ public async Task Viewer_By_GraphyQL_Matches_Api()
//PublicGists
//TotalPrivateRepos
}

[IntegrationTest]
public async Task DateTime_Filter_Works()
{
var query = new GraphQL.Query()
.Viewer.ContributionsCollection(from: Variable.Var("start"))
.Select(c => c.User.Name);

var vars = new Dictionary<string, object>
{
{ "start", new DateTimeOffset(2000, 1, 2, 3, 4, 5, default) }
};

var response = await Connection.Run(query.Compile(), vars);

// no server error
Assert.NotNull(response);
}
}
}
21 changes: 21 additions & 0 deletions Octokit.GraphQL.UnitTests/QueryBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,26 @@ ... on User {

Assert.Equal(expected, query.ToString(), ignoreLineEndingDifferences: true);
}

[Fact]
public void DateTimeOffsetVariable()
{
var expected = @"query($start: DateTime) {
user(login: ""grokys"") {
contributionsCollection(from: $start) {
latestRestrictedContributionDate
}
}
}";

var expression = new Query()
.User("grokys")
.ContributionsCollection(@from: Variable.Var("start"))
.Select(c => c.LatestRestrictedContributionDate);

var query = expression.Compile();

Assert.Equal(expected, query.ToString(), ignoreLineEndingDifferences: true);
}
}
}

0 comments on commit 28d3a6b

Please sign in to comment.