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

Disconnect Where Args Not Implementing Aliases #894

Closed
litewarp opened this issue Jan 30, 2022 · 3 comments · Fixed by #907
Closed

Disconnect Where Args Not Implementing Aliases #894

litewarp opened this issue Jan 30, 2022 · 3 comments · Fixed by #907
Assignees
Labels
bug Something isn't working confirmed Confirmed bug high priority

Comments

@litewarp
Copy link
Contributor

litewarp commented Jan 30, 2022

Found a bug while working on the global node resolution.

If you try and disconnect a relationship based on an aliased field, the translate function doesn't implement the alias.

I think the issue boils down to the fact that the the mapDbToProperty function is not called when resolving a disconnect field. The where filter on a disconnect is ultimately resolved by the createRelationshipWhereAndParams or createNodeWhereAndParams functions, neither of which uses mapDbToProperty, whereas the translation function for connect where args createWhereAndParams does.

Type definitions

  type User {
    id: ID! @id @alias(property: "_id")
    name: String!
    activeOrganization: Organization @relationship(type: "ACTIVELY_MANAGING", direction: OUT) 
  }

  type Organization {
    id: ID! @id @alias(property: "_id")
    name: String!
   }

To Reproduce
Steps to reproduce the behavior:

Try to create a mutation where you connect a relationship by id, and disconnect all previous relationships that don't have that id.

  1. First create nodes and relationship

Mutation

mutation CreateUser($input: [UserCreateInput!]) {
  createUsers(input: $input) {
    users {
      id
    }
  }
}

Arguments

const input = [
  {
    name: "Luke Skywalker",
    activeOrganization: {
      create: { 
        node: { 
          name: "Rebel Alliance"
        }
     }
  }
]
  1. Then create a second organization
    Mutation
mutation CreateOrg($input: [OrganizationCreateInput!] {
  createOrganizations(input: $input) {
     organizations {
       id
     }
  }
}

Arguments

const input = [
  { 
    name: "The Empire"
   }
]
  1. Then update the relationship so Luke joins the dark side and leaves the rebels.
    Mutation
mutation SwapSides($where: UserWhere!, $connect: UserConnectInput, $disconnect: UserDisconnectInput) {
  updateUsers(where: $where, connect: $connect, disconnect: $disconnect) {
    users {
      id
     }
  }
}

Arguments

const selectedId = "" // Id Returned for "The Empire"
const input = {
  where: { name: "Luke Skywalker" },
  connect: {
    activeOrganization: {
      where: { node: { id: selectedId } },
    },
  },
  disconnect: {
    activeOrganization: {
      where: { node: { id_NOT: selectedId } },
    },
  },
}

Expected behavior
The mutation should connect Luke to the Empire and Disconnect him from the Rebels. But if you run the following cypher in the Neo4J browser, you'll see that he is actively managing both.

MATCH (u:User {name: "Luke Skywalker"})-[r:ACTIVELY_MANAGING]->(o:Organization)
RETURN u, r, o

Screenshots

This is a similar call for the schema I'm working with. Notice that the property connect uses for the equality check is _id while the one used for disconnect is the non-aliased field id

Screen Shot 2022-01-30 at 12 56 45 AM

@litewarp litewarp added the bug Something isn't working label Jan 30, 2022
@neo4j-team-graphql
Copy link
Collaborator

Many thanks for raising this bug report @litewarp. 🐛 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 the confirmed Confirmed bug label Jan 31, 2022
@neo4j-team-graphql
Copy link
Collaborator

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

@neo4j-team-graphql
Copy link
Collaborator

This bug report has been assigned high priority to fix. If you wish to contribute a fix, please branch from master and submit your PR with the base set to master. Thanks!

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

Successfully merging a pull request may close this issue.

4 participants