-1

In the database, there are shoes of sizes 41.0, or 41.5-42, 42-43, etc. I have them saved as:

41.0 -> shoes_min=41.0; shoes_max=41.0
41.5-42 -> shoes_min=41.5; shoes_max=42.0
42-43 -> shoes_min=42.0; shoes_max=43.0

My proposed filter to show up all of the above examples as a user might (on the frontend there would just be 2 input values of (41, 42) which indicates the range the user is interested in. It should match all of the above 3 examples, except in my case it is not matching entries with shoes_min=42; shoes_max=43

query MyQuery {
  models(
    where: {
      shoes_min: {_gte: "41"}
      _and: {
        shoes_min: {_lte: "42"}
      },
      _or: {
        shoes_max: {_gte: "41"}
        _and: {
          shoes_max: {_lte: "42"}
        },
      },
    },
    order_by: {shoes_max: asc}
  ) {
    shoes_min
    shoes_max
    name
    url
  }
}
dnk8n
  • 675
  • 8
  • 21

1 Answers1

0

Here is the correct request body:

query MyQuery {
  models(
    where: {
      _or: [
        {_and: [{shoes_min: {_gte: 41}}, {shoes_min: {_lte: 42}}]},
        {_and: [{shoes_max: {_gte: 41}}, {shoes_max: {_lte: 42}}]}
      ]
    },
    order_by: [{shoes_min: asc}, {shoes_max: asc}]
  ) {
    shoes_min
    shoes_max
    name
  }
}
dnk8n
  • 675
  • 8
  • 21
  • I didn't find that it was possible in the Hasura API explorer (GUI) but when I attempted a request body with something that made more sense to me, it actually worked. Apologies for question that ended up being nothing more than a syntax error. – dnk8n Sep 21 '21 at 15:04
  • Is it documented that the API explorer is not fully compatible with this structure, even though the syntax is accepted at a lower level? – dnk8n Sep 21 '21 at 15:06