26
26
import static graphql .introspection .Introspection .SchemaMetaFieldDef ;
27
27
import static graphql .introspection .Introspection .TypeMetaFieldDef ;
28
28
import static graphql .introspection .Introspection .TypeNameMetaFieldDef ;
29
+ import static java .lang .Integer .min ;
29
30
import static java .util .stream .Collectors .groupingBy ;
30
31
31
32
import com .introproventures .graphql .jpa .query .annotation .GraphQLDefaultOrderBy ;
@@ -248,16 +249,17 @@ public List<Object> queryKeys(
248
249
public List <Object > queryResultList (DataFetchingEnvironment environment , int maxResults , List <Object > keys ) {
249
250
// Let's execute query and get result as stream
250
251
Stream <Object > resultStream = queryResultStream (environment , maxResults , keys );
252
+ var size = keys .isEmpty () ? maxResults : min (keys .size (), maxResults );
251
253
// Let's wrap stream into lazy list to pass it downstream
252
- return ResultStreamWrapper .wrap (resultStream , maxResults );
254
+ return ResultStreamWrapper .wrap (resultStream , size );
253
255
}
254
256
255
257
protected Stream <Object > queryResultStream (DataFetchingEnvironment environment , int maxResults , List <Object > keys ) {
256
258
MergedField queryField = resolveQueryField (environment .getField ());
257
259
258
260
// Override query environment with associated entity object type and
259
261
final DataFetchingEnvironment queryEnvironment = getQueryEnvironment (environment , queryField );
260
- final int fetchSize = Integer . min (maxResults , defaultFetchSize );
262
+ final int fetchSize = min (maxResults , defaultFetchSize );
261
263
final boolean isDistinct = resolveDistinctArgument (queryEnvironment .getField ());
262
264
263
265
final TypedQuery <Object > query = getQuery (
@@ -280,7 +282,7 @@ protected <T> Stream<T> getResultStream(
280
282
boolean isDistinct ,
281
283
EntityGraph <?> entityGraph
282
284
) {
283
- // Let' try reduce overhead and disable all caching
285
+ // Let's try to reduce overhead and disable all caching
284
286
query .setHint (ORG_HIBERNATE_READ_ONLY , true );
285
287
query .setHint (ORG_HIBERNATE_FETCH_SIZE , fetchSize );
286
288
query .setHint (ORG_HIBERNATE_CACHEABLE , false );
0 commit comments