Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: How can i get two or more product metafields in input query ?

Solved

How can i get two or more product metafields in input query ?

RickyMagana
Shopify Partner
6 0 0

I can get value of one field but i need to get two or more metafields. If it is possible, I need to know how is the structure of input.graphql

Accepted Solution (1)

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

Hi @RickyMagana -- You can use GraphQL field aliases for this.

  discountNode {
    metafield1: metafield(namespace: "$app:my-app", key: "key1") {
      value
    }
    metafield2: metafield(namespace: "$app:my-app", key: "key2") {
      value
    }
  }

 

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

View solution in original post

Replies 4 (4)

Nick_Wesselman
Shopify Staff
171 43 73

This is an accepted solution.

Hi @RickyMagana -- You can use GraphQL field aliases for this.

  discountNode {
    metafield1: metafield(namespace: "$app:my-app", key: "key1") {
      value
    }
    metafield2: metafield(namespace: "$app:my-app", key: "key2") {
      value
    }
  }

 

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

RickyMagana
Shopify Partner
6 0 0

Thank you so much, now my function works fine.

jakehe
Shopify Partner
12 1 6

I got it working

 

key and namespace values were wrong

 

metafield (key:"locality", namespace:"custom"){
value
}
RickyMagana
Shopify Partner
6 0 0

Here is my graphql file, works very well.

 

query Input {
cart {
lines {
quantity
merchandise {
__typename
...on ProductVariant {
id,
product {
handle,
boxcontains: metafield(namespace: "custom", key: "box_contains") {
value
},
percentagediscountbox: metafield(namespace: "custom", key: "percentage_discount_per_box") {
value
},
}
}
}
cost {
totalAmount {
amount
}
}
}
}
discountNode {
metafield(namespace: "volume-discount", key: "volume-config") {
value
}
}
}