@@ -471,18 +471,8 @@ private GraphQLFieldDefinition getObjectField(Attribute attribute) {
471
471
Stream <Attribute > attributes = findBasicAttributes (foreignType .getAttributes ());
472
472
473
473
// TODO fix page count query
474
- // TODO fix argument bindings. Only static parameter bindings are supported due to GraphQL limitation
475
474
arguments .add (getWhereArgument (foreignType ));
476
475
477
- // Disabled Simple attribute filtering
478
- // attributes.forEach(it -> {
479
- // arguments.add(GraphQLArgument.newArgument()
480
- // .name(it.getName())
481
- // .type((GraphQLInputType) getAttributeType(it))
482
- // .build()
483
- // );
484
- // });
485
-
486
476
} // Get Sub-Objects fields queries via DataFetcher
487
477
else if (attribute instanceof PluralAttribute
488
478
&& (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY
@@ -513,22 +503,24 @@ private Stream<Attribute<?,?>> findBasicAttributes(Collection<Attribute<?,?>> at
513
503
514
504
@ SuppressWarnings ( "rawtypes" )
515
505
private GraphQLType getAttributeType (Attribute <?,?> attribute ) {
516
- if (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .BASIC ) {
517
- if (attribute .getJavaType ().isEnum ()) {
518
- return getTypeFromJavaType (attribute .getJavaType ());
519
- } else {
520
- return JavaScalars .of (attribute .getJavaType ());
521
- }
522
-
523
- } else if (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_MANY ) {
506
+
507
+ if (isBasic (attribute )) {
508
+ return getGraphQLTypeFromJavaType (attribute .getJavaType ());
509
+ }
510
+ else if (isToMany (attribute )) {
524
511
EntityType foreignType = (EntityType ) ((PluralAttribute ) attribute ).getElementType ();
525
512
return new GraphQLList (new GraphQLTypeReference (foreignType .getName ()));
526
- } else if (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_ONE || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_ONE ) {
513
+ }
514
+ else if (isToOne (attribute )) {
527
515
EntityType foreignType = (EntityType ) ((SingularAttribute ) attribute ).getType ();
528
516
return new GraphQLTypeReference (foreignType .getName ());
529
- } else if (attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ELEMENT_COLLECTION ) {
517
+ }
518
+ else if (isElementCollection (attribute )) {
530
519
Type foreignType = ((PluralAttribute ) attribute ).getElementType ();
531
- return new GraphQLList (getTypeFromJavaType (foreignType .getJavaType ()));
520
+
521
+ if (foreignType .getPersistenceType () == Type .PersistenceType .BASIC ) {
522
+ return new GraphQLList (getGraphQLTypeFromJavaType (foreignType .getJavaType ()));
523
+ }
532
524
}
533
525
534
526
final String declaringType = attribute .getDeclaringType ().getJavaType ().getName (); // fully qualified name of the entity class
@@ -538,7 +530,26 @@ private GraphQLType getAttributeType(Attribute<?,?> attribute) {
538
530
"Attribute could not be mapped to GraphQL: field '" + declaringMember + "' of entity class '" + declaringType +"'" );
539
531
}
540
532
541
- private boolean isValidInput (Attribute <?,?> attribute ) {
533
+ protected final boolean isBasic (Attribute <?,?> attribute ) {
534
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .BASIC ;
535
+ }
536
+
537
+ protected final boolean isElementCollection (Attribute <?,?> attribute ) {
538
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ELEMENT_COLLECTION ;
539
+ }
540
+
541
+ protected final boolean isToMany (Attribute <?,?> attribute ) {
542
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_MANY
543
+ || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_MANY ;
544
+ }
545
+
546
+ protected final boolean isToOne (Attribute <?,?> attribute ) {
547
+ return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .MANY_TO_ONE
548
+ || attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ONE_TO_ONE ;
549
+ }
550
+
551
+
552
+ protected final boolean isValidInput (Attribute <?,?> attribute ) {
542
553
return attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .BASIC ||
543
554
attribute .getPersistentAttributeType () == Attribute .PersistentAttributeType .ELEMENT_COLLECTION ;
544
555
}
@@ -586,7 +597,7 @@ private boolean isNotIgnored(AnnotatedElement annotatedElement) {
586
597
}
587
598
588
599
@ SuppressWarnings ( "unchecked" )
589
- private GraphQLType getTypeFromJavaType (Class <?> clazz ) {
600
+ private GraphQLType getGraphQLTypeFromJavaType (Class <?> clazz ) {
590
601
if (clazz .isEnum ()) {
591
602
592
603
if (classCache .containsKey (clazz ))
@@ -597,15 +608,15 @@ private GraphQLType getTypeFromJavaType(Class<?> clazz) {
597
608
for (Enum <?> enumValue : ((Class <Enum <?>>)clazz ).getEnumConstants ())
598
609
enumBuilder .value (enumValue .name (), ordinal ++);
599
610
600
- GraphQLType answer = enumBuilder .build ();
601
- setNoOpCoercing (answer );
611
+ GraphQLType enumType = enumBuilder .build ();
612
+ setNoOpCoercing (enumType );
602
613
603
- classCache .putIfAbsent (clazz , answer );
614
+ classCache .putIfAbsent (clazz , enumType );
604
615
605
- return answer ;
616
+ return enumType ;
606
617
}
607
618
608
- return null ;
619
+ return JavaScalars . of ( clazz ) ;
609
620
}
610
621
611
622
protected GraphQLInputType getFieldsEnumType (EntityType <?> entityType ) {
0 commit comments