Mutation for creating relationship


(Shreyansh Zazz) #1
export const typeDefs = `
type University {
  id: ID!
  level: Int
}
type Department {
  id: ID!
  name: String
  level: Int
  has: [Position] @relation(name: "HAS", direction: "OUT")
  childsof: [Department] @relation(name: "CHILD_OF", direction: "IN")
}
type Position {
  id: ID! 
  name: String
  level: Int
  type: String
}
type Query {
    universities(id: ID, level: Int, first: Int = 10, offset: Int = 0): [University]
    departments(id: ID, name: String, level: Int, first: Int = 10, offset: Int = 0): [Department]
    positions(id: ID, name: String, level: Int, type: String, first: Int = 10, offset: Int = 0): [Position]
}

Here's the schema of my application. I want my :Department node to have a relationship of 'CHILD_OF' i.e. in Cypher this is what I want - a1:Department -[:CHILD_OF]-> a2:Department but I' m unable to do so.
Can anyone tell me how it's done using neo4j-graphql-js

The graphQL generated a mutation based on the relationship given above. For the department's child of relationship it has created an addChildOf but the parameter it is giving is only one and it's of department.


(William Lyon) #3

You can add auto-generated mutations to your schema by calling augmentSchema, passing in your schema object. Here's an example: https://github.com/neo4j-graphql/neo4j-graphql-js/blob/master/example/apollo-server/movies-middleware.js#L18


(Shreyansh Zazz) #5

Hey William,
Sorry for late reply but the solution you're proposing is already been done.
You can take a look at the code @ https://github.com/thepiperpied/palm-tree