Skip to content

Commit b5ff228

Browse files
committed
adjustments for graphql-java update
1 parent 6873361 commit b5ff228

File tree

9 files changed

+44
-181
lines changed

9 files changed

+44
-181
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class BuildingEnv(val types: MutableMap<String, GraphQLNamedType>) {
8989
.forEach { field ->
9090
val typeDefinition = field.type.inner()
9191
val filterType = when {
92-
typeDefinition.isNeo4jType() -> simplePrint(getInputType(typeDefinition))
92+
typeDefinition.isNeo4jType() -> getInputType(typeDefinition).requiredName()
9393
typeDefinition.isScalar() -> typeDefinition.innerName()
9494
typeDefinition is GraphQLEnumType -> typeDefinition.innerName()
9595
else -> addFilterType(getInnerFieldsContainer(typeDefinition), createdTypes)
@@ -124,7 +124,7 @@ class BuildingEnv(val types: MutableMap<String, GraphQLNamedType>) {
124124
val orderingName = "_${type.name}Ordering"
125125
var existingOrderingType = types[orderingName]
126126
if (existingOrderingType != null) {
127-
return simplePrint(existingOrderingType as? GraphQLInputType)
127+
return (existingOrderingType as? GraphQLInputType)?.requiredName()
128128
?: throw IllegalStateException("Ordering type $type.name is already defined but not an input type")
129129
}
130130
val sortingFields = type.fieldDefinitions
@@ -192,7 +192,7 @@ class BuildingEnv(val types: MutableMap<String, GraphQLNamedType>) {
192192
?: throw IllegalArgumentException("${innerType.name} is unknown")
193193
}
194194
return innerType as? GraphQLFieldsContainer
195-
?: throw IllegalArgumentException("${simplePrint(innerType)} is neither an object nor an interface")
195+
?: throw IllegalArgumentException("${innerType.name()} is neither an object nor an interface")
196196
}
197197

198198
private fun getInputType(type: GraphQLType): GraphQLInputType {
@@ -202,12 +202,12 @@ class BuildingEnv(val types: MutableMap<String, GraphQLNamedType>) {
202202
}
203203
if (inner.isNeo4jType()) {
204204
return neo4jTypeDefinitions
205-
.find { it.typeDefinition == simplePrint(inner) }
205+
.find { it.typeDefinition == inner.name() }
206206
?.let { types[it.inputDefinition] } as? GraphQLInputType
207-
?: throw IllegalArgumentException("Cannot find input type for ${simplePrint(inner)}")
207+
?: throw IllegalArgumentException("Cannot find input type for ${inner.name()}")
208208
}
209209
return type as? GraphQLInputType
210-
?: throw IllegalArgumentException("${simplePrint(type)} is not allowed for input")
210+
?: throw IllegalArgumentException("${type.name()} is not allowed for input")
211211
}
212212

213-
}
213+
}

src/main/kotlin/org/neo4j/graphql/GraphQLExtensions.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ import org.neo4j.graphql.DirectiveConstants.Companion.RELATION_NAME
2020
import org.neo4j.graphql.DirectiveConstants.Companion.RELATION_TO
2121
import org.neo4j.graphql.handler.projection.ProjectionBase
2222

23-
import graphql.schema.GraphQLTypeUtil.simplePrint
24-
2523
fun Type<Type<*>>.name(): String? = if (this.inner() is TypeName) (this.inner() as TypeName).name else null
2624
fun Type<Type<*>>.inner(): Type<Type<*>> = when (this) {
2725
is ListType -> this.type.inner()
@@ -35,8 +33,11 @@ fun GraphQLType.inner(): GraphQLType = when (this) {
3533
else -> this
3634
}
3735

36+
fun GraphQLType.name(): String? = (this as? GraphQLNamedType)?.name
37+
fun GraphQLType.requiredName(): String = requireNotNull(name()) { -> "name is required but cannot be determined for " + this.javaClass }
38+
3839
fun GraphQLType.isList() = this is GraphQLList || (this is GraphQLNonNull && this.wrappedType is GraphQLList)
39-
fun GraphQLType.isScalar() = this.inner().let { it is GraphQLScalarType || simplePrint(it).startsWith("_Neo4j") }
40+
fun GraphQLType.isScalar() = this.inner().let { it is GraphQLScalarType || it.innerName().startsWith("_Neo4j") }
4041
fun GraphQLType.isNeo4jType() = this.innerName().startsWith("_Neo4j")
4142
fun GraphQLType.isNeo4jSpatialType() = this.innerName().startsWith("_Neo4jPoint")
4243
fun GraphQLFieldDefinition.isNeo4jType(): Boolean = this.type.isNeo4jType()
@@ -121,7 +122,7 @@ fun GraphQLType.ref(): GraphQLType = when (this) {
121122
is GraphQLScalarType -> this
122123
is GraphQLEnumType -> this
123124
is GraphQLTypeReference -> this
124-
else -> GraphQLTypeReference(simplePrint(this))
125+
else -> GraphQLTypeReference(name())
125126
}
126127

127128
fun relDetails(type: GraphQLFieldsContainer, relDirective: GraphQLDirective): RelationshipInfo {
@@ -185,7 +186,8 @@ data class RelationshipInfo(
185186
}
186187

187188
fun Field.aliasOrName() = (this.alias ?: this.name).quote()
188-
fun GraphQLType.innerName(): String = simplePrint(inner())
189+
fun GraphQLType.innerName(): String = inner().name()
190+
?: throw IllegalStateException("inner name cannot be retrieved for " + this.javaClass)
189191

190192
fun GraphQLFieldDefinition.propertyName() = getDirectiveArgument(PROPERTY, PROPERTY_NAME, this.name)!!
191193

src/main/kotlin/org/neo4j/graphql/Neo4jTypes.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import graphql.language.ObjectValue
55
import graphql.schema.GraphQLFieldDefinition
66
import graphql.schema.GraphQLFieldsContainer
77

8-
import graphql.schema.GraphQLTypeUtil.simplePrint
9-
108
const val NEO4j_FORMATTED_PROPERTY_KEY = "formatted"
119
const val NEO4j_POINT_DISTANCE_FILTER = "_Neo4jPointDistanceFilter"
1210
const val NEO4j_POINT_DISTANCE_FILTER_SUFFIX = "_distance"
@@ -60,7 +58,7 @@ data class Neo4jQueryConversion(val name: String, val propertyName: String, val
6058
if (!isNeo4jType) {
6159
Neo4jQueryConversion(name, name)
6260
}
63-
val converter = getNeo4jTypeConverter(simplePrint(fieldDefinition.type.inner()))
61+
val converter = getNeo4jTypeConverter(fieldDefinition.type.innerName())
6462
val objectValue = (value as? ObjectValue)
6563
?.objectFields
6664
?.map { it.name to it.value }
@@ -82,4 +80,4 @@ val neo4jTypeDefinitions = listOf(
8280
TypeDefinition("Time", "_Neo4jLocalTime"),
8381
TypeDefinition("LocalDateTime", "_Neo4jLocalDateTime"),
8482
TypeDefinition("Point", "_Neo4jPoint")
85-
)
83+
)

src/main/kotlin/org/neo4j/graphql/Predicates.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import org.neo4j.graphql.Predicate.Companion.resolvePredicate
1111
import org.neo4j.graphql.handler.projection.ProjectionBase
1212
import org.slf4j.LoggerFactory
1313

14-
import graphql.schema.GraphQLTypeUtil.simplePrint
15-
1614
typealias CypherDSL = org.neo4j.cypherdsl.core.Cypher
1715

1816
interface Predicate {
@@ -114,7 +112,7 @@ data class ExpressionPredicate(
114112
) : Predicate {
115113
val not = if (op.not) "NOT " else ""
116114
override fun toExpression(variable: String): Cypher {
117-
val paramName: String = ProjectionBase.FILTER + paramName(variable, name, value).capitalize() + "_" + op.name + nestedField.replace('.','_')
115+
val paramName: String = ProjectionBase.FILTER + paramName(variable, name, value).capitalize() + "_" + op.name + nestedField.replace('.', '_')
118116
val query = if (fieldDefinition.isNativeId()) {
119117
if (op.list) {
120118
"${not}ID($variable) ${op.op} [id IN \$$paramName | toInteger(id)]"
@@ -256,7 +254,7 @@ enum class FieldOperator(
256254
fun resolve(queriedField: String, field: GraphQLFieldDefinition, value: Any?): FieldOperator? {
257255
val fieldName = field.name
258256
if (value == null) {
259-
return listOf(IS_NULL, IS_NOT_NULL).find { queriedField == fieldName + it.suffix } ?: return null
257+
return listOf(IS_NULL, IS_NOT_NULL).find { queriedField == fieldName + it.suffix }
260258
}
261259
val ops = enumValues<FieldOperator>().filterNot { it == IS_NULL || it == IS_NOT_NULL }
262260
return ops.find { queriedField == fieldName + it.suffix }
@@ -265,7 +263,6 @@ enum class FieldOperator(
265263
} else {
266264
null
267265
}
268-
?: return null
269266
}
270267

271268
fun forType(type: GraphQLType): List<FieldOperator> =
@@ -279,7 +276,7 @@ enum class FieldOperator(
279276
// todo list types
280277
!type.isScalar() -> listOf(EQ, NEQ, IN, NIN)
281278
else -> listOf(EQ, NEQ, IN, NIN, LT, LTE, GT, GTE) +
282-
if (simplePrint(type) == "String" || simplePrint(type) == "ID") listOf(C, NC, SW, NSW, EW, NEW) else emptyList()
279+
if (type.name() == "String" || type.name() == "ID") listOf(C, NC, SW, NSW, EW, NEW) else emptyList()
283280
}
284281
}
285282

src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import graphql.language.*
44
import graphql.schema.*
55
import org.neo4j.graphql.*
66

7-
import graphql.schema.GraphQLTypeUtil.simplePrint
8-
97
open class ProjectionBase {
108
companion object {
119
const val NATIVE_ID = "_id"
@@ -297,8 +295,10 @@ open class ProjectionBase {
297295
private fun relationshipInfoInCorrectDirection(fieldObjectType: GraphQLFieldsContainer, relInfo0: RelationshipInfo, parent: GraphQLFieldsContainer, relDirectiveField: RelationshipInfo?): RelationshipInfo {
298296
val startField = fieldObjectType.getFieldDefinition(relInfo0.startField)!!
299297
val endField = fieldObjectType.getFieldDefinition(relInfo0.endField)!!
300-
val startFieldTypeName = simplePrint(startField.type.inner())
301-
val inverse = startFieldTypeName != parent.name || simplePrint(startField.type) == simplePrint(endField.type) && relDirectiveField?.out != relInfo0.out
298+
val startFieldTypeName = startField.type.innerName()
299+
val inverse = startFieldTypeName != parent.name
300+
|| startFieldTypeName == endField.type.innerName()
301+
&& relDirectiveField?.out != relInfo0.out
302302
return if (inverse) relInfo0.copy(out = relInfo0.out?.not(), startField = relInfo0.endField, endField = relInfo0.startField) else relInfo0
303303
}
304304

@@ -329,7 +329,7 @@ open class ProjectionBase {
329329

330330
val (endNodePattern, variableSuffix) = when {
331331
isRelFromType -> {
332-
val label = simplePrint(nodeType.getFieldDefinition(relInfo.endField!!)!!.type.inner())
332+
val label = nodeType.getFieldDefinition(relInfo.endField!!)!!.type.innerName()
333333
("$childVariable${relInfo.endField.capitalize()}:$label" to relInfo.endField)
334334
}
335335
else -> ("$childVariable:${nodeType.name}" to null)

src/test/kotlin/org/neo4j/graphql/TranslatorExceptionTests.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TranslatorExceptionTests : AsciiDocTestSuite("translator-tests1.adoc") {
1616
}
1717

1818
override fun schemaTestFactory(schema: String): List<DynamicNode> {
19-
val translator = Translator(SchemaBuilder.buildSchema(schema));
19+
val translator = Translator(SchemaBuilder.buildSchema(schema))
2020
return listOf(
2121
DynamicTest.dynamicTest("unknownType") {
2222
Assertions.assertThrows(IllegalArgumentException::class.java) {

src/test/kotlin/org/neo4j/graphql/utils/GraphQLSchemaTestSuite.kt

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package org.neo4j.graphql.utils
22

33
import graphql.language.InterfaceTypeDefinition
4-
import graphql.schema.*
5-
import graphql.schema.GraphQLTypeUtil.simplePrint
4+
import graphql.schema.GraphQLSchema
5+
import graphql.schema.GraphQLType
66
import graphql.schema.diff.DiffSet
77
import graphql.schema.diff.SchemaDiff
88
import graphql.schema.diff.reporting.CapturingReporter
@@ -17,6 +17,7 @@ import org.junit.jupiter.api.DynamicTest
1717
import org.neo4j.graphql.DynamicProperties
1818
import org.neo4j.graphql.SchemaBuilder
1919
import org.neo4j.graphql.SchemaConfig
20+
import org.neo4j.graphql.requiredName
2021
import org.opentest4j.AssertionFailedError
2122
import java.util.*
2223
import java.util.regex.Pattern
@@ -79,37 +80,14 @@ class GraphQLSchemaTestSuite(fileName: String) : AsciiDocTestSuite(fileName) {
7980
.includeScalarTypes(true)
8081
.includeSchemaDefinition(true)
8182
.includeIntrospectionTypes(false)
82-
.setComparators(DefaultGraphqlTypeComparatorRegistry.newComparators()
83-
.addComparator({ env ->
84-
env.parentType(GraphQLObjectType::class.java)
85-
env.elementType(GraphQLOutputType::class.java)
86-
}, GraphQLOutputType::class.java, fun(o1: GraphQLOutputType, o2: GraphQLOutputType): Int {
87-
val (op1, name1) = o1.splitName()
88-
val (op2, name2) = o2.splitName()
89-
if (op1 == null && op2 == null) {
90-
return name1.compareTo(name2)
91-
}
92-
if (op1 == null) {
93-
return -1
94-
}
95-
if (op2 == null) {
96-
return 1
97-
}
98-
val prio1 = name1.compareTo(name2)
99-
if (prio1 == 0) {
100-
return op1.compareTo(op2)
101-
}
102-
return prio1
103-
})
104-
.build())
10583
)
10684

10785
fun GraphQLType.splitName(): Pair<String?, String> {
108-
val m = METHOD_PATTERN.matcher(simplePrint(this))
86+
val m = METHOD_PATTERN.matcher(this.requiredName())
10987
return if (m.find()) {
11088
m.group(1) to m.group(2).toLowerCase()
11189
} else {
112-
null to simplePrint(this).toLowerCase()
90+
null to this.requiredName().toLowerCase()
11391
}
11492
}
11593

src/test/resources/relationship-tests.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ RETURN team {
305305
[source,graphql]
306306
----
307307
{
308-
player {
308+
player{
309309
id
310310
memberships {
311311
team {

0 commit comments

Comments
 (0)