Hi, I'm new to Shopify and have been creating an app to learn the ropes.
I'm having trouble with something that I feel should be straightforward, so I'm hoping someone with a bit more experience will be able to tell me where I'm going wrong.
My app is built using React/Next/Apollo/GraphQL and I'm trying to save a metafield that holds a small amount of configuration data onto the store.
From what I've been able to tell, this isn't possible via the GraphQL API. It looks as if you're able to save metafields onto products and other resources by doing this when you create/update them - but theres no way to mutate metafields on the store directly?
I tried going down the route of using the REST API for this part of the app, and seemed to be hitting one problem after another in terms of authenticating. CORS, access tokens, etc.
I've reached the point where it seems as though I have to spin up a database to store the access token when the app is installed, create a custom backend function to proxy the REST request, retrieve the access token from the database within this function, use this in order to send an authenticated request to the REST API, then finally save the metafield data.
This seems a bit long winded and is making me think I must be missing an easier way?
Hey @g_elwell ,
Unfortunately (and sadly) you're correct in that you cannot save a metafield at the shop level using GraphQL currently. In good news though that functionality in GraphQL is on the roadmap for the future, but there isn't any kind of ETA that I could provide that wouldn't just be a wild guess.
Is there any chance you're only planning to use your app on your own store, or is this going to be used publicly? If it's only for your own use, you could potentially create a private app on your shop and use its credentials to create your metafields with REST.
That would at least allow you to bypass the confusion you're having with access tokens, etc. because you could use Basic Auth as an authentication method instead, and create your metafields with the REST API using a cURL request. That would be a much simpler solution until shop metafields are available in the GraphQL Admin API.
Thanks for the info - I'll keep an eye out for the shop metafields being added to the GraphQl API in the future.
I'm intending to release this app publicly when it's finished. Do you have any other suggestions for storing an access token without employing a database, or is this the recommended route for now?
Hey again @g_elwell ,
You're on the right track with employing a database, I think that would be the best path forward. My only other thought would be using one of the resources that currently do support metafields for the time being so you don't need to use REST, but even then you'd still need to store some related information to remember where your metafield was so a database would be required either way.