@@ -9,13 +9,15 @@ const data = {
99 views : 254 ,
1010 user_id : 123 ,
1111 published : true ,
12+ published_at : '2021-01-01T00:00:00.000Z' ,
1213 } ,
1314 {
1415 id : 2 ,
1516 title : 'Sic Dolor amet' ,
1617 views : 65 ,
1718 user_id : 456 ,
1819 published : true ,
20+ published_at : '2021-01-01T00:00:00.000Z' ,
1921 } ,
2022 ] ,
2123 users : [
@@ -39,6 +41,8 @@ const PostType = new GraphQLObjectType({
3941 title: { type: GraphQLString },
4042 views: { type: GraphQLInt },
4143 user_id: { type: GraphQLID },
44+ published: { type: GraphQLBoolean },
45+ published_at: { type: GraphQLScalarType },
4246 },
4347});
4448const UsersType = new GraphQLObjectType({
@@ -66,6 +70,8 @@ test('creates one filter field per entity field', () => {
6670 expect ( PostFilterFields . title . type . toString ( ) ) . toEqual ( 'String' ) ;
6771 expect ( PostFilterFields . views . type . toString ( ) ) . toEqual ( 'Int' ) ;
6872 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' ) ;
6975 const CommentFilterFields = filterTypes . User . getFields ( ) ;
7076 expect ( CommentFilterFields . id . type . toString ( ) ) . toEqual ( 'ID' ) ;
7177 expect ( CommentFilterFields . name . type . toString ( ) ) . toEqual ( 'String' ) ;
@@ -88,6 +94,15 @@ test('creates 4 fields for number field for range filters', () => {
8894 expect ( PostFilterFields . views_gte . type . toString ( ) ) . toEqual ( 'Int' ) ;
8995} ) ;
9096
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+
91106test ( 'does not create comparison fields for fields that do not support it' , ( ) => {
92107 const filterTypes = getFilterTypesFromData ( data ) ;
93108 const PostFilterFields = filterTypes . Post . getFields ( ) ;
0 commit comments