
Do you want to know how to get specific country information using GraphQL Query in Magento 2?
In this Magento 2 GraphQL Tutorial, We will show how to get specific country information using GraphQL Query in Magento 2. We will use the {country} query to get specific country information with available regions.
Let’s start!
Get Specific Country Info Query:
The {country} query returns all the information about a specific country.
query { country(id: "AU") { id two_letter_abbreviation three_letter_abbreviation full_name_locale full_name_english available_regions { id code name } } }
Output:
{ "data": { "country": { "id": "AU", "two_letter_abbreviation": "AU", "three_letter_abbreviation": "AUS", "full_name_locale": "Australia", "full_name_english": "Australia", "available_regions": [ { "id": 569, "code": "ACT", "name": "Australian Capital Territory" }, { "id": 570, "code": "NSW", "name": "New South Wales" }, { "id": 576, "code": "NT", "name": "Northern Territory" }, { "id": 572, "code": "QLD", "name": "Queensland" }, { "id": 573, "code": "SA", "name": "South Australia" }, { "id": 574, "code": "TAS", "name": "Tasmania" }, { "id": 571, "code": "VIC", "name": "Victoria" }, { "id": 575, "code": "WA", "name": "Western Australia" } ] } } }
In this example, You will get all information about the Australia country with available regions.
How to Get Country Information Using GraphQL in Magento 2 Click To TweetYou can use ChromeiQL tool to test and run GraphQL Query in Magento 2.
If you liked this tutorial, then please subscribe to our Newsletter for Magento tutorials. You can also find us on Twitter and Facebook. If you have any problem or would like to add to the discussion, leave a comment below!