InputSizeLimitExceededError when checking against many collections

Our function checks whether each item in the cart belongs to specific collections.
Some of our larger customers have a high number of collections, and we need to check all of them using inCollections.

With 30 items and 60 collections, we’re running into the input size limit.
This happens because the input contains 30 × 60 = 1800 blocks in the following format:

{
	"collectionId": "gid://shopify/Collection/1234567890",
	"isMember": false
}

This format consumes a lot of input space, causing us to hit the input size limit.
Please note: it’s not the instruction limit but the input size limit that is being exceeded.

Would it be possible to modify the return format of inCollections so that it returns only a list of collectionIds an item belongs to, instead of a list of objects containing both collectionId and isMember fields?

Or is there another way to achieve the same result without exceeding the input size limit?

2 Likes

Hey Anton,

Are you currently using Rust for your functions?

Hey Liam, yes we do use Rust from the very beginning.

I definitely think this is a valid concern. The input query is not taken into account when scaling input size.

One approach you can use is to use GQL aliases to take a smaller number of bytes per collection check. In your run.gql, do:

{
  ....
  cid: collectionId,
  im: isMember,
}

You’ll likely still run into input size issues with larger numbers of cart lines though!

@bkspace GraphQL aliases help a little, but as you said, they don’t fully resolve the issue.

We’re still running into the InputSizeLimitExceededError, even with just 5 collections and 250 lines in cart. At this scale, the input limit increases to 160 KB, but the inCollections sections end up consuming all of it.

1 Like

Right, yea, I think the real fix is that the function input limits should scale based on input variables, and function output limits should also scale based on cart lines! Hopefully we get something like that in future :slight_smile: