Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,14 @@ private TypedQuery<Long> getCountQuery(DataFetchingEnvironment environment, Fiel
CriteriaQuery<Long> query = cb.createQuery(Long.class);
Root<?> root = query.from(entityType);

DataFetchingEnvironment queryEnvironment = DataFetchingEnvironmentBuilder.newDataFetchingEnvironment(environment)
.root(query)
.build();

query.select(cb.count(root));

List<Predicate> predicates = field.getArguments().stream()
.map(it -> getPredicate(cb, root, null, environment, it))
.map(it -> getPredicate(cb, root, null, queryEnvironment, it))
.filter(it -> it != null)
.collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public void queryForAuthorsWithWhereEXISTSBooksLIKETitle() {
" title: {LIKE: \"War\"}" +
" }" +
" }" +
" }) {" +
" }) {" +
" select {" +
" id" +
" name" +
Expand Down Expand Up @@ -835,8 +835,82 @@ public void queryForAuthorsWithWhereBooksNOTEXISTSAuthorLIKENameLeo() {

// then
assertThat(result.toString()).isEqualTo(expected);
}

}

@Test
public void queryTotalForAuthorsWithWhereEXISTSBooksLIKETitleEmpty() {
//given
String query = "query { "
+ "Authors(where: {" +
" EXISTS: {" +
" books: {" +
" author: {name: {LIKE: \"Anton\"}}" +
" title: {LIKE: \"War\"}" +
" }" +
" }" +
" }) {" +
" total" +
" pages" +
" select {" +
" id" +
" name" +
" books {" +
" id" +
" title" +
" }" +
" }" +
" }"+
"}";

String expected = "{Authors={total=0, pages=0, select=[]}}";

//when
Object result = executor.execute(query).getData();

// then
assertThat(result.toString()).isEqualTo(expected);
}

@Test
public void queryTotalForAuthorsWithWhereBooksNOTEXISTSAuthorLIKENameLeo() {
//given
String query = "query { "
+ " Authors(where: {" +
" books: {" +
" NOT_EXISTS: {" +
" author: {" +
" name: {LIKE: \"Leo\"}" +
" }" +
" }" +
" }" +
" }) {" +
" total" +
" pages" +
" select {" +
" id" +
" name" +
" books {" +
" id" +
" title" +
" }" +
" }" +
" }"+
"}";

String expected = "{Authors={total=3, pages=1, select=["
+ "{id=4, name=Anton Chekhov, books=["
+ "{id=5, title=The Cherry Orchard}, "
+ "{id=6, title=The Seagull}, "
+ "{id=7, title=Three Sisters}]}"
+ "]}}";

//when
Object result = executor.execute(query).getData();

// then
assertThat(result.toString()).isEqualTo(expected);
}

@Test
public void queryForAuthorssWithWhereBooksGenreEquals() {
//given
Expand Down