Skip to content

Commit ad5fe3e

Browse files
authored
Merge pull request #166 from marmelab/string-comparisons
Allow to use `_gt` and `_lt` filters with strings
2 parents 36883c9 + d9e6eb6 commit ad5fe3e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/introspection/getFilterTypesFromData.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const getRangeFiltersFromEntities = (entities) => {
2323
if (
2424
fieldType == GraphQLInt ||
2525
fieldType == GraphQLFloat ||
26+
fieldType.name == GraphQLString ||
2627
fieldType.name == 'Date'
2728
) {
2829
fields[`${fieldName}_lt`] = { type: fieldType };

src/introspection/getFilterTypesFromData.spec.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ const data = {
77
title: 'Lorem Ipsum',
88
views: 254,
99
user_id: 123,
10+
published: true,
1011
},
1112
{
1213
id: 2,
1314
title: 'Sic Dolor amet',
1415
views: 65,
1516
user_id: 456,
17+
published: true,
1618
},
1719
],
1820
users: [
@@ -85,8 +87,8 @@ test('creates 4 fields for number field for range filters', () => {
8587
expect(PostFilterFields.views_gte.type.toString()).toEqual('Int');
8688
});
8789

88-
test('does not create vomparison fiels for non-number fields', () => {
90+
test('does not create comparison fields for fields that do not support it', () => {
8991
const filterTypes = getFilterTypesFromData(data);
9092
const PostFilterFields = filterTypes.Post.getFields();
91-
expect(PostFilterFields.title_lte).toBeUndefined();
93+
expect(PostFilterFields.published_lte).toBeUndefined();
9294
});

0 commit comments

Comments
 (0)