1

I am getting started with Strapi and have setup a basic model in the Strapi admin called page which looks like so:

page: {
  title: Text (required)
  slug: Text (required and unique)
}

As you can see it has a field called slug which is always unique. What I am wondering is how I can query by this field?

So far I have added 1 entry and when I launch graphql playground (at http://localhost:1337/graphql) I can get my entry returned via the following query:

query {
  page(id:"1") {
    title
  }
}

When I try to query via slug as opposed to id like so:

query {
  page(slug:"/") {
    title
  }
}

I am unable to do so even though it's a unique field. It does not even come up with the suggestions to use slug as a unique idetifier input inside the brackets. Why would this be?

9
  • If I read this correctly, you have to do something like page(where: { slug_contains: "/" }) Commented Jun 3, 2021 at 12:36
  • Strangely tha works for the pages type that queries many but trying to use where on the page type does not come up as an option Commented Jun 3, 2021 at 13:04
  • So trying as I suggested works, but the recommendation-feature / autocomplete does not work? If so, then the problem is most likely in the editor and not in your code Commented Jun 3, 2021 at 13:09
  • No I am not referring to the recommendation feature, adding the where object when dealing with single instances like user or page as opposed to users or pages does not work. Commented Jun 3, 2021 at 13:11
  • Your recommendation did not work until I changed page to pages Commented Jun 3, 2021 at 13:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.