diff --git a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt index d6be430a..f8e480d5 100644 --- a/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt +++ b/core/src/main/kotlin/org/neo4j/graphql/handler/projection/ProjectionBase.kt @@ -261,7 +261,7 @@ open class ProjectionBase( val cypherDirective = fieldDefinition.cypherDirective() val isObjectField = fieldDefinition.type.inner() is GraphQLFieldsContainer if (cypherDirective != null) { - val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, propertyContainer.requiredSymbolicName) + val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, variable) projections += if (isObjectField && !cypherDirective.passThrough) { projectListComprehension(variable, field, fieldDefinition, env, query, variableSuffix) } else { diff --git a/core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc b/core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc new file mode 100644 index 00000000..4ea8344a --- /dev/null +++ b/core/src/test/resources/issues/gh-245-cypher-directive-on-relationship.adoc @@ -0,0 +1,64 @@ +:toc: + += Cypher Directive Computing Relationship Type To Field Test + +== Schema + +[source,graphql,schema=true] +---- +type Role @relation(name:"ACTED_IN", from:"actor", to:"movie") { + actor: Person + movie: Movie + type: String @cypher(statement:""" + RETURN type(this) + """) +} + +type Person { + name: String + born: Int + roles: [Role] +} + +type Movie { + title: String + released: Int + characters: [Role] +} + +---- + +== Queries + +=== Simple Cypher Directive on Field + +.GraphQL-Query +[source,graphql] +---- +query { + person { + roles { + type + } + } +} +---- + +.Cypher Params +[source,json] +---- +{} +---- + +.Cypher +[source,cypher] +---- +MATCH (person:Person) +RETURN person { + roles: [(person)-[personRoles:ACTED_IN]->(personRolesMovie:Movie) | personRoles { + type: apoc.cypher.runFirstColumnSingle('WITH $this AS this RETURN type(this)', { + this: personRoles + }) + }] +} AS person +----