Trouble with 'where' on nested fields in graphql

Viewed 769

I'm pretty new to Strapi,React and Graphql; so still learning...

I've got the following GraphQL query:

query {
  specification(id: "5eb170c556d84a7b6e8e6456") {
    id
    Collaborators{
      id
      Acronym
        collaboratorType
      collaboratorName
      ProfessionalRecognition
    }
  }
}

This is working, but I'd like to be able to filter the results of Collaborators based on the value of ProfessionalRecognition (which is a boolean). However, no matter how I try to construct a where statement, it simply returns errors.

Can someone give me some assistance in defining the query that return only those Collaborators where ProfessionalRecognition is 'true'?

Many thanks

2 Answers

Try below graphql query

query {
  specifications(where:{
  id:"5eb170c556d84a7b6e8e6456",
  Collaborators:{
    ProfessionalRecognition:true
  }
  }) {
    id
    Collaborators{
      id
      Acronym
        collaboratorType
      collaboratorName
      ProfessionalRecognition
    }
  }
}

For more information on nested filtering , Please refer to the blog article Perform nested filtering with graphql queries in strapi

It depends on how ProfessionalRecognition is defined. I'd need to see the type definition.

Try something like this:

query {
  specification(id: "5eb170c556d84a7b6e8e6456") {
    id
    Collaborators(where: {ProfessionalRecognition: true}){
      id
      Acronym
        collaboratorType
      collaboratorName
      ProfessionalRecognition
    }
  }
}

But if it's nested, it could be something like this:

query {
  specification(id: "5eb170c556d84a7b6e8e6456") {
    id
    Collaborators(where: {ProfessionalRecognition: {someField: true} }){
      id
      Acronym
        collaboratorType
      collaboratorName
      ProfessionalRecognition
    }
  }
}
Related