Skip to content

Commit

Permalink
Generate plural names for augmented fields and types (#221)
Browse files Browse the repository at this point in the history
resolves #197
  • Loading branch information
Andy2003 authored May 4, 2021
1 parent 823fe6b commit e3c118e
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 127 deletions.
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

0 comments on commit e3c118e

Please sign in to comment.