15
15
*/
16
16
package com .introproventures .graphql .jpa .query .schema .impl ;
17
17
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
-
31
18
import java .beans .BeanInfo ;
32
19
import java .beans .Introspector ;
33
20
import java .beans .PropertyDescriptor ;
52
39
import java .util .stream .Collectors ;
53
40
import java .util .stream .IntStream ;
54
41
import java .util .stream .Stream ;
55
-
56
42
import javax .persistence .EntityManager ;
57
43
import javax .persistence .TypedQuery ;
58
44
import javax .persistence .criteria .AbstractQuery ;
74
60
import javax .persistence .metamodel .PluralAttribute ;
75
61
import javax .persistence .metamodel .SingularAttribute ;
76
62
import javax .persistence .metamodel .Type ;
77
-
78
- import graphql .execution .CoercedVariables ;
79
- import org .slf4j .Logger ;
80
- import org .slf4j .LoggerFactory ;
81
-
82
63
import com .introproventures .graphql .jpa .query .annotation .GraphQLDefaultOrderBy ;
83
64
import com .introproventures .graphql .jpa .query .introspection .ReflectionUtil ;
84
65
import com .introproventures .graphql .jpa .query .schema .JavaScalars ;
87
68
import com .introproventures .graphql .jpa .query .schema .impl .EntityIntrospector .EntityIntrospectionResult .AttributePropertyDescriptor ;
88
69
import com .introproventures .graphql .jpa .query .schema .impl .PredicateFilter .Criteria ;
89
70
import com .introproventures .graphql .jpa .query .support .GraphQLSupport ;
90
-
91
71
import graphql .GraphQLException ;
72
+ import graphql .execution .CoercedVariables ;
92
73
import graphql .execution .MergedField ;
93
74
import graphql .execution .ValuesResolver ;
94
75
import graphql .language .Argument ;
113
94
import graphql .schema .GraphQLScalarType ;
114
95
import graphql .schema .GraphQLSchema ;
115
96
import 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 ;
116
112
117
113
/**
118
114
* Provides implemetation for GraphQL JPA Query Factory
@@ -143,6 +139,7 @@ public final class GraphQLJpaQueryFactory {
143
139
private final GraphQLObjectType entityObjectType ;
144
140
private final int defaultFetchSize ;
145
141
private final RestrictedKeysProvider restrictedKeysProvider ;
142
+ private final boolean resultStream ;
146
143
147
144
private GraphQLJpaQueryFactory (Builder builder ) {
148
145
this .entityManager = builder .entityManager ;
@@ -153,6 +150,7 @@ private GraphQLJpaQueryFactory(Builder builder) {
153
150
this .defaultDistinct = builder .defaultDistinct ;
154
151
this .defaultFetchSize = builder .defaultFetchSize ;
155
152
this .restrictedKeysProvider = builder .restrictedKeysProvider ;
153
+ this .resultStream = builder .resultStream ;
156
154
}
157
155
158
156
public DataFetchingEnvironment getQueryEnvironment (DataFetchingEnvironment environment ,
@@ -260,7 +258,12 @@ protected <T> Stream<T> getResultStream(TypedQuery<T> query,
260
258
logger .info ("\n GraphQL JPQL Fetch Query String:\n {}" , getJPQLQueryString (query ));
261
259
}
262
260
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
264
267
return query .getResultList ()
265
268
.stream ()
266
269
.peek (entityManager ::detach );
@@ -1952,6 +1955,13 @@ public interface IBuildStage {
1952
1955
*/
1953
1956
public IBuildStage withDefaultDistinct (boolean defaultDistinct );
1954
1957
1958
+ /**
1959
+ * Builder method for resultStream parameter.
1960
+ * @param resultStream field to set
1961
+ * @return builder
1962
+ */
1963
+ public IBuildStage withResultStream (boolean resultStream );
1964
+
1955
1965
/**
1956
1966
* Builder method for defaultFetchSize parameter.
1957
1967
* @param defaultFetchSize field to set
@@ -1987,6 +1997,7 @@ public static final class Builder implements IEntityManagerStage, IEntityTypeSta
1987
1997
private boolean toManyDefaultOptional = true ;
1988
1998
private boolean defaultDistinct = true ;
1989
1999
private int defaultFetchSize = 100 ;
2000
+ private boolean resultStream = false ;
1990
2001
1991
2002
private Builder () {
1992
2003
}
@@ -2027,6 +2038,12 @@ public IBuildStage withDefaultDistinct(boolean defaultDistinct) {
2027
2038
return this ;
2028
2039
}
2029
2040
2041
+ @ Override
2042
+ public IBuildStage withResultStream (boolean resultStream ) {
2043
+ this .resultStream = resultStream ;
2044
+ return this ;
2045
+ }
2046
+
2030
2047
@ Override
2031
2048
public IBuildStage withDefaultFetchSize (int defaultFetchSize ) {
2032
2049
this .defaultFetchSize = defaultFetchSize ;
@@ -2038,7 +2055,7 @@ public IBuildStage withRestrictedKeysProvider(RestrictedKeysProvider restrictedK
2038
2055
this .restrictedKeysProvider = restrictedKeysProvider ;
2039
2056
return this ;
2040
2057
}
2041
-
2058
+
2042
2059
@ Override
2043
2060
public GraphQLJpaQueryFactory build () {
2044
2061
Objects .requireNonNull (restrictedKeysProvider , "restrictedKeysProvider must not be null" );
0 commit comments