Skip to content

Commit 9445f89

Browse files
authored
fix: switch off lower(COLUMN_NAME) decoration on String equality check (#186)
* fix: switch off lower(COLUMN_NAME) decoration on String equality check * fix: add unit tests with EQ case matching
1 parent f2d4756 commit 9445f89

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/JpaPredicateBuilder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,12 @@ protected Predicate addOrNull(Path<?> root, Predicate p) {
105105
* @return
106106
*/
107107
protected Predicate getStringPredicate(Path<String> root, PredicateFilter filter) {
108-
Expression<String> fieldValue;
109-
110108
// list or arrays only for in and not in, between and not between
111109
Predicate arrayValuePredicate = mayBeArrayValuePredicate(root, filter);
112110

113111
if(arrayValuePredicate == null) {
114112
String compareValue = filter.getValue().toString();
113+
Expression<String> fieldValue = root;
115114

116115
if (filter.getCriterias().contains(PredicateFilter.Criteria.IN)) {
117116
CriteriaBuilder.In<Object> in = cb.in(root);
@@ -120,15 +119,7 @@ protected Predicate getStringPredicate(Path<String> root, PredicateFilter filter
120119
if (filter.getCriterias().contains(PredicateFilter.Criteria.NIN)) {
121120
return cb.not(root.in(compareValue));
122121
}
123-
124-
if (filter.getCriterias().contains(PredicateFilter.Criteria.CASE)) {
125-
fieldValue = root;
126-
}
127-
else {
128-
fieldValue = cb.lower(root);
129-
compareValue = compareValue.toLowerCase();
130-
}
131-
122+
132123
if (filter.getCriterias().contains(PredicateFilter.Criteria.EQ)) {
133124
return cb.equal(fieldValue, compareValue);
134125
}

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/GraphQLExecutorTests.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@
2727

2828
import javax.persistence.EntityManager;
2929

30-
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
31-
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder;
32-
import graphql.ErrorType;
33-
import graphql.ExecutionResult;
34-
import graphql.GraphQLError;
35-
import graphql.validation.ValidationError;
36-
import graphql.validation.ValidationErrorType;
3730
import org.junit.Test;
3831
import org.junit.runner.RunWith;
3932
import org.springframework.beans.factory.annotation.Autowired;
@@ -52,6 +45,7 @@
5245
import graphql.ExecutionResult;
5346
import graphql.GraphQLError;
5447
import graphql.validation.ValidationError;
48+
import graphql.validation.ValidationErrorType;
5549

5650

5751
@RunWith(SpringRunner.class)
@@ -1448,5 +1442,35 @@ public void queryForTransientMethodAnnotatedWithGraphQLIgnoreShouldFail() {
14481442
.extracting("validationErrorType", "queryPath")
14491443
.containsOnly(tuple(ValidationErrorType.FieldUndefined, list("Books", "select", "authorName")));
14501444
}
1445+
1446+
@Test
1447+
public void queryWithEQNotMatchingCase() {
1448+
//given:
1449+
String query = "query { Books ( where: { title: {EQ: \"War And Peace\"}}) { select { id title} } }";
1450+
1451+
String expected = "{Books={select=[]}}";
1452+
1453+
//when:
1454+
Object result = executor.execute(query).getData();
1455+
1456+
//then:
1457+
assertThat(result.toString()).isEqualTo(expected);
1458+
}
1459+
1460+
@Test
1461+
public void queryWithEQMatchingCase() {
1462+
//given:
1463+
String query = "query { Books ( where: { title: {EQ: \"War and Peace\"}}) { select { id title} } }";
1464+
1465+
String expected = "{Books={select=[" +
1466+
"{id=2, title=War and Peace}" +
1467+
"]}}";
1468+
1469+
//when:
1470+
Object result = executor.execute(query).getData();
1471+
1472+
//then:
1473+
assertThat(result.toString()).isEqualTo(expected);
1474+
}
14511475

14521476
}

0 commit comments

Comments
 (0)