GraphQL arguments on sub-fields

Viewed 1301

Is it possible in GraphQL to filter results based on subfields arguments? For example:

{
 allNews(id: 999) {
    id
    startDate
    endDate
    newsText(title: "hello", message: "testMessage") {
        length
        disitrubutionDate
    }
 }
}

I built the following schema:

type news {
  id: Int
  startDate: String
  endDate: String
  newsText: [newsText]
}

type newsText {
  message: String
  title: String
  length: Int
  distributionDate: String
}
type Query {
  allNews(id: Int, startDate: String, endDate: String): [news]
  allNewsTexts(message: String, title: String): [newsText]
}

If I change the type news to:

type news {
  id: Int
  startDate: String
  endDate: String
  allNewsTexts(message: String, title: String): [newsText]
}

the data fetcher linked to the allNewsTexts query it's not invoked so the output will be:

"allNews": [
        {
            "id": 999,
            "startDate": "2020-02-27",
            "endDate": "2020-02-28",
            "allNewsTexts": null
        }
    ]

My java data fetcher simply return the repository.findAll() filtered by id, startDate, endDate

0 Answers
Related