Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
05-12-2021 06:01 PM
How do I write a server schema that will return two nodes and the relationship between them in my client?
I have a tree hierarchy made up of only two types.
# a node
type Node {
ID: ID!
name: String
}
# the relationship between two Node
type Branch @relation (name: "CHILD_OF_NODE"){
to:[Node]
from:[Node]
ID: ID
index: Int
}
I want to somehow end up with query that returns a Tree type made up of Nodes and Branch types.
# two Node and the relationship between them
type Tree {
parent:[Node]
branch:[Branch]
child:[Node]
}
I have some simple cypher that returns every branch of the tree but this won't work because it returns two types. The docs say cypher can only return one type.
tree(root: String):[Tree]
@cypher(statement:"""
MATCH path = (r:Node{name:$root})<-[b:CHILD_OF_NODE*1..]-(c:Node)
with nodes(path)[-2] as parent, last(b) as branch, c as child
RETURN parent, child, branch
""")
The docs also show how to add a field to a node type and return a list of matching nodes by using "this". In my case I need a return a single node and relationship. I can't see how "this" can help me achieve that.
type Movie {
movieId: ID!
similarMovies: [Movie] @cypher(statement: """
MATCH (this)<-[:ACTED_IN]-(:Actor)-[:ACTED_IN]->(rec:Movie)
WITH rec, COUNT(*) AS score ORDER BY score DESC
RETURN rec LIMIT $limit
""")
}
After months of struggling with this I'm thinking I may be taking a completly wrong approach. Any suggestions will be appreciated.
All the sessions of the conference are now available online