Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DateTimeOffset as Variable #222

Merged
merged 3 commits into from
Aug 1, 2022
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
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 @@ -88,5 +90,23 @@ public async Task Viewer_Has_No_OrganizationVerifiedDomainEmails_For_Octokit()

Assert.Empty(emails);
}

[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);
}
Comment on lines +94 to +110
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any better location for this?

}
}
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);
}
Comment on lines +321 to +340
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could put this into Core like in #214, but I need a DateTimeOffset parameter for this

}
}