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
170 43 69

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
170 43 69

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 7

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
}
}
}