Skip to content

Generate plural names for augmented fields and types #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
<artifactId>graphql-java</artifactId>
<version>15.0</version>
</dependency>
<dependency>
<groupId>org.atteo</groupId>
<artifactId>evo-inflector</artifactId>
<version>1.2.2</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/kotlin/org/neo4j/graphql/BuildingEnv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.neo4j.graphql

import graphql.Scalars
import graphql.schema.*
import org.atteo.evo.inflector.English
import org.neo4j.graphql.handler.projection.ProjectionBase

class BuildingEnv(
Expand Down Expand Up @@ -144,7 +145,7 @@ class BuildingEnv(
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()
.name(ProjectionBase.SORT)
.type(GraphQLList(GraphQLNonNull(GraphQLTypeReference(sortTypeName))))
.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.")
.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.")
.build())
}
optionsTypeBuilder.field(GraphQLInputObjectField.newInputObjectField()
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/kotlin/org/neo4j/graphql/SchemaConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ data class SchemaConfig @JvmOverloads constructor(
*/
val capitalizeQueryFields: Boolean = false,

/**
* if true, the generated fields for query or mutation will use the plural of the types name
*/
val pluralizeFields: Boolean = false,

/**
* Defines the way the input for queries and mutations are generated
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.neo4j.graphql.handler
import graphql.Scalars
import graphql.language.Field
import graphql.schema.*
import org.atteo.evo.inflector.English
import org.neo4j.cypherdsl.core.Cypher.*
import org.neo4j.cypherdsl.core.Statement
import org.neo4j.graphql.*
Expand Down Expand Up @@ -34,9 +35,13 @@ class QueryHandler private constructor(
input(FILTER, GraphQLTypeReference(filterTypeName))
}

var fieldName = if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize()
if (schemaConfig.pluralizeFields) {
fieldName = English.plural(fieldName)
}
val builder = GraphQLFieldDefinition
.newFieldDefinition()
.name(if (schemaConfig.capitalizeQueryFields) typeName else typeName.decapitalize())
.name(fieldName)
.arguments(arguments)
.type(GraphQLNonNull(GraphQLList(GraphQLNonNull(GraphQLTypeReference(type.name)))))

Expand Down
Loading