Skip to content

Commit e3c118e

Browse files
authored
Generate plural names for augmented fields and types (#221)
resolves #197
1 parent 823fe6b commit e3c118e

File tree

8 files changed

+148
-127
lines changed

8 files changed

+148
-127
lines changed

core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
<artifactId>graphql-java</artifactId>
4040
<version>15.0</version>
4141
</dependency>
42+
<dependency>
43+
<groupId>org.atteo</groupId>
44+
<artifactId>evo-inflector</artifactId>
45+
<version>1.2.2</version>
46+
</dependency>
47+
4248
<dependency>
4349
<groupId>org.junit.jupiter</groupId>
4450
<artifactId>junit-jupiter</artifactId>

core/src/main/kotlin/org/neo4j/graphql/BuildingEnv.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.neo4j.graphql
22

33
import graphql.Scalars
44
import graphql.schema.*
5+
import org.atteo.evo.inflector.English
56
import org.neo4j.graphql.handler.projection.ProjectionBase
67

78
class BuildingEnv(
@@ -144,7 +145,7 @@ class BuildingEnv(
144145
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()
145146
.name(ProjectionBase.SORT)
146147
.type(GraphQLList(GraphQLNonNull(GraphQLTypeReference(sortTypeName))))
147-
.description("Specify one or more $sortTypeName objects to sort ${type.name}s by. The sorts will be applied in the order in which they are arranged in the array.")
148+
.description("Specify one or more $sortTypeName objects to sort ${English.plural(type.name)} by. The sorts will be applied in the order in which they are arranged in the array.")
148149
.build())
149150
}
150151
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()

core/src/main/kotlin/org/neo4j/graphql/SchemaConfig.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ data class SchemaConfig @JvmOverloads constructor(
99
*/
1010
val capitalizeQueryFields: Boolean = false,
1111

12+
/**
13+
* if true, the generated fields for query or mutation will use the plural of the types name
14+
*/
15+
val pluralizeFields: Boolean = false,
16+
1217
/**
1318
* Defines the way the input for queries and mutations are generated
1419
*/

core/src/main/kotlin/org/neo4j/graphql/handler/QueryHandler.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.neo4j.graphql.handler
33
import graphql.Scalars
44
import graphql.language.Field
55
import graphql.schema.*
6+
import org.atteo.evo.inflector.English
67
import org.neo4j.cypherdsl.core.Cypher.*
78
import org.neo4j.cypherdsl.core.Statement
89
import org.neo4j.graphql.*
@@ -34,9 +35,13 @@ class QueryHandler private constructor(
3435
input(FILTER, GraphQLTypeReference(filterTypeName))
3536
}
3637

38+
var fieldName = if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize()
39+
if (schemaConfig.pluralizeFields) {
40+
fieldName = English.plural(fieldName)
41+
}
3742
val builder = GraphQLFieldDefinition
3843
.newFieldDefinition()
39-
.name(if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize())
44+
.name(fieldName)
4045
.arguments(arguments)
4146
.type(GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLTypeReference(type.name)))))
4247

0 commit comments

Comments
 (0)