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

Impossible to create/connect a node while deleting some relationships in the same mutation #440

Closed
mathix420 opened this issue Aug 19, 2021 · 5 comments · Fixed by #537
Closed
Labels
bug Something isn't working

Comments

@mathix420
Copy link
Contributor

Hi neo team, hope y'all doing well!
I just ran into a bug trying to disconnect more than 1 node while creating and connecting another node at the same time.

With the following context I got this error message:

Neo4jError: Node(37) already exists with label `Category` and property `id` = 'category-55'

Code: Neo.ClientError.Schema.ConstraintValidationFailed

The thing is that (:Category { id: "category-55" }) do not exist.
Also, everything goes right if there is no more than one node disconnected while at least a node is created.
If no nodes are created, everything is working fine, even with multiple disconnected nodes per query.

Type definitions:

type Video @exclude(operations: [CREATE, DELETE]) {
    id: ID! @id
    // ...
    categories: [Category!]! @relationship(type: "IS_CATEGORIZED_AS", direction: OUT)
}
extend type Video @auth(rules: [
    {
        where: { OR: [{ publisher: { id: "$jwt.sub" } }, { processing: "published" }] }
        allowUnauthenticated: true
    }
    { operations: [UPDATE], allow: { publisher: { id: "$jwt.sub" } } }
])

type Category @exclude(operations: [UPDATE, DELETE]) {
    id: ID! @id(autogenerate: false)
    name: String!
    hidden: Boolean @default(value: true) @coalesce(value: false)
    thumbnail: String
    videos: [Video!]! @relationship(type: "IS_CATEGORIZED_AS", direction: IN)
    creationDate: DateTime! @timestamp(operations: [CREATE])
}
extend type Category @auth(rules: [{ operations: [CREATE], bind: { hidden: true } }])

To Reproduce
Steps to reproduce the behavior:

Mutation:

mutation updateVideo($id: ID!, $fields: VideoUpdateInput!) {
    video: updateVideos(where: {id: $id}, update: $fields) {
        videos {
            id
            categories {
                id
                name
            }
        }
    }
}

Variables used to mutate:

{
  "id": "60f2bd37-bdcc-46c3-aac3-8bdbbe360b9f",
  "fields": {
    "categories": [
      {
        "disconnect": [
          {
            "where": {
              "node": {
                "id_IN": [
                  "category-1",
                  "category-2"
                ]
              }
            }
          }
        ],
        "create": [
          {
            "node": {
              "id": "category-55",
              "name": "New category 55",
              "hidden": true
            }
          }
        ]
      }
    ]
  }
}

Expected behavior

  • category-55 should have been created as well as the relation between the video
  • category-1 and category-2 relation should be deleted

System (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS 5.4.0-80-generic
  • Version: @neo4j/graphql@2.0.1 @neo4j/graphql-ogm@2.0.1 neo4j-driver@4.3.2
  • Node.js version: v12.22.3 ts-node-dev ver. 1.1.8 (using ts-node ver. 9.1.1, typescript ver. 3.9.10)
  • Using Neo4j Aura

Additionnal infos
There are no changes in the CQL query - apart from the variables - between a mutation with one deleted relationship and a mutation with many deleted relationships.

@mathix420 mathix420 added bug Something isn't working inbox labels Aug 19, 2021
@darrellwarde
Copy link
Contributor

Hey @mathix420! This sounds like it could be similar to #235, where the multiple disconnects are essentially branching off into two, meaning that the create operation is duplicated. Will likely be addressed by also wrapping disconnects in a subquery as we did for the other issue. Thanks for the report, we'll take a look. 🙂

@mathix420
Copy link
Contributor Author

Hey @darrellwarde, thanks for your fast reply! I will have a look at this today, I can probably work on this PR. 🙂

@darrellwarde
Copy link
Contributor

Sure thing, if you like, always appreciated! 🙂

@darrellwarde
Copy link
Contributor

Hey @mathix420, just been taking a short look at this - it looks like delete operations also need wrapping in a subquery like this as well. Please feel free to take this on at the same time, it would be much appreciated, but of course we'll pick it up if you don't have time! 🙂

A lot of TCK test changes for these kinds of fixes, our apologies for that. 😞

@mathix420
Copy link
Contributor Author

Hey @mathix420, just been taking a short look at this - it looks like delete operations also need wrapping in a subquery like this as well. Please feel free to take this on at the same time, it would be much appreciated, but of course we'll pick it up if you don't have time!

A lot of TCK test changes for these kinds of fixes, our apologies for that.

No problem, I will have a look to this as well. 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants