graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Disconnect for undirected relationships doesn't work from both sides

Open AccsoSG opened this issue 2 years ago • 6 comments

Describe the bug Disconnecting undirected relationships only works from one side

Type definitions

type Item {
  name: String
  relatesTo: [Item!]! @relationship(type: "RELATES_TO", direction: OUT, queryDirection: DEFAULT_UNDIRECTED)
}

To Reproduce Steps to reproduce the behavior:

  1. Run a server with the following code...
  2. Execute the following Mutation...
mutation {
  createItems(input: {
    name: "A",
    relatesTo: {
      create: {
        node: {
          name: "B"
        }
      }
    }
  }) {
    items {
      name
      relatesTo {
        name
      }
    }
  }
}
  1. Then run the following Query... The relationship was created successfully. It is possible to query the relationship from both sides.
query {
  items {
    name
    relatesTo {
      name
      relatesTo {
        name
      }
    }
  }
}

Result:

{
  "data": {
    "items": [
      {
        "name": "A",
        "relatesTo": [
          {
            "name": "B",
            "relatesTo": [
              {
                "name": "A"
              }
            ]
          }
        ]
      },
      {
        "name": "B",
        "relatesTo": [
          {
            "name": "A",
            "relatesTo": [
              {
                "name": "B"
              }
            ]
          }
        ]
      }
    ]
  }
}
  1. Run the following mutations: (1) Works fine: The relationship has been deleted
mutation {
  updateItems(
    where: {
  		name: "A",
    },
    disconnect: {
      relatesTo: {
        where: {
          node: {
            name: "B"
          }
        }
      }
    }
  ) {
    items {
      name
      relatesTo {
        name
        relatesTo {
          name
        }
      }
    }
  }
}

(2) Doesn't work: The relationship persists after the mutation. Nothing has happened.

mutation {
  updateItems(
    where: {
  		name: "B",
    },
    disconnect: {
      relatesTo: {
        where: {
          node: {
            name: "A"
          }
        }
      }
    }
  ) {
    items {
      name
      relatesTo {
        name
        relatesTo {
          name
        }
      }
    }
  }
}

Expected behavior As with the query, a mutation should also work in both directions if the DEFAULT_UNDIRECTED or UNDIRECTED_ONLY option is activated.

AccsoSG avatar Sep 06 '22 14:09 AccsoSG

Many thanks for raising this bug report @AccsoSG. :bug: 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! :pray:

neo4j-team-graphql avatar Sep 06 '22 14:09 neo4j-team-graphql

Hi, @AccsoSG, At this moment we do not provide a way to disconnect in an undirected way. Could be counter-intuitive but the argument queryDirection is used only to evaluate the Selection Set. Although, it's possible that in the future this behavior could be included.

MacondoExpress avatar Sep 07 '22 15:09 MacondoExpress

Hi @MacondoExpress, Thanks for the answer

Is there currently a workaround to do this in a single mutation?

AccsoSG avatar Sep 07 '22 21:09 AccsoSG

As far as I'm aware, I believe not, unfortunately!

MacondoExpress avatar Sep 08 '22 09:09 MacondoExpress

@MacondoExpress I've noticed that the queryDirection value is not used in the where clause as well. This to me is pretty misleading as the direction specified in the property is retained in the where clause, but not in the selection set. Is this behavior also known?

jrsperry avatar Jan 03 '23 16:01 jrsperry

@jrsperry Yes, is the expected behavior.

MacondoExpress avatar Jan 05 '23 11:01 MacondoExpress