Most performant way to fetch a metafield by key and namespace

Jeff_Chang
Shopify Partner
14 1 1

It seems that when using Flow, there are two ways to fetch a specific metafield:

 

1. Doing a liquid loop through all the resource's metafields and checking each one's key and namespace

 

2. Using the "run code" functionality, request the resource's metafields and then use .find() in Javascript on the returned array. It seems you can't filter metafields within the GraphQL query.

 

My questions are, am I missing any other options? And secondly, are there performance issues to be worried about in the case the resource has a large amount of large metafields?

 

Option 2 has been working fine for me, but my concern is that I store potentially large JSON files (the maximum size is 2 million characters so why not?) as metafields on variants and I'm wondering if this could cause Flow to timeout or fail even if I'm just trying to access a smaller metafield.

 

 

Replies 2 (2)
paul_n
Shopify Staff
1005 133 240

This is a Flow question not a general API question.

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.

paul_n
Shopify Staff
1005 133 240

Those are both about the same performance as they will fetch all of the fields that you use in your code/liquid

 

We have an update for metafields coming very soon that will allow fetching each metafields one-by-one, which we prioritized because of the performance issues in looping and the growing size of metafields. 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.