Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
$this->query = <<<'GRAPHQL'
query ($id: ID!) {
node(id: $id) {
...ProductFragment
}
}
fragment ProductFragment on Product {
id
description
handle
productType
title
vendor
options {
id
name
values
}
variants(first: 250) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
cursor
node {
id
weight
title
sku
requiresShipping
compareAtPrice
price
selectedOptions{name value}
}
}
}
}
GRAPHQL;
{"errors": [
{
"message": "Field must have selections (field 'price' returns MoneyV2 but has no selections. Did you mean 'price { ... }'?)",
"locations": [
{
"line": 56,
"column": 9
}
],
"path": [
"fragment ProductFragment",
"variants",
"edges",
"node",
"price"
],
"extensions": {
"code": "selectionMismatch",
"nodeName": "field 'price'",
"typeName": "MoneyV2"
}
},
{
"message": "Field must have selections (field 'compareAtPrice' returns MoneyV2 but has no selections. Did you mean 'compareAtPrice { ... }'?)",
"locations": [
{
"line": 61,
"column": 9
}
],
"path": [
"fragment ProductFragment",
"variants",
"edges",
"node",
"compareAtPrice"
],
"extensions": {
"code": "selectionMismatch",
"nodeName": "field 'compareAtPrice'",
"typeName": "MoneyV2"
}
}
],
}
replace is with
price {
amount
currencyCode
}
to be
edges {
cursor
node {
id
weight
title
sku
requiresShipping
compareAtPrice
price {
amount
currencyCode
}
selectedOptions{name value}
}
}
}
This will return an object inside the price { amount:"25.00", currencyCode: "MYR", __typename: MoneyV2 } , how do we only get the value of amount? not the object