Search code examples
graphqlstrapi

Using slug as a filter with Graphql and Strapi V4


Trying to use slug as an uuid to fetch single pages from a strapi backend v4. my query to get pages works well. It's just I can't filter using slug:

my pages query:

  query {
   pages {
    data {
      attributes {
            Name
            slug
      }
    }
 }
}

how to get single page using slug uuid within this schema ? every trails to implement ($slug: String!) fails as where to locate slug.


Solution

  • You can use filters. Just pass slug as argument and use the 'eq' keyword for comparison which stands for equals.

    query pages($slug:String) {
        pages(filters:{slug:{eq:$slug}}) {
            data {
                attributes {
                    Name
                    slug
                }
            }
        }
    }