Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship mutations are not using the correct direction #98

Closed
ZikFat opened this issue Jul 30, 2020 · 3 comments · Fixed by #107
Closed

Relationship mutations are not using the correct direction #98

ZikFat opened this issue Jul 30, 2020 · 3 comments · Fixed by #107
Assignees

Comments

@ZikFat
Copy link

ZikFat commented Jul 30, 2020

I have a database with nodes like this:

graph

And a graphql schema like this:

type Team {
  id: ID!
  name: String!
  players: [Player!]! @relation(name: "MEMBER_OF", direction: IN)
}

type Player {
  id: ID!
  name: String!
  teams: [Team] @relation(name: "MEMBER_OF")
}

The cypher queries generated when I run the deleteTeamPlayers and addTeamPlayers mutations are specifying the relationship in the wrong direction.

Here's the cypher generated by deleteTeamPlayers:

RUN "MATCH (from:Team { id: $fromId }) MATCH (to:Player) WHERE to.id IN $toPlayers MATCH (from)-[r:MEMBER_OF]->(to) DELETE r WITH DISTINCT from AS deleteResult RETURN deleteResult { .name } AS deleteResult"

And here's addTeamPlayers:

RUN "MATCH (from:Team { id: $fromId }) MATCH (to:Player) WHERE to.id IN $toPlayers MERGE (from)-[:MEMBER_OF]->(to) WITH DISTINCT from AS addResult RETURN addResult { .name } AS addResult"

These queries are building MATCH and MERGE clauses going from Team to Player even though my graphQL schema and database have the relationships going from Player to Team. The result is that the deleteTeamPlayers mutation doesn't do anything since it can't find any relationships to match on, and the addTeamPlayers mutation adds a relationship in the opposite direction of what's desired.

The deletePlayerTeams and addPlayerTeams mutations that were generated from the Player type work fine. It seems like the problem is that these relationship mutations are always using an outbound direction.

@jexp
Copy link
Contributor

jexp commented Aug 5, 2020

Thanks for reporting that is an really unexpected bug.

@jexp
Copy link
Contributor

jexp commented Aug 5, 2020

But you are correct, we don't test it in the inverse direction and the arrow here is hardcoded @Andy2003

https://github.com/neo4j-graphql/neo4j-graphql-java/blob/master/src/main/kotlin/org/neo4j/graphql/handler/relation/DeleteRelationHandler.kt#L54

Probably the same for the MERGE / CREATE handler

Andy2003 added a commit to Andy2003/neo4j-graphql-java that referenced this issue Aug 7, 2020
…esolves neo4j-graphql#98)

This bugfix solves the problem that the mapping was wrong for incoming relations
@jexp jexp closed this as completed in #107 Aug 7, 2020
jexp pushed a commit that referenced this issue Aug 7, 2020
…esolves #98) (#107)

This bugfix solves the problem that the mapping was wrong for incoming relations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants