we are adding paymentCustomizations
metafields using the Admin GraphQL API for one of our stores. While the data sent in the mutation is successfully retrieved when queried via GraphQL, the Shopify function logs unexpectedly show these metafields as null
.
The payment customization function is added and active on the store without any errors in the function logs.
This issue seems to be specific to one store, as it works fine across all other stores. Could it be possible that another app or script is altering the metafields received in the run.js
of the extension functions?
Mutation to set metafields:
metafieldsSet(metafields: [
{
ownerId: "${ownerId}"
namespace: "${namespace}"
key: "${key}"
value: ${JSON.stringify(JSON.stringify(value))}
type: "json"
}
]) {
metafields {
id
}
userErrors {
message
}
}
}
Query to get metafields:
query {
paymentCustomizations(first: 10) {
edges {
node {
id
functionId
title
enabled
metafields(first: 10) {
edges {
node {
id
key
namespace
value
}
}
}
}
}
}
}
run.graphql
..
...
paymentCustomization {
conditionsMetafield: metafield(
namespace: "paymentCustomizations"
key: "customConditionsPaymentMapping"
) {
value
}
}
..
...
run.js
export function run(input) { //getting metafields as null in from this input, this input gets logged inside shopify function logs
let configuration = JSON.parse(
input?.paymentCustomization?.conditionsMetafield?.value?? "{}"
);
const rules = configuration?.paymentCustomizationConfig || [];
}
After some research and trial-and-error, I discovered the issue: Shopify metafields have a size limitation. If the string stored in a metafield exceeds 10,000 bytes, it becomes unavailable in a function run.
For more details, you can refer to the documentation:
Shopify Functions Input and Output Limitations