简体   繁体   中英

Is it possible to filter a collection based on a collection field on the content type in graphql & contentful

This might be impossible in graphql/contentful or introduce too much complexity but I'm trying to query a collection and filter on a collection field, something like the following...

query {
  eventCollection(
    where: {
      OR: [
        { categoryCollection: { key: "fashion" } }
      ]
    }
  ) {
  items {
    slug
  }
}

My back up plan is to query all the events and filter in the client but I thought it would be possible to do the above.

Contentful DevRel here.

Currently, that's not possible. But what you can do is flip the query around and filter on the categoryCollection and then use linkedFrom to request the items linking to it.

query {
  categoryCollection(where: {
    key: "fashion
  }) {
    items {
      title
      linkedFrom {
        eventCollection {
          items {
            slug
          }
        }
      }
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM