When I setup our app/extension in a clients store, I need to specify the GID of the product from their store that contains the fee that needs to be added to certain orders. As of right now we are handling the setup of the app/extensions for our clients as part of our service.
I am trying to add a metafield to a cart transform function that contains the GID of the product to be added when I need to expand a cart item to add a fee. I was following this GitHub as an example.
Here is the GraphQL I used to add the metafield to the function:
mutation addCartTransform {
cartTransformCreate(
functionId: "9869e7dc-2d98-4ad6-b7cd-07fb07abac8d"
blockOnFailure: true
metafields: [{namespace: "$app:cart-transforms", key: "fee-product-id", type: "single_line_text_field", value: "gid://shopify/ProductVariant/45723759739034"}]
) {
cartTransform {
id
functionId
metafields(first: 10) {
nodes {
id
}
}
}
userErrors {
field
message
}
}
}
This query to verify the field is there:
query getCartTransforms {
cartTransforms(first: 10) {
nodes {
id
metafields(first: 10) {
nodes {
id
namespace
type
value
key
}
}
}
}
}
Returns this result:
{
"data": {
"cartTransforms": {
"nodes": [
{
"id": "gid://shopify/CartTransform/35455130",
"metafields": {
"nodes": [
{
"id": "gid://shopify/Metafield/33708880625818",
"namespace": "app--2315872--cart-transforms",
"type": "single_line_text_field",
"value": "gid://shopify/ProductVariant/45723759739034",
"key": "fee-product-id"
}
]
}
}
]
}
},
"extensions": {
"cost": {
"requestedQueryCost": 30,
"actualQueryCost": 6,
"throttleStatus": {
"maximumAvailable": 2000,
"currentlyAvailable": 1994,
"restoreRate": 100
}
}
}
}
This is the graphql query that is used in the cart transform function:
query RunInput {
cart {
lines {
id
merchandise {
... on ProductVariant {
id
sku
product {
title
}
sku
requiresShipping
}
}
cost {
amountPerQuantity {
amount
}
}
}
}
cartTransform {
targetVariantID: metafield(key: "fee-product-id", namespace: "$app:cart-transforms") {
value
}
}
}
Here is the partial result when the function runs on the cart, as you can see the targetVariantID is null.
{
"shopId": 66930835610,
"apiClientId": 242488672257,
"payload": {
"export": "run",
"input": {
"cart": {
"lines": [
{
"id": "gid://shopify/CartLine/aa9bb533-1dde-49af-afde-d5ca6b35798a",
"merchandise": {
"id": "gid://shopify/ProductVariant/45677996048538",
"sku": "EVT-665",
"product": {
"title": "My Panel"
},
"requiresShipping": false
},
"cost": {
"amountPerQuantity": {
"amount": "19.0"
}
}
}
]
},
"cartTransform": {
"targetVariantID": null
}
},
I did all of the work to add the metafield to the function via the Shopify GraphIQL app. Is there a more appropriate place to run that? I read a few posts that said it could be because $app
for the GraphIQL app is different that what my app/extension would be using, is this true?
Thoughts?