0

I am new to GraphQL and I've been trying to come up with a simple query but I'm not getting the results I need.

Basically, I am writing a mutation to delete a row when the following conditions are met:

(A = a AND B = b) OR (A = b AND B = a)

However, I can't seem to figure out how to write it.

I tried doing something like:

delete_links(where: {_or: {_and: {a: {_eq: a}, b: {_eq: b}}}, {_and: {a: {_eq: b}, b: {_eq: a}}}) {
affected_rows
  }
}

I am using Hasura on postgresql.

Basically I have a table called Links storing:

link_a | link_b

The problem is a link between item 9 and 2 in link can either be:

link_a | link_b
2      | 9

or

link_a | link_b
9      | 2

Hence I want my delete mutation to delete BOTH cases. However I cant seem to do a query (A = a AND B = b) OR (A = b AND B = a)

Jack
  • 1
  • 1
  • 1
    The query is very specific, its totally related to your schema on server. Give us more info might help (for example, server schema, type and related types of where, your technology that you use on Backend also helps) – Long Nguyen Duc Oct 09 '21 at 11:04
  • @LongNguyen Hi, I have added more information. Thanks for pointing that out. – Jack Oct 09 '21 at 11:10

1 Answers1

1

Since _or, _and is array. So, your mutation should look like this:

# in this example: typeof A = Int, typeof B = Int
mutation delete_links($a: Int, $b: Int) {
  delete_links(
    where: {
      _or: [
        { A: { _eq: $a }, B: { _eq: $b } }
        { A: { _eq: $b }, B: { _eq: $a } }
      ]
    }
  ) {
    affected_rows
  }
}

# if you'd like to use additional _and
mutation delete_links($a: Int, $b: Int) {
  delete_links(
    where: {
      _or: [
        { _and: [{ A: { _eq: $a } }, { B: { _eq: $b } }] }
        { _and: [{ A: { _eq: $b } }, { B: { _eq: $a } }] }
      ]
    }
  ) {
    affected_rows
  }
}

Long Nguyen Duc
  • 1,317
  • 1
  • 8
  • 13