Cart Transform function returns null even though it is Shop Metafield

I am adding metafields to the store using the MetafieldsSet graphql mutation. I set OwnerId as the store id. I successfully created the metafield. I verified that the metafield was created by testing with the following query.

query getShopMetafields{
  shop {
    id
    metafields(first: 30) {
        nodes {
            namespace
            id
            key
            value
            type
        }
    }
  }
}
    "data": {
        "shop": {
            "id": "gid://shopify/Shop/88556339494",
            "metafields": {
                "nodes": [
                    {
                        "namespace": "my_app",
                        "id": "gid://shopify/Metafield/43504335552806",
                        "key": "fields",
                        "value": "example_values",
                        "type": "json"
                    }
                ]
            }
        }
    },

I pull this store metafield data from cart transform plugin as below:

query Input {
	cart {
         ...
	}
	shop {
		fields: metafield(namespace: "my_app", key: "fields") {
			value
		}
	}
}

Until this time, our application was successfully pulling this data into the cart transform plugin, but today we found that this data was null in a store using our application.

We checked the store metafields that use our app where this happened and we are sure that the metafield already exists and the namespace and key are correct.

This has happened and continues to happen in only one store that uses our app. Each function request returns metafield null. The other stores that use our app do not have any issues.

We tried uninstalling our app from the store and reinstalling it, same thing.

Cart transform extension cargo.toml:

[package]
name = "my-app-cart-transform"
version = "1.0.0"
edition = "2021"
rust-version = "1.62"

[dependencies]
rust_decimal = "1.27.0"
serde = { version = "1.0.13", features = ["derive"] }
serde_with = "1.13.0"
serde_json = "1.0"
shopify_function = "0.8.0"
graphql_client = "0.14.0"

[profile.release]
lto = true
opt-level = 's'
strip = true

Cart transform extension shopify.extension.toml:

api_version = "2024-07"

[[extensions]]
name = "t:name"
handle = "my-app-cart-transform"
type = "function"

description = "t:description"

  [[extensions.targeting]]
  target = "purchase.cart-transform.run"
  input_query = "src/run.graphql"
  export = "run"

  [extensions.build]
  command = "cargo wasi build --release"
  path = "target/wasm32-wasi/release/my-app-cart-transform.wasm"
  watch = [ "src/**/*.rs" ]

  [extensions.ui.paths]
  create = "/"
  details = "/"

1 Like

This could happen because the size of your json could exceed the allowed limit of 10KB.

If it exceeds the limit, metafield is returned as null.

Can you confirm if the metafield json is less than 10KB?

3 Likes

That’s exactly what our problem was. Thank you very much for your help. It would be nice to see an error on the function details page in case of exceeding the metafield size limit.

1 Like