good-idea / sane-shopify

MIT License
212 stars 15 forks source link

Unable to filter product by collection #119

Closed liqueflies closed 4 years ago

liqueflies commented 4 years ago

Hello!

I am facing an issue when I'm trying to filter products by it's collection, here an example:

{
  allSanityShopifyProduct(
    sort: { by:"maxVariantPrice", order:DESC }, 
    filter: { collections: { contains: "fC2enKhGoDy6FwhgsPjK7e" } }  # this is the collection sanity ID
  ) {
    totalCount
    edges {
      node {
        title
        collections {
          title
          handle
        }
        maxVariantPrice
      }
    }
  }
}

it returns no-results.

Also is not possible to filter products inside collection IE.

query ShopifyCollection ($id: ID!) {
  collection: sanityShopifyCollection(id: $id) {
    _id
    title
    products { # products(...) ordering, filtering... etc
      _id
      title
    }
  }
}

The second one is not important instead the first. FYI I am using gridsome :)

Thank you again <3

Lorenzo

liqueflies commented 4 years ago

Update: Tried into sanity playground:

{
  allShopifyProduct(where: { _: { references: "fC2enKhGoDy6FwhgsPjK7e" } } ) {
    _id
    title
    collections {
      title
      handle
    }
  }
}

and it's working.

It's an issue related to gridsome or the source plugin that i am using?

good-idea commented 4 years ago

Hi Lorenzo, sorry for the slow response ~

I use the latter _: { references: "..." } when I need to do a query like this. An unfortunate result of this, though, is that the products return do not match with the way they are ordered within that collection.

Unfortunately, deeper filtering (like you mention with products { # products(...) ordering, filtering... etc) is a limitation from Sanity's GraphQL API - you can only do filtering & sorting on the top-level query ☹️ Hopefully this is something they are working on.

I have a project that includes filter/sorting/search functionality -- and I've found that the only way to do more complicated things is to use GROQ.

I'm going to close this since it's really an issue with Sanity's GraphQL API and not specific to this project - but feel free to continue the discussion.