0

I have the following situation in Hasura. A table with articles, a table with tags and one mapping table called articles_tags. What I'm trying to achieve is to get all the articles that have certain tags assigned to them. The query that comes to my mind is the following:

query SomeQuery {
   articles(where: {
    articles_tags: {
      _and: [
         tagId: { _eq: 1 },
         tagId: { _eq: 2 },
         ...
      ]
    }}) {
     id
   }
}

The problem with this query is that the number of items in the _and condition is hardcoded and the only way I can make it dynamic is by string operations, which as I know are marked as bad practise in GraphQl. So my question is do you know some way to pass an array of the tag ids instead of the hardcoded ones and to build the same Hasura condition? Also what are the best practises in this situation?

zhelyazko777
  • 17
  • 1
  • 5

1 Answers1

1

You could try passing the _and parameters as a variable, this may not be the exact syntax as I don't have your schema

query SomeQuery($_and: [articles_tags_bool_exp!]!) {
 articles(where: {
   articles_tags: { _and: $_and }
})
Arjun Yelamanchili
  • 577
  • 1
  • 3
  • 16
  • Yeah, but it acts like _or condition, if anything in the array matches the record it will give me the row. The behaviour I want is to act like _and operation and to check it the record matches all the conditions – zhelyazko777 Oct 12 '22 at 15:11
  • @zhelyazko777 I edited my answer, could you try it? – Arjun Yelamanchili Oct 12 '22 at 17:02