4

For the blog I'm working on I have a category page that lists all blogposts that are tagged with that category. Now I want to order those blogs by the createdAt date but I can't seem to find a solution how to order a linked collection with the Contentful GraphQL API.

The query currently looks like this:

query {
  categoryCollection(limit: 1, where: {slug: "aws"}) {
    items {
      linkedFrom {
        postCollection(limit: 6, skip: 0) {
          total
          items {
            title
            content
            createdAt
          }
        }
      }
    }
  }
}

I can use the order parameter for the categoryCollection but not for the postCollection. Is there anything I'm missing with the GraphQL API or do I need to change my content model in Contentful to make this work?

Lingertje
  • 216
  • 3
  • 10
  • if `postCollection` accepts some `orderBy` arg - check [API] docs, use playground (docs inside) !!! – xadm May 05 '21 at 09:12
  • @xadm That's the problem. `postCollection` only accepts an order arg if it's the top level of the query not when it is `linkedFrom`. – Lingertje May 05 '21 at 09:17
  • then simply not supported now (IDK, maybe with some model change) ... sort after fetching, inside react component ` or sort before passing/rendering – xadm May 05 '21 at 10:06

0 Answers0