7
7
require_relative "foo_helper"
8
8
9
9
class TestQueryResult < Minitest ::Test
10
- class DateTimeType < GraphQL ::Schema ::Scalar
11
- def self . coerce_input ( value , ctx )
12
- Time . iso8601 ( value )
13
- end
14
-
15
- def self . coerce_result ( value , ctx )
16
- value . utc . iso8601
17
- end
18
- end
19
-
20
10
module NodeType
21
11
include GraphQL ::Schema ::Interface
22
12
field :id , ID , null : false
@@ -58,7 +48,7 @@ class UserType < GraphQL::Schema::Object
58
48
59
49
module HumanLike
60
50
include GraphQL ::Schema ::Interface
61
- field :updated_at , DateTimeType , null : false
51
+ field :updated_at , GraphQL :: Types :: ISO8601DateTime , null : false
62
52
end
63
53
64
54
class PersonType < GraphQL ::Schema ::Object
@@ -69,7 +59,8 @@ class PersonType < GraphQL::Schema::Object
69
59
field :last_name , String , null : true
70
60
field :company , String , null : true
71
61
field :homepageURL , String , null : true , method : :homepage_url , camelize : false
72
- field :created_at , DateTimeType , null : false
62
+ field :created_at , GraphQL ::Types ::ISO8601DateTime , null : false
63
+ field :created_on , GraphQL ::Types ::ISO8601Date , null : false
73
64
field :hobbies , [ String ] , null : true
74
65
field :plan , PlanType , null : false
75
66
end
@@ -113,6 +104,7 @@ def me
113
104
last_name : "Peek" ,
114
105
company : "GitHub" ,
115
106
created_at : Time . at ( 0 ) ,
107
+ created_on : Date . new ( 1970 , 1 , 1 ) ,
116
108
updated_at : Time . at ( 1 ) ,
117
109
hobbies : [ "soccer" , "coding" ] ,
118
110
homepage_url : nil ,
@@ -133,6 +125,7 @@ def issue_or_pull_request
133
125
last_name : "Peek" ,
134
126
company : "GitHub" ,
135
127
created_at : Time . at ( 0 ) ,
128
+ created_on : Date . new ( 1970 , 1 , 1 ) ,
136
129
updated_at : Time . at ( 1 ) ,
137
130
hobbies : [ "soccer" , "coding" ] ,
138
131
plan : "LARGE"
@@ -596,7 +589,7 @@ def test_interface_within_union_values
596
589
assert_equal Time . at ( 1 ) . utc , actor . updated_at
597
590
end
598
591
599
- def test_date_scalar_casting
592
+ def test_datetime_scalar_casting
600
593
Temp . const_set :Query , @client . parse ( <<-'GRAPHQL' )
601
594
{
602
595
me {
@@ -615,6 +608,23 @@ def test_date_scalar_casting
615
608
assert_equal Time . at ( 1 ) , person . updated_at
616
609
end
617
610
611
+ def test_date_scalar_casting
612
+ Temp . const_set :Query , @client . parse ( <<-'GRAPHQL' )
613
+ {
614
+ me {
615
+ name
616
+ createdOn
617
+ }
618
+ }
619
+ GRAPHQL
620
+
621
+ response = @client . query ( Temp ::Query )
622
+
623
+ person = response . data . me
624
+ assert_equal "Josh" , person . name
625
+ assert_equal Date . new ( 1970 , 1 , 1 ) , person . created_on
626
+ end
627
+
618
628
include FooHelper
619
629
620
630
def test_source_location
0 commit comments