2626import static graphql .introspection .Introspection .SchemaMetaFieldDef ;
2727import static graphql .introspection .Introspection .TypeMetaFieldDef ;
2828import static graphql .introspection .Introspection .TypeNameMetaFieldDef ;
29+ import static java .lang .Integer .min ;
2930import static java .util .stream .Collectors .groupingBy ;
3031
3132import com .introproventures .graphql .jpa .query .annotation .GraphQLDefaultOrderBy ;
@@ -248,16 +249,17 @@ public List<Object> queryKeys(
248249 public List <Object > queryResultList (DataFetchingEnvironment environment , int maxResults , List <Object > keys ) {
249250 // Let's execute query and get result as stream
250251 Stream <Object > resultStream = queryResultStream (environment , maxResults , keys );
252+ var size = keys .isEmpty () ? maxResults : min (keys .size (), maxResults );
251253 // Let's wrap stream into lazy list to pass it downstream
252- return ResultStreamWrapper .wrap (resultStream , maxResults );
254+ return ResultStreamWrapper .wrap (resultStream , size );
253255 }
254256
255257 protected Stream <Object > queryResultStream (DataFetchingEnvironment environment , int maxResults , List <Object > keys ) {
256258 MergedField queryField = resolveQueryField (environment .getField ());
257259
258260 // Override query environment with associated entity object type and
259261 final DataFetchingEnvironment queryEnvironment = getQueryEnvironment (environment , queryField );
260- final int fetchSize = Integer . min (maxResults , defaultFetchSize );
262+ final int fetchSize = min (maxResults , defaultFetchSize );
261263 final boolean isDistinct = resolveDistinctArgument (queryEnvironment .getField ());
262264
263265 final TypedQuery <Object > query = getQuery (
@@ -280,7 +282,7 @@ protected <T> Stream<T> getResultStream(
280282 boolean isDistinct ,
281283 EntityGraph <?> entityGraph
282284 ) {
283- // Let' try reduce overhead and disable all caching
285+ // Let's try to reduce overhead and disable all caching
284286 query .setHint (ORG_HIBERNATE_READ_ONLY , true );
285287 query .setHint (ORG_HIBERNATE_FETCH_SIZE , fetchSize );
286288 query .setHint (ORG_HIBERNATE_CACHEABLE , false );
0 commit comments