32
32
import javax .persistence .metamodel .Attribute ;
33
33
import javax .persistence .metamodel .EmbeddableType ;
34
34
import javax .persistence .metamodel .EntityType ;
35
+ import javax .persistence .metamodel .ManagedType ;
35
36
import javax .persistence .metamodel .PluralAttribute ;
36
37
import javax .persistence .metamodel .SingularAttribute ;
37
38
import javax .persistence .metamodel .Type ;
@@ -194,12 +195,19 @@ private GraphQLFieldDefinition getQueryFieldSelectDefinition(EntityType<?> entit
194
195
.build ();
195
196
}
196
197
197
- private Map <EntityType <?>, GraphQLArgument > whereArgumentsMap = new HashMap <>();
198
-
199
- private GraphQLArgument getWhereArgument (EntityType <?> entityType ) {
200
- String type = namingStrategy .pluralize (entityType .getName ())+"CriteriaExpression" ;
198
+ private Map <ManagedType <?>, GraphQLArgument > whereArgumentsMap = new HashMap <>();
199
+
200
+ private GraphQLArgument getWhereArgument (ManagedType <?> managedType ) {
201
+ String typeName ="" ;
202
+ if (managedType instanceof EmbeddableType ){
203
+ typeName = managedType .getJavaType ().getSimpleName ()+"EmbeddableType" ;
204
+ } else if (managedType instanceof EntityType ) {
205
+ typeName = ((EntityType )managedType ).getName ();
206
+ }
207
+
208
+ String type = namingStrategy .pluralize (typeName )+"CriteriaExpression" ;
201
209
202
- GraphQLArgument whereArgument = whereArgumentsMap .get (entityType );
210
+ GraphQLArgument whereArgument = whereArgumentsMap .get (managedType );
203
211
204
212
if (whereArgument != null )
205
213
return whereArgument ;
@@ -219,7 +227,7 @@ private GraphQLArgument getWhereArgument(EntityType<?> entityType) {
219
227
.type (new GraphQLTypeReference (type ))
220
228
.build ()
221
229
)
222
- .fields (entityType .getAttributes ().stream ()
230
+ .fields (managedType .getAttributes ().stream ()
223
231
.filter (this ::isValidInput )
224
232
.filter (this ::isNotIgnored )
225
233
.map (this ::getWhereInputField )
@@ -233,7 +241,7 @@ private GraphQLArgument getWhereArgument(EntityType<?> entityType) {
233
241
.type (whereInputObject )
234
242
.build ();
235
243
236
- whereArgumentsMap .put (entityType , whereArgument );
244
+ whereArgumentsMap .put (managedType , whereArgument );
237
245
238
246
return whereArgument ;
239
247
@@ -457,22 +465,17 @@ private GraphQLFieldDefinition getObjectField(Attribute attribute) {
457
465
}
458
466
459
467
// Get the fields that can be queried on (i.e. Simple Types, no Sub-Objects)
460
- if (attribute instanceof SingularAttribute
461
- && attribute .getPersistentAttributeType () != Attribute .PersistentAttributeType .BASIC
462
- && attribute .getPersistentAttributeType () != Attribute .PersistentAttributeType .EMBEDDED
463
- ) {
464
-
465
- EntityType foreignType = (EntityType ) ((SingularAttribute ) attribute ).getType ();
466
- Stream <Attribute > attributes = findBasicAttributes (foreignType .getAttributes ());
468
+ if (attribute instanceof SingularAttribute
469
+ && attribute .getPersistentAttributeType () != Attribute .PersistentAttributeType .BASIC ) {
470
+ ManagedType foreignType = (ManagedType ) ((SingularAttribute ) attribute ).getType ();
467
471
468
472
// TODO fix page count query
469
473
arguments .add (getWhereArgument (foreignType ));
470
474
471
- } // Get Sub-Objects fields queries via DataFetcher
475
+ } // Get Sub-Objects fields queries via DataFetcher
472
476
else if (attribute instanceof PluralAttribute
473
477
&& (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY
474
- || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_MANY )
475
- ) {
478
+ || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_MANY )) {
476
479
EntityType declaringType = (EntityType ) ((PluralAttribute ) attribute ).getDeclaringType ();
477
480
EntityType elementType = (EntityType ) ((PluralAttribute ) attribute ).getElementType ();
478
481
@@ -498,9 +501,9 @@ private Stream<Attribute<?,?>> findBasicAttributes(Collection<Attribute<?,?>> at
498
501
499
502
@ SuppressWarnings ( "rawtypes" )
500
503
private GraphQLType getAttributeType (Attribute <?,?> attribute ) {
501
-
504
+
502
505
if (isBasic (attribute )) {
503
- return getGraphQLTypeFromJavaType (attribute .getJavaType ());
506
+ return getGraphQLTypeFromJavaType (attribute .getJavaType ());
504
507
}
505
508
else if (isEmbeddable (attribute )) {
506
509
EmbeddableType embeddableType = (EmbeddableType ) ((SingularAttribute ) attribute ).getType ();
@@ -518,7 +521,7 @@ else if (isElementCollection(attribute)) {
518
521
Type foreignType = ((PluralAttribute ) attribute ).getElementType ();
519
522
520
523
if (foreignType .getPersistenceType () == Type .PersistenceType .BASIC ) {
521
- return new GraphQLList (getGraphQLTypeFromJavaType (foreignType .getJavaType ()));
524
+ return new GraphQLList (getGraphQLTypeFromJavaType (foreignType .getJavaType ()));
522
525
}
523
526
}
524
527
@@ -542,12 +545,12 @@ protected final boolean isElementCollection(Attribute<?,?> attribute) {
542
545
}
543
546
544
547
protected final boolean isToMany (Attribute <?,?> attribute ) {
545
- return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY
548
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY
546
549
|| attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_MANY ;
547
550
}
548
551
549
552
protected final boolean isToOne (Attribute <?,?> attribute ) {
550
- return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_ONE
553
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_ONE
551
554
|| attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_ONE ;
552
555
}
553
556
0 commit comments