Discussing Shopify Functions development, deployment, and usage in Shopify apps.
Hi there,
I'm currently making an in-house checkout extension app, and have made a few functions and UI extensions, but I am struggling a bit with using variables in input queries.
For example, I want the user to be able to create a discount that applies to a specific line item property, or whether the product is in a particular collection. From my understanding, in order to do this, I need to save the user's input to an app metafield, and use that in the graphQL input - but i don't know how to do this?
I have been looking at https://shopify.dev/docs/apps/functions/input-output/variables-queries but i don't understand how I am supposed to save the user input to those json files (or run the metafieldsSet mutation in the app), and then reference them in the graphQL?
I initially thought I had to define the metafield first, but after contacting support they let me know that is not the case (and also admitted their documentation was not clear).
Does anyone have an example of saving to these metafields and using them in the input query?
I would be very very grateful!
Thanks so much,
Rhianna
Solved! Go to the solution
This is an accepted solution.
@RhiRo wrote:
i don't understand how I am supposed to save the user input to those json files (or run the metafieldsSet mutation in the app), and then reference them in the graphQL?
So we can improve our docs, can you explain where you got stuck here? Are you already using GraphQL in your app? Typically you would make this invocation from the same create/edit pages you made for your functions, or wherever else you are invoking APIs to enable the function.
You can see an example of this in action in an example app I have. It sets the metafields directly on the Discount instead of a separate metafieldsSet call.
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
This is an accepted solution.
@RhiRo wrote:
i don't understand how I am supposed to save the user input to those json files (or run the metafieldsSet mutation in the app), and then reference them in the graphQL?
So we can improve our docs, can you explain where you got stuck here? Are you already using GraphQL in your app? Typically you would make this invocation from the same create/edit pages you made for your functions, or wherever else you are invoking APIs to enable the function.
You can see an example of this in action in an example app I have. It sets the metafields directly on the Discount instead of a separate metafieldsSet call.
Nick Wesselman | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Ahh okay thank you Nick! These look great!
I am only using GraphQL in the input queries at the moment, not within the create/edit pages themselves. I'm probably making myself look really stupid here, but up until yesterday, I didn't realise you could make those invocations from those files.
I actually was struggling a bit with the editing part of the discount, with getting the existing discount information, when I came across this post with your answer yesterday and that was the first time I think I've seen an example of GraphQL being used in these files (and had an inkling it might help with my question here). It would be great to point to these/have more examples like these in the docs 🙂
Thanks so much again!
Rhianna
Hi Nick
I am creating payment customization with multiple rules set, for that I create a function and each able to create 5 customization. My issue is that we can only access single metafield to access input for customization on function run.graphgql file but my app is able to create more then 1 customization with different rules set. how to handle this issue