@@ -9,13 +9,15 @@ const data = {
9
9
views : 254 ,
10
10
user_id : 123 ,
11
11
published : true ,
12
+ published_at : '2021-01-01T00:00:00.000Z' ,
12
13
} ,
13
14
{
14
15
id : 2 ,
15
16
title : 'Sic Dolor amet' ,
16
17
views : 65 ,
17
18
user_id : 456 ,
18
19
published : true ,
20
+ published_at : '2021-01-01T00:00:00.000Z' ,
19
21
} ,
20
22
] ,
21
23
users : [
@@ -39,6 +41,8 @@ const PostType = new GraphQLObjectType({
39
41
title: { type: GraphQLString },
40
42
views: { type: GraphQLInt },
41
43
user_id: { type: GraphQLID },
44
+ published: { type: GraphQLBoolean },
45
+ published_at: { type: GraphQLScalarType },
42
46
},
43
47
});
44
48
const UsersType = new GraphQLObjectType({
@@ -66,6 +70,8 @@ test('creates one filter field per entity field', () => {
66
70
expect ( PostFilterFields . title . type . toString ( ) ) . toEqual ( 'String' ) ;
67
71
expect ( PostFilterFields . views . type . toString ( ) ) . toEqual ( 'Int' ) ;
68
72
expect ( PostFilterFields . user_id . type . toString ( ) ) . toEqual ( 'ID' ) ;
73
+ expect ( PostFilterFields . published . type . toString ( ) ) . toEqual ( 'Boolean' ) ;
74
+ expect ( PostFilterFields . published_at . type . toString ( ) ) . toEqual ( 'Date' ) ;
69
75
const CommentFilterFields = filterTypes . User . getFields ( ) ;
70
76
expect ( CommentFilterFields . id . type . toString ( ) ) . toEqual ( 'ID' ) ;
71
77
expect ( CommentFilterFields . name . type . toString ( ) ) . toEqual ( 'String' ) ;
@@ -88,6 +94,15 @@ test('creates 4 fields for number field for range filters', () => {
88
94
expect ( PostFilterFields . views_gte . type . toString ( ) ) . toEqual ( 'Int' ) ;
89
95
} ) ;
90
96
97
+ test ( 'creates 4 fields for dates fields' , ( ) => {
98
+ const filterTypes = getFilterTypesFromData ( data ) ;
99
+ const PostFilterFields = filterTypes . Post . getFields ( ) ;
100
+ expect ( PostFilterFields . published_at_lt . type . toString ( ) ) . toEqual ( 'Date' ) ;
101
+ expect ( PostFilterFields . published_at_lte . type . toString ( ) ) . toEqual ( 'Date' ) ;
102
+ expect ( PostFilterFields . published_at_gt . type . toString ( ) ) . toEqual ( 'Date' ) ;
103
+ expect ( PostFilterFields . published_at_gte . type . toString ( ) ) . toEqual ( 'Date' ) ;
104
+ } ) ;
105
+
91
106
test ( 'does not create comparison fields for fields that do not support it' , ( ) => {
92
107
const filterTypes = getFilterTypesFromData ( data ) ;
93
108
const PostFilterFields = filterTypes . Post . getFields ( ) ;
0 commit comments