Skip to content

Commit 6b28da7

Browse files
committed
Generate plural names for augmented fields and types
resolves #197
1 parent 9acc31e commit 6b28da7

File tree

8 files changed

+173
-129
lines changed

8 files changed

+173
-129
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(
@@ -143,7 +144,7 @@ class BuildingEnv(
143144
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()
144145
.name(ProjectionBase.SORT)
145146
.type(GraphQLList(GraphQLNonNull(GraphQLTypeReference(sortTypeName))))
146-
.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.")
147+
.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.")
147148
.build())
148149
}
149150
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ data class SchemaConfig @JvmOverloads constructor(
77
* if true, the top level fields of the Query-type will be capitalized
88
*/
99
val capitalizeQueryFields: Boolean = false,
10+
11+
/**
12+
* if true, the generated fields for query or mutation will use the plural of the types name
13+
*/
14+
val pluralizeFields: Boolean = false,
15+
1016
/**
1117
* Defines the way the input for queries and mutations are generated
1218
*/

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.*
@@ -29,9 +30,13 @@ class QueryHandler private constructor(
2930
buildingEnv.addInputType("_${typeName}Input", type.relevantFields())
3031
val filterTypeName = buildingEnv.addFilterType(type)
3132

33+
var fieldName = if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize()
34+
if (schemaConfig.pluralizeFields) {
35+
fieldName = English.plural(fieldName)
36+
}
3237
val builder = GraphQLFieldDefinition
3338
.newFieldDefinition()
34-
.name(if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize())
39+
.name(fieldName)
3540
.arguments(buildingEnv.getInputValueDefinitions(relevantFields) { true })
3641
.argument(input(FILTER, GraphQLTypeReference(filterTypeName)))
3742
.type(GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLTypeReference(type.name)))))

0 commit comments

Comments
 (0)