A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I have a simple graphql query, see below. But it behaves very oddly. If the vendor search word has a space in it, it seems to work exactly as you would expect. However, if there is no space in the vendor name, it appears that everything gets returned.
The query is a bit limited anyway as I can only get back a max of about 30 orders. What I'm trying to do is just get orders relevant to a particular vendor and ignore the rest. Filtering could be done outside Shopify, but ideally we don't want all that data going to our servers.
Solved! Go to the solution
This is an accepted solution.
Hi @pgj99 👋
I'd recommend reviewing this list of supported filter parameters for the `query` argument. Since `lineItems.product.vendor` is not a supported parameter, the `orders` query ignores the invalid filter and returns all unfiltered results. This guide highlights how to effectively use the search syntax as well.
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
The issue you're encountering might be due to the way Shopify's Search API handles non-space-separated words. When the vendor name doesn't have a space, the search query may treat the vendor name as a single token and thus not return the expected results.
In your case, you can try enclosing your vendor name in quotes, like so:
{
orders(first: 10, query: "lineItems.product.vendor:\"MyVendor\"") {
edges {
node {
id
updatedAt
createdAt
lineItems(first: 10) {
edges {
node {
id
title
variant {
id
title
}
product {
vendor
}
}
}
}
}
}
}
}
This will explicitly treat "MyVendor" as a single string.
For dealing with the issue of only getting 30 orders back at a time, you can paginate your results using cursor-based pagination. You can use the `after` argument and pass the cursor of the last edge in the previous page to get the next page of results. Here is an example of how to do that:
{
orders(first: 10, after:"<cursor>", query: "lineItems.product.vendor:\"MyVendor\"") {
pageInfo {
hasNextPage
}
edges {
cursor
node {
id
updatedAt
createdAt
lineItems(first: 10) {
edges {
node {
id
title
variant {
id
title
}
product {
vendor
}
}
}
}
}
}
}
}
Here, replace `<cursor>` with the cursor of the last item from the previous query. `pageInfo` tells you whether there are more pages to fetch. If `hasNextPage` is true, you can take the `cursor` of the last edge in `edges` and use that as the `after` argument in the next query to fetch the next page.
Try this out and see if it works for your purposes!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Thanks Liam,
The cursor should work well for what we need, however the issue with the query was actually that it works as 2 words but not as a single.
e.g.
This is an accepted solution.
Hi @pgj99 👋
I'd recommend reviewing this list of supported filter parameters for the `query` argument. Since `lineItems.product.vendor` is not a supported parameter, the `orders` query ignores the invalid filter and returns all unfiltered results. This guide highlights how to effectively use the search syntax as well.
Hope that helps!
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
OK Thanks. Guess, I can't use that one then. How odd it works when it has a space though 😄 I assume that maybe one that's being worked on for future.