GraphQL query filter not working

Solved

GraphQL query filter not working

maartenvdh
Visitor
2 0 1

I am probably missing something simple but I cannot find what.

When I run this GraphQL query in the Shopify GraphiQL App it comes back with 10 products:

{
  shop {
    name
  }
  products(first: 10) {
    edges {
      node {
        id
        title
        description
      }
    }
  }
}

 

When I add a query filter like this:

{
  shop {
    name
  }
  products(first: 10, query: "title=bike") {
    edges {
      node {
        id
        title
        description
      }
    }
  }
}

 

It comes back with nothing 😞 , but when I run this on https://shopify.dev/apps/tools/graphiql-admin-api it works. Is there maybe some setting in the shop that I am missing that doesn't allow filtering on title?

Other queries I tried which where not working:

  • products(first: 10, query: "description=the")
  • products(query:"title:*bike*" first:5 )
  • products(first: 10, query:"title=*b*")

Hopefully someone can shine a light and push me in the right direction.

Accepted Solution (1)

Luke_K
Shopify Staff
402 66 102

This is an accepted solution.

Hey @maartenvdh 

Thanks for getting in touch! So I'd tried this below in GraphiQL with the equality comparator(docs) on my title, which is the way of returning the product title - please see below.

 

{
  shop {
    name
  }
  products(first: 10, query: "title:mycoolproduct") {
    edges {
      node {
        id
        title
        description
      }
    }
  }
}

 

I'm returned two results in my store's GraphiQL app - that's expected for me as I only have two products on my store that hold the title of 'mycoolproduct'. There's some further docs here on comparators here if needed too. Hope that helps!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!

View solution in original post

Replies 2 (2)

Luke_K
Shopify Staff
402 66 102

This is an accepted solution.

Hey @maartenvdh 

Thanks for getting in touch! So I'd tried this below in GraphiQL with the equality comparator(docs) on my title, which is the way of returning the product title - please see below.

 

{
  shop {
    name
  }
  products(first: 10, query: "title:mycoolproduct") {
    edges {
      node {
        id
        title
        description
      }
    }
  }
}

 

I'm returned two results in my store's GraphiQL app - that's expected for me as I only have two products on my store that hold the title of 'mycoolproduct'. There's some further docs here on comparators here if needed too. Hope that helps!

 

| Shopify |
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
maartenvdh
Visitor
2 0 1

@Luke_K thanks I am not sure what I did wrong but it works now