Skip to content

Commit e5a9dac

Browse files
authored
update dependencies (#302)
1 parent 97aee0d commit e5a9dac

File tree

28 files changed

+287
-241
lines changed

28 files changed

+287
-241
lines changed

core/pom.xml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<dependency>
1919
<groupId>org.neo4j.driver</groupId>
2020
<artifactId>neo4j-java-driver</artifactId>
21-
<version>5.3.1</version>
21+
<version>5.11.0</version>
2222
<scope>test</scope>
2323
</dependency>
2424
<dependency>
@@ -45,10 +45,15 @@
4545
<version>${neo4j-apoc.version}</version>
4646
<scope>test</scope>
4747
</dependency>
48+
<dependency>
49+
<groupId>org.neo4j</groupId>
50+
<artifactId>neo4j-cypher-dsl</artifactId>
51+
<version>2023.9.5</version>
52+
</dependency>
4853
<dependency>
4954
<groupId>com.graphql-java</groupId>
5055
<artifactId>graphql-java</artifactId>
51-
<version>19.2</version>
56+
<version>21.5</version>
5257
</dependency>
5358
<dependency>
5459
<groupId>org.atteo</groupId>
@@ -70,11 +75,6 @@
7075
<artifactId>assertj-core</artifactId>
7176
<scope>test</scope>
7277
</dependency>
73-
<dependency>
74-
<groupId>org.neo4j</groupId>
75-
<artifactId>neo4j-cypher-dsl</artifactId>
76-
<version>2023.0.0</version>
77-
</dependency>
7878
<dependency>
7979
<groupId>ch.qos.logback</groupId>
8080
<artifactId>logback-classic</artifactId>
@@ -91,7 +91,7 @@
9191
<dependency>
9292
<groupId>org.junit.vintage</groupId>
9393
<artifactId>junit-vintage-engine</artifactId>
94-
<version>5.9.0</version>
94+
<version>${junit-jupiter.version}</version>
9595
<scope>test</scope>
9696
</dependency>
9797
</dependencies>
@@ -111,12 +111,12 @@
111111
<dependency>
112112
<groupId>org.assertj</groupId>
113113
<artifactId>assertj-core</artifactId>
114-
<version>3.23.1</version>
114+
<version>3.24.2</version>
115115
</dependency>
116116
<dependency>
117117
<groupId>org.slf4j</groupId>
118118
<artifactId>slf4j-api</artifactId>
119-
<version>2.0.5</version>
119+
<version>2.0.7</version>
120120
</dependency>
121121
</dependencies>
122122
</dependencyManagement>

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

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

33
import graphql.Assert
4+
import graphql.GraphQLContext
5+
import graphql.execution.CoercedVariables
46
import graphql.language.*
57
import graphql.schema.*
8+
import java.util.*
69

710
object DynamicProperties {
811

912
val INSTANCE: GraphQLScalarType = GraphQLScalarType.newScalar()
1013
.name("DynamicProperties")
1114
.coercing(object : Coercing<Any, Any> {
1215
@Throws(CoercingSerializeException::class)
13-
override fun serialize(input: Any): Any {
16+
override fun serialize(input: Any, graphQLContext: GraphQLContext, locale: Locale): Any {
1417
return input
1518
}
1619

17-
@Throws(CoercingParseValueException::class)
18-
override fun parseValue(input: Any): Any {
20+
@Throws(CoercingParseLiteralException::class)
21+
override fun parseValue(input: Any, graphQLContext: GraphQLContext, locale: Locale): Any {
1922
return input
2023
}
2124

2225
@Throws(CoercingParseLiteralException::class)
23-
override fun parseLiteral(o: Any): Any {
24-
return parse(o, emptyMap())
26+
override fun parseLiteral(
27+
input: Value<*>,
28+
variables: CoercedVariables,
29+
graphQLContext: GraphQLContext,
30+
locale: Locale
31+
): Any {
32+
return parse(input, emptyMap())
2533
}
2634
})
2735
.build()

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import graphql.language.Description
44
import graphql.language.VariableReference
55
import graphql.schema.GraphQLOutputType
66
import org.neo4j.cypherdsl.core.*
7+
import org.neo4j.cypherdsl.core.Cypher
8+
import org.neo4j.cypherdsl.core.Cypher.elementId
79
import java.util.*
810

911
fun queryParameter(value: Any?, vararg parts: String?): Parameter<*> {
1012
val name = when (value) {
1113
is VariableReference -> value.name
1214
else -> normalizeName(*parts)
1315
}
14-
return org.neo4j.cypherdsl.core.Cypher.parameter(name).withValue(value?.toJavaValue())
16+
return Cypher.parameter(name).withValue(value?.toJavaValue())
1517
}
1618

17-
fun Expression.collect(type: GraphQLOutputType) = if (type.isList()) Functions.collect(this) else this
19+
fun Expression.collect(type: GraphQLOutputType) = if (type.isList()) Cypher.collect(this) else this
1820
fun StatementBuilder.OngoingReading.withSubQueries(subQueries: List<Statement>) = subQueries.fold(this, { it, sub -> it.call(sub) })
1921

2022
fun normalizeName(vararg parts: String?) = parts.mapNotNull { it?.capitalize() }.filter { it.isNotBlank() }.joinToString("").decapitalize()
2123

2224
fun PropertyContainer.id(): FunctionInvocation = when (this) {
23-
is Node -> Functions.id(this)
24-
is Relationship -> Functions.id(this)
25+
is Node -> elementId(this)
26+
is Relationship -> elementId(this)
2527
else -> throw IllegalArgumentException("Id can only be retrieved for Nodes or Relationships")
2628
}
2729

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fun GraphQLFieldDefinition.isNeo4jTemporalType(): Boolean = this.type.isNeo4jTem
5252

5353
fun GraphQLFieldDefinition.isRelationship() = !type.isNeo4jType() && this.type.inner().let { it is GraphQLFieldsContainer }
5454

55-
fun GraphQLFieldsContainer.isRelationType() = (this as? GraphQLDirectiveContainer)?.getDirective(DirectiveConstants.RELATION) != null
55+
fun GraphQLFieldsContainer.isRelationType() = (this as? GraphQLDirectiveContainer)?.getAppliedDirective(DirectiveConstants.RELATION) != null
5656
fun GraphQLFieldsContainer.relationshipFor(name: String): RelationshipInfo<GraphQLFieldsContainer>? {
5757
val field = getRelevantFieldDefinition(name)
5858
?: throw IllegalArgumentException("$name is not defined on ${this.name}")
@@ -61,15 +61,15 @@ fun GraphQLFieldsContainer.relationshipFor(name: String): RelationshipInfo<Graph
6161
val (relDirective, inverse) = if (isRelationType()) {
6262
val typeName = this.name
6363
(this as? GraphQLDirectiveContainer)
64-
?.getDirective(DirectiveConstants.RELATION)?.let {
64+
?.getAppliedDirective(DirectiveConstants.RELATION)?.let {
6565
// do inverse mapping, if the current type is the `to` mapping of the relation
6666
it to (fieldObjectType.getRelevantFieldDefinition(it.getArgument(RELATION_TO, null as String?))?.name == typeName)
6767
}
6868
?: throw IllegalStateException("Type ${this.name} needs an @relation directive")
6969
} else {
7070
(fieldObjectType as? GraphQLDirectiveContainer)
71-
?.getDirective(DirectiveConstants.RELATION)?.let { it to true }
72-
?: field.getDirective(DirectiveConstants.RELATION)?.let { it to false }
71+
?.getAppliedDirective(DirectiveConstants.RELATION)?.let { it to true }
72+
?: field.getAppliedDirective(DirectiveConstants.RELATION)?.let { it to false }
7373
?: throw IllegalStateException("Field $field needs an @relation directive")
7474
}
7575

@@ -92,7 +92,7 @@ fun GraphQLFieldsContainer.getValidTypeLabels(schema: GraphQLSchema): List<Strin
9292
fun GraphQLFieldsContainer.label(): String = when {
9393
this.isRelationType() ->
9494
(this as? GraphQLDirectiveContainer)
95-
?.getDirective(DirectiveConstants.RELATION)
95+
?.getAppliedDirective(DirectiveConstants.RELATION)
9696
?.getArgument(RELATION_NAME)?.argumentValue?.value?.toJavaValue()?.toString()
9797
?: this.name
9898

@@ -125,7 +125,7 @@ fun GraphQLType.getInnerFieldsContainer() = inner() as? GraphQLFieldsContainer
125125
?: throw IllegalArgumentException("${this.innerName()} is neither an object nor an interface")
126126

127127
fun <T> GraphQLDirectiveContainer.getDirectiveArgument(directiveName: String, argumentName: String, defaultValue: T?): T? =
128-
getDirective(directiveName)?.getArgument(argumentName, defaultValue) ?: defaultValue
128+
getAppliedDirective(directiveName)?.getArgument(argumentName, defaultValue) ?: defaultValue
129129

130130
@Suppress("UNCHECKED_CAST")
131131
fun <T> DirectivesContainer<*>.getDirectiveArgument(typeRegistry: TypeDefinitionRegistry, directiveName: String, argumentName: String, defaultValue: T? = null): T? {
@@ -141,25 +141,24 @@ fun <T> DirectivesContainer<*>.getDirectiveArgument(typeRegistry: TypeDefinition
141141

142142
fun DirectivesContainer<*>.getDirective(name: String): Directive? = directives.firstOrNull { it.name == name }
143143

144-
@Suppress("UNCHECKED_CAST")
145144
fun <T> DirectivesContainer<*>.getMandatoryDirectiveArgument(typeRegistry: TypeDefinitionRegistry, directiveName: String, argumentName: String, defaultValue: T? = null): T =
146145
getDirectiveArgument(typeRegistry, directiveName, argumentName, defaultValue)
147146
?: throw IllegalStateException("No default value for @${directiveName}::$argumentName")
148147

149-
fun <T> GraphQLDirective.getMandatoryArgument(argumentName: String, defaultValue: T? = null): T = this.getArgument(argumentName, defaultValue)
148+
fun <T> GraphQLAppliedDirective.getMandatoryArgument(argumentName: String, defaultValue: T? = null): T = this.getArgument(argumentName, defaultValue)
150149
?: throw IllegalStateException(argumentName + " is required for @${this.name}")
151150

152-
fun <T> GraphQLDirective.getArgument(argumentName: String, defaultValue: T? = null): T? {
151+
fun <T> GraphQLAppliedDirective.getArgument(argumentName: String, defaultValue: T? = null): T? {
153152
val argument = getArgument(argumentName)
154153
@Suppress("UNCHECKED_CAST")
155154
return when {
156155
argument.argumentValue.isSet && argument.argumentValue.value != null -> argument.argumentValue.value?.toJavaValue() as T?
157-
argument.argumentDefaultValue.isSet -> argument.argumentDefaultValue.value?.toJavaValue() as T?
156+
argument.definition?.value != null -> argument.definition?.value?.toJavaValue() as T?
158157
else -> defaultValue ?: throw IllegalStateException("No default value for @${this.name}::$argumentName")
159158
}
160159
}
161160

162-
fun GraphQLFieldDefinition.cypherDirective(): CypherDirective? = getDirective(CYPHER)?.let {
161+
fun GraphQLFieldDefinition.cypherDirective(): CypherDirective? = getAppliedDirective(CYPHER)?.let {
163162
val originalStatement = it.getMandatoryArgument<String>(CYPHER_STATEMENT)
164163
// Arguments on the field are passed to the Cypher statement and can be used by name.
165164
// They must not be prefixed by $ since they are no longer parameters. Just use the same name as the fields' argument.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class Neo4jTimeConverter(name: String) : Neo4jConverter(name) {
6363
class Neo4jPointConverter(name: String) : Neo4jConverter(name) {
6464

6565
fun createDistanceCondition(lhs: Expression, rhs: Parameter<*>, conditionCreator: (Expression, Expression) -> Condition): Condition {
66-
val point = Functions.point(rhs.property("point"))
66+
val point = Cypher.point(rhs.property("point"))
6767
val distance = rhs.property("distance")
68-
return conditionCreator(Functions.distance(lhs, point), distance)
68+
return conditionCreator(Cypher.distance(lhs, point), distance)
6969
}
7070
}
7171

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ import graphql.language.TypeDefinition
55
import graphql.schema.GraphQLFieldDefinition
66
import graphql.schema.GraphQLFieldsContainer
77
import org.neo4j.cypherdsl.core.*
8-
import org.neo4j.cypherdsl.core.Predicates.OngoingListBasedPredicateFunction
8+
import org.neo4j.cypherdsl.core.Cypher
99
import org.slf4j.LoggerFactory
1010

11-
typealias CypherDSL = org.neo4j.cypherdsl.core.Cypher
12-
13-
private fun createArrayPredicate(factory: (SymbolicName) -> OngoingListBasedPredicateFunction) = { lhs: Expression, rhs: Expression ->
14-
val x: SymbolicName = org.neo4j.cypherdsl.core.Cypher.name("x")
11+
private fun createArrayPredicate(factory: (SymbolicName) -> Predicates.OngoingListBasedPredicateFunction) = { lhs: Expression, rhs: Expression ->
12+
val x: SymbolicName = Cypher.name("x")
1513
factory(x).`in`(lhs).where(x.`in`(rhs))
1614
}
1715

@@ -42,10 +40,10 @@ enum class FieldOperator(
4240
EW("_ends_with", { lhs, rhs -> lhs.endsWith(rhs) }),
4341
MATCHES("_matches", { lhs, rhs -> lhs.matches(rhs) }),
4442

45-
INCLUDES_ALL("_includes_all", createArrayPredicate(Predicates::all), list = true),
46-
INCLUDES_SOME("_includes_some", createArrayPredicate(Predicates::any), list = true),
47-
INCLUDES_NONE("_includes_none", createArrayPredicate(Predicates::none), list = true),
48-
INCLUDES_SINGLE("_includes_single", createArrayPredicate(Predicates::single), list = true),
43+
INCLUDES_ALL("_includes_all", createArrayPredicate(Cypher::all), list = true),
44+
INCLUDES_SOME("_includes_some", createArrayPredicate(Cypher::any), list = true),
45+
INCLUDES_NONE("_includes_none", createArrayPredicate(Cypher::none), list = true),
46+
INCLUDES_SINGLE("_includes_single", createArrayPredicate(Cypher::single), list = true),
4947

5048
DISTANCE(NEO4j_POINT_DISTANCE_FILTER_SUFFIX, { lhs, rhs -> lhs.isEqualTo(rhs) }, distance = true),
5149
DISTANCE_LT(NEO4j_POINT_DISTANCE_FILTER_SUFFIX + "_lt", { lhs, rhs -> lhs.lt(rhs) }, distance = true),
@@ -74,10 +72,10 @@ enum class FieldOperator(
7472
val id = propertyContainer.id()
7573
val parameter = queryParameter(value, variablePrefix, queriedField, suffix)
7674
val condition = if (list) {
77-
val idVar = CypherDSL.name("id")
78-
conditionCreator(id, CypherDSL.listWith(idVar).`in`(parameter).returning(CypherDSL.call("toInteger").withArgs(idVar).asFunction()))
75+
val idVar = Cypher.name("id")
76+
conditionCreator(id, Cypher.listWith(idVar).`in`(parameter).returning(idVar))
7977
} else {
80-
conditionCreator(id, CypherDSL.call("toInteger").withArgs(parameter).asFunction())
78+
conditionCreator(id, parameter)
8179
}
8280
listOf(condition)
8381
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.neo4j.graphql
22

33
import graphql.language.ImplementingTypeDefinition
4-
import graphql.schema.GraphQLDirective
4+
import graphql.schema.GraphQLAppliedDirective
55
import graphql.schema.GraphQLDirectiveContainer
66
import graphql.schema.GraphQLFieldsContainer
77
import graphql.schema.idl.TypeDefinitionRegistry
@@ -33,10 +33,10 @@ data class RelationshipInfo<TYPE>(
3333

3434
companion object {
3535
fun create(type: GraphQLFieldsContainer): RelationshipInfo<GraphQLFieldsContainer>? = (type as? GraphQLDirectiveContainer)
36-
?.getDirective(DirectiveConstants.RELATION)
36+
?.getAppliedDirective(DirectiveConstants.RELATION)
3737
?.let { relDirective -> create(type, relDirective) }
3838

39-
fun create(type: GraphQLFieldsContainer, relDirective: GraphQLDirective): RelationshipInfo<GraphQLFieldsContainer> {
39+
fun create(type: GraphQLFieldsContainer, relDirective: GraphQLAppliedDirective): RelationshipInfo<GraphQLFieldsContainer> {
4040
val relType = relDirective.getArgument(DirectiveConstants.RELATION_NAME, "")!!
4141
val direction = relDirective.getArgument<String>(DirectiveConstants.RELATION_DIRECTION, null)
4242
?.let { RelationDirection.valueOf(it) }

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class SchemaBuilder(
131131
when (typeDefinition) {
132132
is ImplementingTypeDefinition -> typeDefinition.fieldDefinitions
133133
.flatMap { fieldDefinition -> fieldDefinition.inputValueDefinitions.map { it.type } + fieldDefinition.type }
134+
134135
is InputObjectTypeDefinition -> typeDefinition.inputValueDefinitions.map { it.type }
135136
else -> emptyList()
136137
}
@@ -141,6 +142,20 @@ class SchemaBuilder(
141142
.filterNot { typeDefinitionRegistry.hasType(it) }
142143
.mapNotNull { neo4jTypeDefinitionRegistry.getType(it).unwrap() }
143144
.forEach { typeDefinitionRegistry.add(it) }
145+
146+
147+
if (typeDefinitionRegistry.getType(mutationTypeName).isPresent) {
148+
typeDefinitionRegistry.schemaDefinition().ifPresent { schemaDefinition ->
149+
typeDefinitionRegistry.remove(schemaDefinition)
150+
typeDefinitionRegistry.add(schemaDefinition.transform {
151+
val ops = schemaDefinition.operationTypeDefinitions.toMutableList()
152+
if (ops.find { it.name == "mutation" } == null) {
153+
ops.add(OperationTypeDefinition("mutation", TypeName(mutationTypeName)))
154+
}
155+
it.operationTypeDefinitions(ops)
156+
})
157+
}
158+
}
144159
}
145160

146161
/**
@@ -282,7 +297,7 @@ class SchemaBuilder(
282297
override fun get(env: DataFetchingEnvironment): Any? {
283298
val source = env.getSource<Any>() ?: return null
284299
val propertyName = env.mergedField.singleField.alias ?: env.mergedField.singleField.name
285-
return PropertyDataFetcherHelper.getPropertyValue(propertyName, source, env.fieldType, env)
300+
return PropertyDataFetcherHelper.getPropertyValue(propertyName, source, env.fieldType, { env })
286301
}
287302
}
288303
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class BaseDataFetcher(schemaConfig: SchemaConfig) : ProjectionBase(sche
3434
.build()
3535
).render(statement)
3636

37-
val params = statement.parameters.mapValues { (_, value) ->
37+
val params = statement.catalog.parameters.mapValues { (_, value) ->
3838
(value as? VariableReference)?.let { env.variables[it.name] } ?: value
3939
}
4040
return Cypher(query, params, env.fieldDefinition.type, variable = field.aliasOrName())

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import graphql.language.ArrayValue
55
import graphql.schema.GraphQLFieldDefinition
66
import graphql.schema.GraphQLFieldsContainer
77
import graphql.schema.GraphQLType
8-
import org.neo4j.cypherdsl.core.*
8+
import org.neo4j.cypherdsl.core.Condition
99
import org.neo4j.cypherdsl.core.Cypher.*
10+
import org.neo4j.cypherdsl.core.Expression
11+
import org.neo4j.cypherdsl.core.PropertyContainer
1012
import org.neo4j.graphql.*
1113

1214
/**
@@ -96,19 +98,19 @@ abstract class BaseDataFetcherForContainer(schemaConfig: SchemaConfig) : BaseDat
9698
val (propContainer, func) = if (isRelation) {
9799
val variableName = name(variable)
98100
val rel = anyNode().relationshipTo(anyNode(), label).named(variableName)
99-
rel to Functions.id(rel)
101+
rel to elementId(rel)
100102
} else {
101103
val node = node(label).named(variable)
102-
node to Functions.id(node)
104+
node to elementId(node)
103105
}
104-
val where = func.isEqualTo(call("toInteger").withArgs(idParam).asFunction())
106+
val where = func.isEqualTo(idParam)
105107
propContainer to where
106108
} else {
107109
val node = node(label).named(variable)
108110
if (idProperty.value is ArrayValue) {
109111
node to node.property(idField.propertyName()).`in`(idParam)
110112
} else {
111-
node.withProperties(idField.propertyName(), idParam) to Conditions.noCondition()
113+
node.withProperties(idField.propertyName(), idParam) to noCondition()
112114
}
113115
}
114116
}

core/src/main/kotlin/org/neo4j/graphql/handler/filter/OptimizedFilterHandler.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ class OptimizedFilterHandler(val type: GraphQLFieldsContainer, schemaConfig: Sch
214214
private fun totalFilter(relationPredicate: RelationPredicate, relVariableName: String): Pair<SymbolicName, AliasedExpression> {
215215
val totalRel = relationPredicate.relationshipInfo.createRelation(currentNode(), relationPredicate.relNode)
216216
val totalVar = normalizeName(relVariableName, "Total")
217-
val total = Functions.size(totalRel).`as`(totalVar)
217+
val total = Cypher.size(totalRel).`as`(totalVar)
218218
return Cypher.name(totalVar) to total
219219
}
220220

221221
private fun countFilter(relVariable: Node, relVariableName: String): Pair<SymbolicName, AliasedExpression> {
222222
val countVar = normalizeName(relVariableName, "Count")
223-
val count = Functions.countDistinct(relVariable).`as`(countVar)
223+
val count = Cypher.countDistinct(relVariable).`as`(countVar)
224224
return Cypher.name(countVar) to count
225225
}
226226

0 commit comments

Comments
 (0)