Re: Function return null for product metafields ?

Solved

Function return null for product metafields ?

SPEAZ
Shopify Partner
27 3 14

So ive tried to get products metafields from function, but it's return null 

It's works perfectly for DiscountNode metafield !

Ive also tried directly from the Shopify GraphiQL App and product metafield are correctly returned.

 

my input.graphql

query Input {
cart {
lines {
quantity
merchandise {
... on ProductVariant {
id
product {
id
handle
metafield(key: "MYAPP", namespace: "MYAPP") {
type
value
}
}
}
}
}
}
discountNode {
metafield(namespace: "MYAPP", key: "MYAPP") {
value
}
}
}

function return 

{
  "cart": {
    "lines": [
      {
        "quantity": 1,
        "merchandise": {
          "id": "gid://shopify/ProductVariant/41966607499422",
          "product": {
            "id": "gid://shopify/Product/6023989461150",
            "handle": "bangle-bracelet",
            "metafield": null // works with graphql app
          }
        }
      }
    ]
  },
  "discountNode": {
    "metafield": {
      "value": "{\"ok\":\"ok\"}"
    }
  }
}

 

graphql app 

 

{ product(id:"gid://shopify/Product/6023989461150"){
  id
  handle
  metafield(namespace:"MYAPP",key:"MYAPP"){
    value // works
    type
  }
} }

any clues or it's a bug ?

Accepted Solution (1)

SPEAZ
Shopify Partner
27 3 14

This is an accepted solution.

Ok finally found out it's not a bug but a limitation : only 1kb of metafields ,query cost of 30 and max 3000bytes.

Well it's seems pretty too much restrictions, so if a customer have many products in cart and you have a products metafields based function , the function will not just work 😕

 

 

SPEAZ_0-1668176861886.png

 

so i guess function are not use-able in my case, pretty sad 😞

 

 

View solution in original post

Replies 10 (10)

SPEAZ
Shopify Partner
27 3 14

This is an accepted solution.

Ok finally found out it's not a bug but a limitation : only 1kb of metafields ,query cost of 30 and max 3000bytes.

Well it's seems pretty too much restrictions, so if a customer have many products in cart and you have a products metafields based function , the function will not just work 😕

 

 

SPEAZ_0-1668176861886.png

 

so i guess function are not use-able in my case, pretty sad 😞

 

 

Nick_Wesselman
Shopify Staff
170 43 69

Just to clarify, it's the query itself that can't be more than 3000 bytes. The limitation you are likely hitting is the metafield value, which is currently limited to 1kB.

Can I ask what you are storing in this metafield?

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

SPEAZ
Shopify Partner
27 3 14

Hi Nick !  just saw your message really sorry for the delay.

I have a booking app, and i allow merchants to set special discounts on any dates of calendar they want to.. so the metafields can be really big since it need to store the dates, and usually merchants set-it for months ahead like : 

 

2023/04/12 : $20

2023/04/16 : $30

etc..

 

so basically with theses limitations it's impossible to achieve that using shopify functions 😕

or maybe you have an idea i didnt think about ?

Nick_Wesselman
Shopify Staff
170 43 69

@SPEAZ Interesting case. Where are the customer's selected dates being stored? Any ideas on what a more reasonable metafield value limit would be for your use case?

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

SPEAZ
Shopify Partner
27 3 14

There are stored in metafields 🙂

 

Well i cant say, cause it's depend of merchants and number of items with metafields on cart etc so i dont think it's usable for the case when you need to grab a lot of settings 😕

 

Btw there is already a limitation of 5ms for the function, so why there is also a limitation cost since if it's too heavy and slow there is already a limit ?

 

What about instead of limitations warn the merchant about the function can slow down the checkout process (if it's too slow) ? i'm pretty sure 80% of merchant will prefer to use a slow function rather than dont have a possibility to use it !

markus12
Shopify Partner
30 1 14

+1 for a not-so-restrictive limit on metafields. Function configuration metafield is a bottleneck. 10k would be a more reasonable limit. 

SPEAZ
Shopify Partner
27 3 14

     Removed

SPEAZ
Shopify Partner
27 3 14

Hi Nick ! Any updates concerning the limitations of input queries ? I just saw it's now possible to use functions with javascript and i would love to use functions on my app 🙂

DanteFXX
Shopify Partner
15 2 8

For new readers - It appears that the limitation for metafield size has been changed to 10000 bytes instead of 1 KB, as seen earlier. See https://shopify.dev/docs/apps/functions/input-output#limitations

originmaster
Shopify Partner
45 2 19

Thanks for the update. This is still much too restrictive for our use case as we store product bundle configurations within a metafield. With scripts we could do around 80 bundles, now we can do less than 10.