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

The connection to a to-1 union does not check whether only one node is actually connected. #4424

Open
AccsoSG opened this issue Dec 18, 2023 · 3 comments
Labels
bug report Something isn't working confirmed Confirmed bug
Projects

Comments

@AccsoSG
Copy link

AccsoSG commented Dec 18, 2023

Describe the bug
With a To-1 relationship to a union, the library does not check whether only one node is actually connected.

Type definitions

type Movie {
  name: String!
  publicationEvent: [PublicationEvent!]! @relationship(type: "HAS_PUBLICATION_EVENT", direction: OUT, nestedOperations: [CONNECT, DISCONNECT])
}

type Episode {
  name: String!
  publicationEvent: [PublicationEvent!]! @relationship(type: "HAS_PUBLICATION_EVENT", direction: OUT, nestedOperations: [CONNECT, DISCONNECT])
}

union MovieOrEpisode = Movie | Episode

type PublicationEvent {
  name: String!
  product: MovieOrEpisode! @relationship(type: "HAS_PUBLICATION_EVENT", direction: IN, nestedOperations: [CONNECT, DISCONNECT])
}

To Reproduce
Steps to reproduce the behavior:

  1. Run a server with the following code...
  2. Execute the following Mutation...
    (1) Create movies and episodes
mutation CreateMoviesAndEpisodes {
  createMovies(input: [
    {
      name: "TestMovie1"
    },
    {
      name: "TestMovie2"
    }
  ]) {
    movies {
      name
    }
  }

  createEpisodes(input: [
    {
      name: "TestEpisode1"
    },
    {
      name: "TestEpisode2"
    }
  ]){
    episodes {
      name
    }
  }
}

(2) Create PublicationEvent-Object
No filter is specified here for the connection (it has been forgotten). The mutation works anyway. Both movie nodes are connected.

mutation CreatePublicationEvent {
  createPublicationEvents(input: {
    name: "TestPubEvent1",
    product: {
      Movie: {
        connect: {
          where: {
            node: {}
          }
        }
      }
    }
  }){
    publicationEvents {
      name
    }
  }
}
  1. Then run the following Query...
    However, only one movie node is returned. It appears undeterministic.
query GetPublicationEvents {
  publicationEvents {
    name
    product {
      ... on Movie {
        name
      }
      ... on Episode {
        name
      }
    }
  }
}
{
  "data": {
    "publicationEvents": [
      {
        "name": "TestPubEvent1",
        "product": {
          "name": "TestMovie2"
        }
      }
    ]
  }
}

Expected behavior
When executing the second mutation, the following error message should be returned: PublicationEvent.product required exactly once

Screenshots
image

System (please complete the following information):

  • OS: [e.g. macOS, Windows]
  • Version: @neo4j/graphql@4.4.1
  • Node.js version: [e.g. 14.16.0]

Additional context
Add any other context about the problem here.

@AccsoSG AccsoSG added the bug report Something isn't working label Dec 18, 2023
@neo4j-team-graphql
Copy link
Collaborator

Many thanks for raising this bug report @AccsoSG. 🐛 We will now attempt to reproduce the bug based on the steps you have provided.

Please ensure that you've provided the necessary information for a minimal reproduction, including but not limited to:

  • Type definitions
  • Resolvers
  • Query and/or Mutation (or multiple) needed to reproduce

If you have a support agreement with Neo4j, please link this GitHub issue to a new or existing Zendesk ticket.

Thanks again! 🙏

@neo4j-team-graphql neo4j-team-graphql added this to Bug reports in Bug Triage Dec 18, 2023
@a-alle a-alle added the confirmed Confirmed bug label Dec 19, 2023
@neo4j-team-graphql
Copy link
Collaborator

We've been able to confirm this bug using the steps to reproduce that you provided - many thanks @AccsoSG! 🙏 We will now prioritise the bug and address it appropriately.

@neo4j-team-graphql neo4j-team-graphql moved this from Bug reports to Confirmed in Bug Triage Dec 19, 2023
@darrellwarde
Copy link
Contributor

Hey @AccsoSG, I'm honestly unsure whether we ever implemented cardinality checks for union relationships, it's something we need to go away and look at. But this could be a feature request as opposed to a bug in that sense. Thanks, happy holidays!

@darrellwarde darrellwarde moved this from Confirmed to Low priority in Bug Triage Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Something isn't working confirmed Confirmed bug
Projects
Bug Triage
Low priority
Development

No branches or pull requests

4 participants