d
Topic
Robert Member
Posts:
3
Last edited 4 months ago

How would one go about efficiently creating metafields for products in shops with 10s of thousands of products

I'm developing an app and to be efficient and reduce the amount of data pulled from my servers (better for page load speeds etc) I'd like to store some data in the metafields.

Those are quite cool but what if a shop has, say 50k products? If I use the API I will have to wait for my installation process to run multiple days! Is there any way to create those metafields in bulk? Or any other efficient way? I can't find anything in the API description.

i
Replies
Alex Richter Developer Experience
Posts:
892
4 months ago

One more hacky approach I've seen is actually storing all of your metafield data in one metafield by passing it a hash value:

{ "metafield": { "key": { "sub_key": "value", "sub_key_2": "value" } } }

We don't currently have a createMetafield mutation on our GraphQL admin API but that might be something to look for in the future as well, the whole idea behind our GQL api is to reduce request count so I wouldn't be surprised if that made things a bit easier too.

Robert Member
Posts:
3
4 months ago

hmmmm yeah that would be a little bit better (4x better in my case) - would liquid render that tho in the templates?

I was looking through GQL, got very excited, learnt the basics just to find out that metafields were not a part of that API yet ¯\_(ツ)_/¯

Alex Richter Developer Experience
Posts:
892
4 months ago

Hey Robert,

My mistake! I got confused because the way we handle it is a bit more different from the RESTful approach than I thought. You can add metafields through the product object directly rather than creating the metafield on its own:

https://help.shopify.com/en/api/graphql-admin-api/reference/mutation/productupdate

We just don't have a mutation to create a metafield externally. As long as you do it through the product you should be good. It's worth noting you can also perform multiple mutations in one request as well as long as you're within the complexity limit.

Cheers.

Robert Member
Posts:
3
4 months ago

Riiiight. So you're saying that I can mutate multiple products at a time and as part of that mutation create a metafield? Do I understand correctly?

Could you share an example of how that would look like?

Posts:
11
3 months ago

Hey Alex,

related question. Can we create/update metafields on the shop level through the GraphQL Admin API yet? I see there is a "metafieldDelete" mutation bur I cannot find something along the lines of "shopUpdate" that woul let me do updates of shop metafields analog to "productUpdate".

Any ideas?

Thanks a ton for your time!

~Dom

 

 

Log in or sign up for an account to reply.

f
Your Reply