I'm finding GraphQL queries very unreliable

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.

{
orders(first: 10, query: “lineItems.product.vendor:=‘My Vendor’”) {
edges {
node {
id
updatedAt
createdAt
lineItems(first: 10) {
edges {
node {
id
title
variant {
id
title
}
product {
vendor
}
}
}
}
}
}
}
}

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:"

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!

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.

orders(first: 10, query: “lineItems.product.vendor:="Yappy Dev"”)
This currently returns all orders that have a product with Yappy Dev as a vendor and nothing else. If 2 lines on in the order one Yappy Dev one not, it will also return the order as expected.

This however…

orders(first: 10, query: “lineItems.product.vendor:="Burton"”)
Returns everything. Some of my orders do have Burton as a vendor as this is just test data.

Also I could even query “asdf” or something and it still brings back all results. But “asdf asdf” would bring back nothing, which would be correct in this case.

Thanks,
Paul

Hi @pgj99 :waving_hand:

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!

OK Thanks. Guess, I can’t use that one then. How odd it works when it has a space though :grinning_face_with_smiling_eyes: I assume that maybe one that’s being worked on for future.