Mutation for creating relationship

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.

1 Like

You can add auto-generated mutations to your schema by calling augmentSchema, passing in your schema object. Here's an example: neo4j-graphql-js/movies-middleware.js at master · neo4j-graphql/neo4j-graphql-js · GitHub

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

https://github.com/thepiperpied/palm-tree/blob/b1d16ac52950a220bdfde60fd25b760a6f58e9d5/graphql-schema.js#L24
to be specific :smiley:

4 Likes