Skip to content

Commit fcae202

Browse files
authored
Upgrade to GraphQL-Java 17.3 (#262)
1 parent 520264a commit fcae202

File tree

10 files changed

+38
-27
lines changed

10 files changed

+38
-27
lines changed

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.graphql-java</groupId>
3939
<artifactId>graphql-java</artifactId>
40-
<version>16.2</version>
40+
<version>17.3</version>
4141
</dependency>
4242
<dependency>
4343
<groupId>org.atteo</groupId>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ object DynamicProperties {
2020
}
2121

2222
@Throws(CoercingParseLiteralException::class)
23-
override fun parseLiteral(o: Any): Any? {
23+
override fun parseLiteral(o: Any): Any {
2424
return parse(o, emptyMap())
2525
}
2626
})
2727
.build()
2828

2929

3030
@Throws(CoercingParseLiteralException::class)
31-
private fun parse(input: Any, variables: Map<String, Any>): Any? {
31+
private fun parse(input: Any, variables: Map<String, Any>): Any {
3232
return when (input) {
3333
!is Value<*> -> throw CoercingParseLiteralException("Expected AST type 'StringValue' but was '${input::class.java.simpleName}'.")
34-
is NullValue -> null
34+
is NullValue -> throw CoercingParseLiteralException("Expected non null value.")
3535
is ObjectValue -> input.objectFields.associate { it.name to parseNested(it.value, variables) }
3636
else -> Assert.assertShouldNeverHappen("Only maps structures are expected")
3737
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fun GraphQLFieldsContainer.label(): String = when {
9292
this.isRelationType() ->
9393
(this as? GraphQLDirectiveContainer)
9494
?.getDirective(DirectiveConstants.RELATION)
95-
?.getArgument(RELATION_NAME)?.value?.toJavaValue()?.toString()
95+
?.getArgument(RELATION_NAME)?.argumentValue?.value?.toJavaValue()?.toString()
9696
?: this.name
9797
else -> name
9898
}
@@ -150,10 +150,11 @@ fun <T> GraphQLDirective.getMandatoryArgument(argumentName: String, defaultValue
150150
fun <T> GraphQLDirective.getArgument(argumentName: String, defaultValue: T? = null): T? {
151151
val argument = getArgument(argumentName)
152152
@Suppress("UNCHECKED_CAST")
153-
return argument?.value as T?
154-
?: argument.defaultValue as T?
155-
?: defaultValue
156-
?: throw IllegalStateException("No default value for @${this.name}::$argumentName")
153+
return when {
154+
argument.argumentValue.isSet && argument.argumentValue.value != null -> argument.argumentValue.value?.toJavaValue() as T?
155+
argument.argumentDefaultValue.isSet -> argument.argumentDefaultValue.value?.toJavaValue() as T?
156+
else -> defaultValue ?: throw IllegalStateException("No default value for @${this.name}::$argumentName")
157+
}
157158
}
158159

159160
fun GraphQLFieldDefinition.cypherDirective(): CypherDirective? = getDirective(CYPHER)?.let {
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package org.neo4j.graphql
22

33
import graphql.schema.Coercing
4+
import graphql.schema.CoercingParseLiteralException
5+
import graphql.schema.CoercingParseValueException
46

57
object NoOpCoercing : Coercing<Any, Any> {
6-
override fun parseLiteral(input: Any?) = input?.toJavaValue()
78

8-
override fun serialize(dataFetcherResult: Any?) = dataFetcherResult
9+
override fun parseLiteral(input: Any) = input.toJavaValue()
10+
?: throw CoercingParseLiteralException("literal should not be null")
11+
12+
override fun serialize(dataFetcherResult: Any) = dataFetcherResult
913

1014
override fun parseValue(input: Any) = input.toJavaValue()
15+
?: throw CoercingParseValueException("literal should not be null")
1116
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ abstract class BaseDataFetcherForContainer(schemaConfig: SchemaConfig) : BaseDat
2525
.arguments
2626
.filterNot { listOf(FIRST, OFFSET, ORDER_BY, NATIVE_ID, OPTIONS).contains(it.name) }
2727
.onEach { arg ->
28-
if (arg.defaultValue != null) {
29-
defaultFields[arg.name] = arg.defaultValue
28+
if (arg.argumentDefaultValue.isSet) {
29+
arg.argumentDefaultValue.value?.let { defaultFields[arg.name] = it }
3030
}
3131
}
3232
.mapNotNull { type.getRelevantFieldDefinition(it.name) }

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.neo4j.graphql.handler.projection
22

3+
import graphql.Scalars.GraphQLString
34
import graphql.schema.*
45
import org.neo4j.cypherdsl.core.*
56
import org.neo4j.cypherdsl.core.Cypher.*
@@ -49,8 +50,10 @@ open class ProjectionBase(
4950
override fun getName(): String = TYPE_NAME
5051
override fun getQualifiedName(): String = TYPE_NAME
5152
override fun getFullyQualifiedName(): String = TYPE_NAME
52-
override fun getObjectType(): GraphQLObjectType? = null
53-
override fun getFieldDefinition(): GraphQLFieldDefinition? = null
53+
override fun getObjectTypes(): List<GraphQLObjectType> = emptyList()
54+
override fun getObjectTypeNames(): List<String> = emptyList()
55+
override fun getFieldDefinitions(): List<GraphQLFieldDefinition> = emptyList()
56+
override fun getType(): GraphQLOutputType = GraphQLString
5457
override fun getArguments(): Map<String, Any> = emptyMap()
5558
override fun getLevel(): Int = 0
5659
override fun isConditional(): Boolean = false
@@ -81,7 +84,8 @@ open class ProjectionBase(
8184
val options = args[OPTIONS] as? Map<*, *>
8285
val defaultOptions = (fieldDefinition?.getArgument(OPTIONS)?.type as? GraphQLInputObjectType)
8386

84-
val sortArray = (options?.get(SORT) ?: defaultOptions?.getField(SORT)?.defaultValue?.toJavaValue())
87+
val sortArray = (options?.get(SORT)
88+
?: defaultOptions?.getField(SORT)?.inputFieldDefaultValue?.value?.toJavaValue())
8589
as? List<*> ?: return null
8690

8791
return sortArray
@@ -100,7 +104,7 @@ open class ProjectionBase(
100104
): List<SortItem>? {
101105

102106
val orderBy = args[ORDER_BY]
103-
?: fieldDefinition?.getArgument(ORDER_BY)?.defaultValue
107+
?: fieldDefinition?.getArgument(ORDER_BY)?.argumentDefaultValue?.value
104108
return orderBy
105109
?.let { it ->
106110
when (it) {
@@ -257,7 +261,8 @@ open class ProjectionBase(
257261
}
258262
projectField(propertyContainer, variable, it, nodeType, env, variableSuffix)
259263
} else {
260-
projectField(propertyContainer, variable, it, it.objectType, env, variableSuffix)
264+
projectField(propertyContainer, variable, it, it.objectTypes.firstOrNull()
265+
?: throw IllegalStateException("only one object type is supported"), env, variableSuffix)
261266
}
262267
projections.addAll(pro)
263268
subQueries += sub
@@ -391,8 +396,8 @@ open class ProjectionBase(
391396
.forEach { (name, value) -> args[name] = queryParameter(value, ctxVariable.value, name).`as`(name) }
392397
fieldDefinition.arguments
393398
.filterNot { SPECIAL_FIELDS.contains(it.name) }
394-
.filter { it.defaultValue != null && !args.containsKey(it.name) }
395-
.forEach { args[it.name] = queryParameter(it.defaultValue, ctxVariable.value, it.name).`as`(it.name) }
399+
.filter { it.argumentDefaultValue.value != null && !args.containsKey(it.name) }
400+
.forEach { args[it.name] = queryParameter(it.argumentDefaultValue.value, ctxVariable.value, it.name).`as`(it.name) }
396401

397402
var reading: OrderableOngoingReadingAndWithWithoutWhere? = null
398403
if (thisValue != null) {
@@ -594,14 +599,14 @@ open class ProjectionBase(
594599

595600
private fun convertArgument(variable: String, arguments: Map<String, Any>, fieldDefinition: GraphQLFieldDefinition?, name: String): Parameter<*>? {
596601
val value = arguments[name]
597-
?: fieldDefinition?.getArgument(name)?.defaultValue
602+
?: fieldDefinition?.getArgument(name)?.argumentDefaultValue?.value
598603
?: return null
599604
return queryParameter(value, variable, name)
600605
}
601606

602607
private fun convertOptionField(variable: String, options: Map<*, *>?, defaultOptions: GraphQLInputObjectType?, name: String): Parameter<*>? {
603608
val value = options?.get(name)
604-
?: defaultOptions?.getField(name)?.defaultValue
609+
?: defaultOptions?.getField(name)?.inputFieldDefaultValue?.value
605610
?: return null
606611
return queryParameter(value, variable, name)
607612
}

core/src/main/kotlin/org/neo4j/graphql/parser/QueryParser.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ object QueryParser {
118118
.toMap(mutableMapOf())
119119
var index = queriedFields.size
120120
fieldDefinition.arguments
121-
.filter { it.defaultValue != null }
121+
.filter { it.argumentDefaultValue.value != null }
122122
.filterNot { queriedFields.containsKey(it.name) }
123123
.filterNot { ProjectionBase.SPECIAL_FIELDS.contains(it.name) }
124124
.forEach { argument ->
125-
queriedFields[argument.name] = index++ to argument.defaultValue
125+
queriedFields[argument.name] = index++ to argument.argumentDefaultValue.value
126126
}
127127

128128
return createParsedQuery(queriedFields, type)

examples/dgs-spring-boot/src/test/kotlin/org/neo4j/graphql/examples/dgsspringboot/datafetcher/AdditionalDataFetcherTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,6 @@ internal class AdditionalDataFetcherTest(
135135

136136
companion object {
137137
@Container
138-
private val neo4jServer = Neo4jContainer<Nothing>("neo4j:4.2.4")
138+
private val neo4jServer = Neo4jContainer<Nothing>("neo4j:4.4.1")
139139
}
140140
}

examples/graphql-spring-boot/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
<properties>
1818
<testcontainers.version>1.16.2</testcontainers.version>
19-
<graphql-kotlin.version>5.2.0</graphql-kotlin.version>
19+
<graphql-kotlin.version>5.3.1</graphql-kotlin.version>
2020
<spring-boot.version>2.6.1</spring-boot.version>
2121
</properties>
2222

examples/graphql-spring-boot/src/test/kotlin/org/neo4j/graphql/examples/graphqlspringboot/controller/QueriesIT.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal class QueriesIT(
104104

105105
companion object {
106106
@Container
107-
private val neo4jServer = Neo4jContainer<Nothing>("neo4j:4.2.4")
107+
private val neo4jServer = Neo4jContainer<Nothing>("neo4j:4.4.1")
108108

109109
}
110110

0 commit comments

Comments
 (0)