In cipher it's like : MATCH (a:Department{id: id}, b:Department{id: id}) CREATE a-[:CHILD]->b RETURN a, b
The auto generated mutation through /* augmentSchema will add autogenerated mutations based on types in schema */ const augmentedSchema = augmentSchema(schema); doesn't create what I need.
It's only providing me with a mutation i.e. AddDepartmentChildren( departmentid: ID! ): Department
Where should I put the parameters that I want in return if the relationship is successfully created and where should I define the properties for the relation CHILD_DEPT?
Oh right, that mutation should return a Department node and I forgot the return clause. Our convention for the generated mutations has been to return the from node. So the query should be
MATCH (from:Department {id: $fromDepartmentID})
MATCH (to:Department {id: $toDepartmentID})
CREATE (from)-[:CHILD_DEPT]->(to)
RETURN from
To add properties to the relationship just include them as parameters of the mutation and update the @cypher query accordingly. Here's an example:
type Mutation {
AddDepartmentChildren(fromDepartmentID: ID!, toDepartmentID: ID!, count: Int): Department @cypher(
statement:"""
MATCH (from:Department {id: $fromDepartmentID})
MATCH (to:Department {id: $toDepartmentID})
CREATE (from)-[r:CHILD_DEPT]->(to)
SET r.count = $count
RETURN from
""")
Note that the neo4j-graphql-js library (and the neo4j-graphql database plugin) do not currently support an automatic way of working with relationship properties so you'll have to define @cypher directives on fields to work with relationship properties.