A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi,
Newbie to GraphQL. I have a basic query working, for example to show the first 100 product titles:
{"query": "{products(first:100){edges{node{title}}}}"}
However, I've had no luck with any type of query to search a product. My current (failing) query is as follows - searching for a wildcarded piece of text and returning the first node and its title:
{"query": "{products(first:1, query:"title:Brace*"){edges{node{title}}}}"}
This results in Error 400, Bad Request. Appreciate a heads-up on what's wrong with the above query. My content header and access key are all ok since the first query works ok.
Thanks in advance.
Solved! Go to the solution
This is an accepted solution.
You need to use double quotes for your products query.
Try this:
{"query":"{products(first:100,query:\"title:*brace*\"){edges{node{title}}}}"}
Gojiberry - Best post-purchase survey and feedback app for Shopify | Install on App Store for free
Shopify Community is helpful, BUT... why not start asking your customers for feedback instead?
Hello,
You have syntax errors in your code, below is proper syntax to achieve this. Let me know if you have any more questions!
query {
products(first:100,query:"title:*brace*"){
edges{
node{
title
}
}
}
}
Daveed, thanks for the reply.
I think quotes are my problem. I now see this:
{"errors":[{"message":"syntax error, unexpected invalid token (\"'\") at [1, 27]","locations":[{"line":1,"column":27}]}]}
Can I use single quotes around the query, like this?
{"query":"{products(first:100,query:'title:*brace*'){edges{node{title}}}}"}
If I use a double quote, it breaks. I am escaping my second lot of quotes also, but should I need to? Is there an alternative syntax for the query() ?
This is an accepted solution.
You need to use double quotes for your products query.
Try this:
{"query":"{products(first:100,query:\"title:*brace*\"){edges{node{title}}}}"}
Gojiberry - Best post-purchase survey and feedback app for Shopify | Install on App Store for free
Shopify Community is helpful, BUT... why not start asking your customers for feedback instead?
This worked in the end:
{"query":"{products(first:10,query:\"title:*brace*\"){edges{node{title}}}}"}
I had to use \ to escape. I think the issue is my platform/environment. Thanks for nudging me along; I have a solution now at least 👍