diff --git a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaQueryDataFetcher.java b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaQueryDataFetcher.java index f305cb7f..af06479f 100644 --- a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaQueryDataFetcher.java +++ b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaQueryDataFetcher.java @@ -34,7 +34,6 @@ import graphql.schema.DataFetcher; import graphql.schema.DataFetchingEnvironment; import graphql.schema.GraphQLScalarType; -import java.util.Collection; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -118,12 +117,7 @@ public PagedResult get(DataFetchingEnvironment environment) { } if (totalSelection.isPresent() || pagesSelection.isPresent()) { - final var selectResult = pagedResult.getSelect(); - - final long total = recordsSelection.isEmpty() || - selectResult.filter(Predicate.not(Collection::isEmpty)).isPresent() - ? queryFactory.queryTotalCount(environment, restrictedKeys) - : 0L; + final Long total = queryFactory.queryTotalCount(environment, restrictedKeys); pagedResult.withTotal(total); } diff --git a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/PagedResult.java b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/PagedResult.java index abba0b1c..e41c9202 100644 --- a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/PagedResult.java +++ b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/PagedResult.java @@ -20,7 +20,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; public class PagedResult { @@ -136,10 +135,6 @@ public Builder withSelect(List select) { return this; } - public Optional> getSelect() { - return Optional.ofNullable(select); - } - /** * Builder method for select parameter. * @param select field to set diff --git a/schema/src/test/java/com/introproventures/graphql/jpa/query/support/StarwarsQueryExecutorTestsSupport.java b/schema/src/test/java/com/introproventures/graphql/jpa/query/support/StarwarsQueryExecutorTestsSupport.java index 9a1a6f1f..5620f513 100644 --- a/schema/src/test/java/com/introproventures/graphql/jpa/query/support/StarwarsQueryExecutorTestsSupport.java +++ b/schema/src/test/java/com/introproventures/graphql/jpa/query/support/StarwarsQueryExecutorTestsSupport.java @@ -392,6 +392,20 @@ public void queryWhereRoot() { assertThat(result.toString()).isEqualTo(expected); } + @Test + public void queryWhereRoot2() { + //given: + String query = "query { Humans( page: { start: 4, limit: 2 }) { pages, total, select { name } } }"; + + String expected = "{Humans={pages=3, total=5, select=[]}}"; + + //when: + Object result = executor.execute(query).getData(); + + //then: + assertThat(result.toString()).isEqualTo(expected); + } + @Test public void queryWhereRootPagedWithVariables() { //given: @@ -427,6 +441,20 @@ public void queryPaginationWithoutRecords() { assertThat(result.toString()).isEqualTo(expected); } + @Test + public void queryPaginationWithoutRecords2() { + //given: + String query = "query { Humans ( page: { start: 4, limit: 2 }) { pages, total } }"; + + String expected = "{Humans={pages=3, total=5}}"; + + //when: + Object result = executor.execute(query).getData(); + + //then: + assertThat(result.toString()).isEqualTo(expected); + } + @Test public void queryOrderByFields() { //given: