Skip to content

Commit 4862ad0

Browse files
authored
feat: add NE predicate for custom attributes criteria expressions (#140)
1 parent e2ddd4d commit 4862ad0

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,16 @@ else if (Object.class.isAssignableFrom(type)) {
452452
object = getValue(object, type);
453453
}
454454

455-
if (filter.getCriterias().contains(PredicateFilter.Criteria.EQ)) {
456-
return cb.equal(from.get(filter.getField()), object);
455+
if (filter.getCriterias().contains(PredicateFilter.Criteria.EQ)
456+
|| filter.getCriterias().contains(PredicateFilter.Criteria.NE)) {
457+
458+
Predicate equal = cb.equal(from.get(filter.getField()), object);
459+
460+
if (filter.getCriterias().contains(PredicateFilter.Criteria.NE)) {
461+
return cb.not(equal);
462+
}
463+
464+
return equal;
457465
}
458466
else if (filter.getCriterias().contains(PredicateFilter.Criteria.IN)
459467
|| filter.getCriterias().contains(PredicateFilter.Criteria.NIN)

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,36 @@ public void queryProcessVariablesWhereWithNINSingleValueSearchCriteria() {
551551

552552
// then
553553
assertThat(result.toString()).isEqualTo(expected);
554-
}
554+
}
555+
556+
@Test
557+
public void queryProcessVariablesWhereWithNEValueSearchCriteria() {
558+
//given
559+
String query = "query {" +
560+
" TaskVariables(where: {"
561+
+ "value: {NE: null}"
562+
+ "}) {" +
563+
" select {" +
564+
" name" +
565+
" value" +
566+
" }" +
567+
" }" +
568+
"}";
569+
570+
String expected = "{TaskVariables={select=["
571+
+ "{name=variable1, value=data}, "
572+
+ "{name=variable2, value=true}, "
573+
+ "{name=variable4, value={key=data}}, "
574+
+ "{name=variable5, value=1.2345}, "
575+
+ "{name=variable6, value=12345}, "
576+
+ "{name=variable7, value=[1, 2, 3, 4, 5]}]}}";
577+
578+
//when
579+
Object result = executor.execute(query).getData();
580+
581+
// then
582+
assertThat(result.toString()).isEqualTo(expected);
583+
}
555584

556585
@Test
557586
public void queryProcessVariablesWhereWithINListTypedValueSearchCriteria() {

0 commit comments

Comments
 (0)