Search code examples
reactjsmongodbgraphqlnext.jsstrapi

How to use "where" argument in a query using graphql and mongodb?


I need a query that looks for specific data, and I created the following query:

query GET_RELATORIOS_SLUGW($slug: JSON ) {
  relatorios(where: {slug: $slug}){
     id
    title
    slug
  }
}

step by variable:

{
  "$slug": "agua"
}

but it keeps returning all the data and not just what I'm looking for, I would like some help, to know how to make this query work?


Solution

  • Slug looks like a string, and your variable syntax wasn't correct.

    query GET_RELATORIOS_SLUGW($slug: String) {
      relatorios(where: { slug: $slug }) {
        id
        title
        slug
      }
    }
    

    Variables:

    {
      "slug": "agua"
    }