Skip to content

Commit

Permalink
Use relationship alias for this in directive on rich relationship (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikwattro authored Oct 28, 2021
1 parent 3e65508 commit cbdacfe
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
----

0 comments on commit cbdacfe

Please sign in to comment.