diff --git a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java index b058dcee..dc97c673 100644 --- a/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java +++ b/schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/GraphQLJpaSchemaBuilder.java @@ -421,7 +421,9 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT final var selectTypeName = resolveSelectTypeName(entityType); final var aggregateObjectTypeName = selectTypeName.concat("Aggregate"); - var aggregateObjectType = newObject().name(aggregateObjectTypeName); + var aggregateObjectType = newObject() + .name(aggregateObjectTypeName) + .description("%s entity aggregate object type".formatted(selectTypeName)); DataFetcher aggregateDataFetcher = environment -> { Map source = environment.getSource(); @@ -431,6 +433,7 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT var countFieldDefinition = newFieldDefinition() .name("count") + .description("Count the number of records in the database for the %s aggregate".formatted(selectTypeName)) .dataFetcher(aggregateDataFetcher) .type(GraphQLInt); @@ -440,7 +443,12 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT .filter(it -> EntityIntrospector.introspect(entityType).isNotIgnored(it.getName())) .filter(Attribute::isAssociation) .map(Attribute::getName) - .map(name -> newEnumValueDefinition().name(name).build()) + .map(name -> + newEnumValueDefinition() + .name(name) + .description("%s entity associated %s child entity".formatted(selectTypeName, name)) + .build() + ) .toList(); var fieldsEnumValueDefinitions = entityType @@ -449,16 +457,27 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT .filter(it -> EntityIntrospector.introspect(entityType).isNotIgnored(it.getName())) .filter(it -> isBasic(it) || isEmbeddable(it)) .map(Attribute::getName) - .map(name -> newEnumValueDefinition().name(name).build()) + .map(name -> + newEnumValueDefinition() + .name(name) + .description("%s entity %s attribute".formatted(selectTypeName, name)) + .build() + ) .toList(); if (entityType.getAttributes().stream().anyMatch(Attribute::isAssociation)) { countFieldDefinition.argument( newArgument() .name("of") + .description( + "Count the number of associated records in the database for the %s aggregate".formatted( + selectTypeName + ) + ) .type( newEnum() .name(aggregateObjectTypeName.concat("CountOfAssociationsEnum")) + .description("%s entity associated entity name values".formatted(selectTypeName)) .values(associationEnumValueDefinitions) .build() ) @@ -467,21 +486,34 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT var groupFieldDefinition = newFieldDefinition() .name("group") + .description("Group by %s entity query field aggregated by multiple fields".formatted(selectTypeName)) .dataFetcher(aggregateDataFetcher) .type( new GraphQLList( newObject() .name(aggregateObjectTypeName.concat("GroupBy")) + .description("%s entity group by object type".formatted(selectTypeName)) .field( newFieldDefinition() .name("by") + .description( + "Group by %s field container used to query aggregate data by one or more fields".formatted( + selectTypeName + ) + ) .dataFetcher(aggregateDataFetcher) .argument( newArgument() .name("field") + .description( + "Group by field argument used to specify %s entity field name".formatted( + selectTypeName + ) + ) .type( newEnum() .name(aggregateObjectTypeName.concat("GroupByFieldsEnum")) + .description("%s entity field name values".formatted(selectTypeName)) .values(fieldsEnumValueDefinitions) .build() ) @@ -515,6 +547,12 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT aggregateObjectType.field( newFieldDefinition() .name(association.getName()) + .description( + "Aggregate %s query field definition for the associated %s entity".formatted( + selectTypeName, + association.getName() + ) + ) .dataFetcher(aggregateDataFetcher) .type( new GraphQLList( @@ -524,13 +562,29 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT .concat(capitalize(association.getName())) .concat("GroupByNestedAssociation") ) + .description( + "Aggregate %s query object type for the associated %s entity".formatted( + selectTypeName, + association.getName() + ) + ) .field( newFieldDefinition() .name("by") .dataFetcher(aggregateDataFetcher) + .description( + "Group by %s attribute field used to query aggregate data by one or more fields".formatted( + association.getName() + ) + ) .argument( newArgument() .name("field") + .description( + "Group by field argument used to specify associated %s entity field name".formatted( + association.getName() + ) + ) .type( newEnum() .name( @@ -544,7 +598,16 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT ) .type(JavaScalars.GraphQLObjectScalar) ) - .field(newFieldDefinition().name("count").type(GraphQLInt)) + .field( + newFieldDefinition() + .name("count") + .description( + "Count the number of records in the database for the %s associated nested aggregate".formatted( + association.getName() + ) + ) + .type(GraphQLInt) + ) .build() ) ) @@ -554,7 +617,10 @@ private GraphQLFieldDefinition getAggregateFieldDefinition(EntityType entityT aggregateObjectType.field(countFieldDefinition).field(groupFieldDefinition); - var aggregateFieldDefinition = newFieldDefinition().name("aggregate").type(aggregateObjectType); + var aggregateFieldDefinition = newFieldDefinition() + .name("aggregate") + .description("Aggregate data query field for %s entity".formatted(selectTypeName)) + .type(aggregateObjectType); return aggregateFieldDefinition.build(); } diff --git a/schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaQueryAggregateTests.java b/schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaQueryAggregateTests.java index 8684f534..1d268185 100644 --- a/schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaQueryAggregateTests.java +++ b/schema/src/test/java/com/introproventures/graphql/jpa/query/converter/GraphQLJpaQueryAggregateTests.java @@ -80,7 +80,7 @@ public Object serialize(final Object input) { .filter(VariableValue.class::isInstance) .map(VariableValue.class::cast) .map(it -> Optional.ofNullable(it.getValue()).orElse(Optional.empty())) - .orElse(input); + .orElseGet(() -> super.serialize(input)); } } ) diff --git a/tests/gatling/src/main/java/com/introproventures/graphql/jpa/query/example/Application.java b/tests/gatling/src/main/java/com/introproventures/graphql/jpa/query/example/Application.java index ba69d37d..03ef5ca9 100644 --- a/tests/gatling/src/main/java/com/introproventures/graphql/jpa/query/example/Application.java +++ b/tests/gatling/src/main/java/com/introproventures/graphql/jpa/query/example/Application.java @@ -64,7 +64,7 @@ public Object serialize(final Object input) { .filter(VariableValue.class::isInstance) .map(VariableValue.class::cast) .map(it -> Optional.ofNullable(it.getValue()).orElse(Optional.empty())) - .orElse(input); + .orElseGet(() -> super.serialize(input)); } } )