0

(From Strapi) I am trying to get all "acts" with a certain age (can return multiple) and with a certain place (can return multiple). I can't figure out how to filter that. This is what I am trying in GraphQL-playground (works without the variables), but it says "Unknown argument "age" on field "Act.ages"." (and "place" respectively).

query GetActs ($age:Int, $place:String) {
  acts {
    data {
      id
      attributes {
        Title
        ages (age: $age) {
          data {
            id
            attributes {
              age
            }
          }
        }
        places (place: $place) {
          data {
            id
            attributes {
              place
            }
          }
        }
      }
    }
  }
}

1 Answer 1

2

I just ran into this same issue. I can't make out the error you're reporting, but here is what worked for me.

You can use filter at the collection level to drill down to nested fields for the corresponding attributes. This follows the GraphQL example at the bottom of this Strapi resource on filtering nested fields.

Solution

query GetActs ($age:Int, $place:String) {
  acts (filters: {ages: {age: {eq: $age}}, places: {place: {eq: $place}}}) {
    data {
      id
      attributes {
        Title
        ages {
          data {
            id
            attributes {
              age
            }
          }
        }
        places {
          data {
            id
            attributes {
              place
            }
          }
        }
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.