Skip to content

Commit fa7a769

Browse files
authored
DateTime <-> DateTimeGraphType mapping (graphql-dotnet#1629)
1 parent 9434640 commit fa7a769

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/GraphQL.Tests/Bugs/Issue1082.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using GraphQL.Types;
3+
using Xunit;
4+
5+
namespace GraphQL.Tests.Bugs
6+
{
7+
public class Issue1082 : QueryTestBase<Issue1082Schema>
8+
{
9+
[Fact]
10+
public void Should_Return_DateTime_With_Time_Component()
11+
{
12+
var query = "{ dateTimeField }";
13+
AssertQuerySuccess(query, @"{""dateTimeField"": ""1000-10-10T01:02:03""}");
14+
}
15+
16+
[Fact]
17+
public void Should_Return_Date_Without_Time_Component()
18+
{
19+
var query = "{ dateField }";
20+
AssertQuerySuccess(query, @"{""dateField"": ""1000-10-10""}");
21+
}
22+
}
23+
24+
public class Issue1082Schema : Schema
25+
{
26+
public Issue1082Schema()
27+
{
28+
var query = new ObjectGraphType<Model>();
29+
query.Field(f => f.DateTimeField).Resolve(_ => new DateTime(1000, 10, 10, 1, 2, 3));
30+
query.Field(f => f.DateField, type: typeof(DateGraphType)).Resolve(_ => new DateTime(1000, 10, 10, 1, 2, 3).Date);
31+
Query = query;
32+
}
33+
34+
private class Model
35+
{
36+
public DateTime DateTimeField { get; set; }
37+
38+
public DateTime DateField { get; set; }
39+
}
40+
}
41+
}

src/GraphQL/Utilities/GraphTypeTypeRegistry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static class GraphTypeTypeRegistry
1717
[typeof(decimal)] = typeof(DecimalGraphType),
1818
[typeof(string)] = typeof(StringGraphType),
1919
[typeof(bool)] = typeof(BooleanGraphType),
20-
[typeof(DateTime)] = typeof(DateGraphType),
20+
[typeof(DateTime)] = typeof(DateTimeGraphType),
2121
[typeof(DateTimeOffset)] = typeof(DateTimeOffsetGraphType),
2222
[typeof(TimeSpan)] = typeof(TimeSpanSecondsGraphType),
2323
[typeof(Guid)] = typeof(IdGraphType),

0 commit comments

Comments
 (0)