GRAPHQL STRAPI turn full array of filters to be a variable

Viewed 177

I'm using strapi with graphql Here is my current query to get all of the filtered categories

 query GetRecommendedStuff(
    $answer1: String!
    $answer2: String!
    $answer3: String!
  ) {
    tools(
      filters: {
        and: [
          { categories: { category: { eq: $answer1 } } }
          { categories: { category: { eq: $answer2 } } }
          { categories: { category: { eq: $answer3 } } }
        ]
      }
    ) {
      data {
        attributes {
          toolname
          app_categories {
            data {
              attributes {
                category
              }
            }
          }
        }
      }
    }
  }

I want to turn it to something like this so the filters can be dynamic when querying the filtered data.

  query GetRecommendedStuff(
    $answers: [Objects]!
  ) {
    tools(
      filters: { and: $answers }
    ) {
      data {
        attributes {
          toolname
          app_categories {
            data {
              attributes {
                category
              }
            }
          }
        }
      }
    }
  }

is this possible?

1 Answers
query GetRecommendedStuff(
    $toolFilters: ToolFiltersInput
  ) {
    tools(
      filters: $toolFilters
    ) {
      data {
        attributes {
          toolname
          app_categories {
            data {
              attributes {
                category
              }
            }
          }
        }
      }
    }
  }

//pass variables as a whole
variables: {toolFilters: {
            and: [
              { categories: { category: { eq: "" } } }
              { categories: { category: { eq: "" } } }
              { categories: { category: { eq: "" } } }
            ]
          }}
Related