Skip to content

Relationship mutations are not using the correct direction #98

Closed
@ZikFat

Description

@ZikFat

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions