cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Removing a self referencing relationship

iuviene
Node Link

I'm a little new to GrandStack/neo4j-graphql and I've been having trouble figuring out a reasonable way to remove relationships when they are self referencing and in practice meant to be bidirectional (e.g. a friends relationship)

The issue I'm facing is that when removing a FRIENDS relationship between PersonA and PersonB, I need to know the underlying direction of how that relationship was initially added. Running a regular GraphQL query of:

`query Person {
    name
    friends {
       name
   }
}
`

won't give me any indication of that direction. Without that detail, I don't know which Person should be in the to position and which the from position in the Remove mutation. Is there a simple solution to this pattern? Am I missing something obvious?

Any suggestions would be much appreciated.

3 REPLIES 3

MuddyBootsCode
Graph Steward

How do you have your GraphQL Schema set up? You get to decide the direction of the relationship. So something like:

type Person {
friends: [Person] @relation (name: "friend", direction: "out")
}

Something of that nature. You can make it in or out. That gives you an easy way to determine what you're getting back.

I had the relationship set as "BOTH". This works on the query side of things, i.e. you get all friends of the Person regardless of which Person initiated the relationship, but the Remove mutation seems to be direction specific.

MuddyBootsCode
Graph Steward

Have you checked out your mutations in the Graphiql interface? It should have a remove friendship mutation and it almost certainly has a to and from id that you pass. So that no matter what the direction you're specifying the direction you're trying to remove.