Second Product.All() call uses previous call's filters?


#1

If I make a Product.All() call after another call which had a filter, it still includes all the filters.

Take this example code:

const first = await Moltin.Products.All()
console.log("First 'all' result", first.data.length)

const second = await Moltin.Products.Filter({ eq: { slug: "x" } }).With(["category", "main_image"]).All()
console.log("One product result", second.data.length)

const third = await Moltin.Products.All()
console.log("Second 'all' result", third.data.length)

If I run that with request logging on, I get this:

Fetch finished loading: OPTIONS "https://api.moltin.com/v2/products".
First 'all' result 34

Fetch finished loading: OPTIONS "https://api.moltin.com/v2/products?include=category,main_image&filter=eq(slug,x)".
One product result 0

Fetch finished loading: OPTIONS "https://api.moltin.com/v2/products?include=category,main_image&filter=eq(slug,x)".
Second 'all' result 0

Is this intended? Is there some way to clear filters or something? It feels super strange…


#2

Hi @damien

This appears to be a bug with class inheritance with the JS SDK. I’ve logged this internally so we can push out a fix.

Thanks for flagging this :smile: and apologies for the inconvenience caused.