neo4j-graphql / neo4j-graphql-java

Neo4j Labs Project: Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question re deleting relationships

michael-forman opened this issue · comments

commented

I have a simplified schema of:

type User
{
  name: String!
  uuid: ID!
  associates: [User!] @relation(name:"ASSOCIATES_WITH",direction:BOTH)
}

specifically the direction is BOTH, meaning I'm attempting a "symmetrical" relationship.

This is working fine in so much as when I create a graph like:

Users

the query like query { user(uuid: $uuid) { uuid, name, associates { name uuid } } } for the uuid for "Fred" will return both "Pete" and "Harry", which are out and in links respectively.

The mutation for deleting deletePersonAssociates is still "directional", in that it takes the ID (uuid in my case) of the "from" side of a link, and the list of IDs of associates to delete. In order to use this I must know the direction still. ie from the ID (uuid) of "Fred" in my graph I can not delete the link to "Harry". In order to delete the link between Fred and Harry I need to do deletePersonAssociates using the ID of the "from" side, so Harry to Fred.

Not sure if this is deliberate, but it means that my "application" layer still needs to understand the directionality of the links.

Have I missed something here?

Cheers,

Michael

The generated Cypher for your issue is correct:

Schema

type User
{
  name: String!
  uuid: ID!
  associates: [User!] @relation(name:"ASSOCIATES_WITH", direction:BOTH)
}

Data:

CREATE
    (pete:User{ name: 'Pete', uuid: '1' }),
    (fred:User{ name: 'Fred', uuid: '2' }),
    (harry:User{ name: 'Harry', uuid: '3' }),
    (pete)<-[:ASSOCIATES_WITH]-(fred),
    (fred)<-[:ASSOCIATES_WITH]-(harry)

Mutation

mutation {
  deleteUserAssociates(uuid: "2", associates: ["1", "3"]) {
    name
    associates { name uuid }
  }
}

Generated Cypher:

MATCH (from: User { uuid: $fromUuid })
MATCH (to: User) WHERE to.uuid IN $toAssociates
MATCH (from)-[r: ASSOCIATES_WITH]-(to)
DELETE r
WITH DISTINCT from AS deleteUserAssociates
RETURN deleteUserAssociates {
    .name,
    associates: [(deleteUserAssociates)-[: ASSOCIATES_WITH]-(deleteUserAssociatesAssociates: User) | deleteUserAssociatesAssociates {
        .name,
        .uuid
    }]
} AS deleteUserAssociates

I guess it was fixed by #107 (#98)