1515 */
1616package com .introproventures .graphql .jpa .query .schema .impl ;
1717
18- import static com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaSchemaBuilder .SELECT_DISTINCT_PARAM_NAME ;
19- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .getObjectField ;
20- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isAfterArgument ;
21- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isDistinctArgument ;
22- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isFirstArgument ;
23- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isLogicalArgument ;
24- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isPageArgument ;
25- import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isWhereArgument ;
26- import static graphql .introspection .Introspection .SchemaMetaFieldDef ;
27- import static graphql .introspection .Introspection .TypeMetaFieldDef ;
28- import static graphql .introspection .Introspection .TypeNameMetaFieldDef ;
29- import static java .util .stream .Collectors .groupingBy ;
30-
3118import java .beans .BeanInfo ;
3219import java .beans .Introspector ;
3320import java .beans .PropertyDescriptor ;
5239import java .util .stream .Collectors ;
5340import java .util .stream .IntStream ;
5441import java .util .stream .Stream ;
55-
5642import javax .persistence .EntityManager ;
5743import javax .persistence .TypedQuery ;
5844import javax .persistence .criteria .AbstractQuery ;
7460import javax .persistence .metamodel .PluralAttribute ;
7561import javax .persistence .metamodel .SingularAttribute ;
7662import javax .persistence .metamodel .Type ;
77-
78- import graphql .execution .CoercedVariables ;
79- import org .slf4j .Logger ;
80- import org .slf4j .LoggerFactory ;
81-
8263import com .introproventures .graphql .jpa .query .annotation .GraphQLDefaultOrderBy ;
8364import com .introproventures .graphql .jpa .query .introspection .ReflectionUtil ;
8465import com .introproventures .graphql .jpa .query .schema .JavaScalars ;
8768import com .introproventures .graphql .jpa .query .schema .impl .EntityIntrospector .EntityIntrospectionResult .AttributePropertyDescriptor ;
8869import com .introproventures .graphql .jpa .query .schema .impl .PredicateFilter .Criteria ;
8970import com .introproventures .graphql .jpa .query .support .GraphQLSupport ;
90-
9171import graphql .GraphQLException ;
72+ import graphql .execution .CoercedVariables ;
9273import graphql .execution .MergedField ;
9374import graphql .execution .ValuesResolver ;
9475import graphql .language .Argument ;
11394import graphql .schema .GraphQLScalarType ;
11495import graphql .schema .GraphQLSchema ;
11596import graphql .schema .GraphQLType ;
97+ import org .slf4j .Logger ;
98+ import org .slf4j .LoggerFactory ;
99+
100+ import static com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaSchemaBuilder .SELECT_DISTINCT_PARAM_NAME ;
101+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .getObjectField ;
102+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isAfterArgument ;
103+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isDistinctArgument ;
104+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isFirstArgument ;
105+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isLogicalArgument ;
106+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isPageArgument ;
107+ import static com .introproventures .graphql .jpa .query .support .GraphQLSupport .isWhereArgument ;
108+ import static graphql .introspection .Introspection .SchemaMetaFieldDef ;
109+ import static graphql .introspection .Introspection .TypeMetaFieldDef ;
110+ import static graphql .introspection .Introspection .TypeNameMetaFieldDef ;
111+ import static java .util .stream .Collectors .groupingBy ;
116112
117113/**
118114 * Provides implemetation for GraphQL JPA Query Factory
@@ -143,6 +139,7 @@ public final class GraphQLJpaQueryFactory {
143139 private final GraphQLObjectType entityObjectType ;
144140 private final int defaultFetchSize ;
145141 private final RestrictedKeysProvider restrictedKeysProvider ;
142+ private final boolean resultStream ;
146143
147144 private GraphQLJpaQueryFactory (Builder builder ) {
148145 this .entityManager = builder .entityManager ;
@@ -153,6 +150,7 @@ private GraphQLJpaQueryFactory(Builder builder) {
153150 this .defaultDistinct = builder .defaultDistinct ;
154151 this .defaultFetchSize = builder .defaultFetchSize ;
155152 this .restrictedKeysProvider = builder .restrictedKeysProvider ;
153+ this .resultStream = builder .resultStream ;
156154 }
157155
158156 public DataFetchingEnvironment getQueryEnvironment (DataFetchingEnvironment environment ,
@@ -260,7 +258,12 @@ protected <T> Stream<T> getResultStream(TypedQuery<T> query,
260258 logger .info ("\n GraphQL JPQL Fetch Query String:\n {}" , getJPQLQueryString (query ));
261259 }
262260
263- // Let's execute query and get wrap result into stream
261+ if (resultStream ) {
262+ return query .getResultStream ()
263+ .peek (entityManager ::detach );
264+ }
265+
266+ // Let's execute query and wrap result into stream
264267 return query .getResultList ()
265268 .stream ()
266269 .peek (entityManager ::detach );
@@ -1952,6 +1955,13 @@ public interface IBuildStage {
19521955 */
19531956 public IBuildStage withDefaultDistinct (boolean defaultDistinct );
19541957
1958+ /**
1959+ * Builder method for resultStream parameter.
1960+ * @param resultStream field to set
1961+ * @return builder
1962+ */
1963+ public IBuildStage withResultStream (boolean resultStream );
1964+
19551965 /**
19561966 * Builder method for defaultFetchSize parameter.
19571967 * @param defaultFetchSize field to set
@@ -1987,6 +1997,7 @@ public static final class Builder implements IEntityManagerStage, IEntityTypeSta
19871997 private boolean toManyDefaultOptional = true ;
19881998 private boolean defaultDistinct = true ;
19891999 private int defaultFetchSize = 100 ;
2000+ private boolean resultStream = false ;
19902001
19912002 private Builder () {
19922003 }
@@ -2027,6 +2038,12 @@ public IBuildStage withDefaultDistinct(boolean defaultDistinct) {
20272038 return this ;
20282039 }
20292040
2041+ @ Override
2042+ public IBuildStage withResultStream (boolean resultStream ) {
2043+ this .resultStream = resultStream ;
2044+ return this ;
2045+ }
2046+
20302047 @ Override
20312048 public IBuildStage withDefaultFetchSize (int defaultFetchSize ) {
20322049 this .defaultFetchSize = defaultFetchSize ;
@@ -2038,7 +2055,7 @@ public IBuildStage withRestrictedKeysProvider(RestrictedKeysProvider restrictedK
20382055 this .restrictedKeysProvider = restrictedKeysProvider ;
20392056 return this ;
20402057 }
2041-
2058+
20422059 @ Override
20432060 public GraphQLJpaQueryFactory build () {
20442061 Objects .requireNonNull (restrictedKeysProvider , "restrictedKeysProvider must not be null" );
0 commit comments