Try to get variant price by using store front api.

Try to get variant price by using store front api.

namrata016
Visitor
2 0 1
Please help i am using 2022-10 api version . 
I used this store front query and getting
no selections error.
$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"
            }
        }
    ],
    
}
​

 

Replies 2 (2)

osama-apollo
Visitor
1 0 0

replace is with 

 

price {
    amount
    currencyCode
}

 

to be 

 

 edges {
   cursor
   node {
     id
     weight
     title
     sku      
     requiresShipping
     compareAtPrice
     price  {
         amount
         currencyCode
    }
     selectedOptions{name value}      
   }
 }
}

 

ToddByteex
Shopify Partner
1 0 0

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