0
votes

I have the following GraphQL query; "categories" is a one-to-many relationship, each containing a name and a slug. I want to get all Articles with category slug of "derp". Any thoughts?

{
allContentfulArticle(
  sort: { order: DESC, fields: [createdAt] }
) {
  edges {
    node {
      title
      slug
      datePublished
      createdAt
      categories {
        name
        slug
      }
    }
  }
}

}

1

1 Answers

0
votes

Contentful DevRel here. 👋

I just prototyped your scenario and this query should do it.

query {
  categoryCollection(where: { slug_contains: "schnitzel" }) {
    items {
      linkedFrom {
        entryCollection {
          items {
            ...on Article {
              title 
            }
          }
        }
      }
    }
  }
}

You can find more info in the docs about links to a specific entry.

Hope that helps. :)