我需要使用变量作为标签 id 和集合 id。我在“shop”上创建了元字段并设置了值 这是文档https://shopify.dev/docs/apps/functions/input-output/variables-queries`
但不幸的是它没有获取变量值。
query RunInput(
$selectedCollectionIds: [ID!]
$selectedProductTags: [String!]
) {
cart {
lines {
quantity
merchandise {
__typename
... on ProductVariant {
id
weight
product {
isGiftCard
inAnyCollection(ids: $selectedCollectionIds)
inCollections{
__typename
collectionId
isMember
}
hasAnyTag(tags: $selectedProductTags)
hasTags(tags:$selectedProductTags){
__typename
hasTag
tag
}
}
}
}
}
}
shop{
metafield(
namespace: "$app:my_namespace"
key: "my_key"
) {
value
}
}
}
根据文档,也在 .toml 文件中添加了变量名称。
api_version = "2023-10"
[[extensions]]
handle = "my-app"
name = "t:name"
description = "t:description"
type = "function"
[[extensions.targeting]]
target = "purchase.validation.run"
input_query = "src/run.graphql"
export = "run"
[extensions.input.variables]
namespace = "$app:my_namespace"
key = "my_key"
[extensions.build]
command = ""
path = "dist/function.wasm"
[extensions.ui.paths]
create = "/"
details = "/"
这是在商店资源上创建的元字段值
{
id: 35171720954165,
namespace:
'$app:my_namespace',
key: 'my_key',
value: '{"selectedProductTags":[],"selectedCollectionIds":["gid://shopify/Collection/442796769589","gid://shopify/Collection/442796704053","gid://shopify/Collection/442796802357"]}',
description: null,
owner_id: shopId,
created_at: '2023-10-16T00:59:56-04:00',
updated_at: '2023-10-16T03:31:01-04:00',
owner_resource: 'shop',
type: 'json',
admin_graphql_api_id:
'gid://shopify/Metafield/3517172095416
}
我也遇到同样的问题,请问你解决了吗? 谢谢