Skip to content

Commit cbdacfe

Browse files
authored
Use relationship alias for this in directive on rich relationship (#246)
1 parent 3e65508 commit cbdacfe

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ open class ProjectionBase(
261261
val cypherDirective = fieldDefinition.cypherDirective()
262262
val isObjectField = fieldDefinition.type.inner() is GraphQLFieldsContainer
263263
if (cypherDirective != null) {
264-
val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, propertyContainer.requiredSymbolicName)
264+
val query = cypherDirective(field.contextualize(variable), fieldDefinition, field, cypherDirective, variable)
265265
projections += if (isObjectField && !cypherDirective.passThrough) {
266266
projectListComprehension(variable, field, fieldDefinition, env, query, variableSuffix)
267267
} else {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
:toc:
2+
3+
= Cypher Directive Computing Relationship Type To Field Test
4+
5+
== Schema
6+
7+
[source,graphql,schema=true]
8+
----
9+
type Role @relation(name:"ACTED_IN", from:"actor", to:"movie") {
10+
actor: Person
11+
movie: Movie
12+
type: String @cypher(statement:"""
13+
RETURN type(this)
14+
""")
15+
}
16+
17+
type Person {
18+
name: String
19+
born: Int
20+
roles: [Role]
21+
}
22+
23+
type Movie {
24+
title: String
25+
released: Int
26+
characters: [Role]
27+
}
28+
29+
----
30+
31+
== Queries
32+
33+
=== Simple Cypher Directive on Field
34+
35+
.GraphQL-Query
36+
[source,graphql]
37+
----
38+
query {
39+
person {
40+
roles {
41+
type
42+
}
43+
}
44+
}
45+
----
46+
47+
.Cypher Params
48+
[source,json]
49+
----
50+
{}
51+
----
52+
53+
.Cypher
54+
[source,cypher]
55+
----
56+
MATCH (person:Person)
57+
RETURN person {
58+
roles: [(person)-[personRoles:ACTED_IN]->(personRolesMovie:Movie) | personRoles {
59+
type: apoc.cypher.runFirstColumnSingle('WITH $this AS this RETURN type(this)', {
60+
this: personRoles
61+
})
62+
}]
63+
} AS person
64+
----

0 commit comments

Comments
 (0)