How to Get Country List Using GraphQL in Magento 2

Do you want to know how to get all the available country list using GraphQL Query in Magento 2?

In this Magento 2 GraphQL Tutorial, We will show how to get all the available country list using GraphQL Query in Magento 2. We will use the {countries} query to get country list of your Magento instance.

Let’s start!

Get Countries List Query:

The {countries} query returns all countries listed for the current instance of Magento.

query {
    countries {
        id
        two_letter_abbreviation
        three_letter_abbreviation
        full_name_locale
        full_name_english
        available_regions {
            id
            code
            name
        }
    }
}

Output:

{
  "data": {
    "countries": [
      {
        "id": "AD",
        "two_letter_abbreviation": "AD",
        "three_letter_abbreviation": "AND",
        "full_name_locale": "Andorra",
        "full_name_english": "Andorra",
        "available_regions": null
      },
      {
        "id": "AE",
        "two_letter_abbreviation": "AE",
        "three_letter_abbreviation": "ARE",
        "full_name_locale": "United Arab Emirates",
        "full_name_english": "United Arab Emirates",
        "available_regions": null
      },
      {
        "id": "AF",
        "two_letter_abbreviation": "AF",
        "three_letter_abbreviation": "AFG",
        "full_name_locale": "Afghanistan",
        "full_name_english": "Afghanistan",
        "available_regions": null
      },
      {
        "id": "AG",
        "two_letter_abbreviation": "AG",
        "three_letter_abbreviation": "ATG",
        "full_name_locale": "Antigua and Barbuda",
        "full_name_english": "Antigua and Barbuda",
        "available_regions": null
      },
      {
        "id": "AT",
        "two_letter_abbreviation": "AT",
        "three_letter_abbreviation": "AUT",
        "full_name_locale": "Austria",
        "full_name_english": "Austria",
        "available_regions": [
          {
            "id": 102,
            "code": "BL",
            "name": "Burgenland"
          },
          {
            "id": 99,
            "code": "KN",
            "name": "Kärnten"
          },
          {
            "id": 96,
            "code": "NO",
            "name": "Niederösterreich"
          },
          {
            "id": 97,
            "code": "OO",
            "name": "Oberösterreich"
          },
          {
            "id": 98,
            "code": "SB",
            "name": "Salzburg"
          },
          {
            "id": 100,
            "code": "ST",
            "name": "Steiermark"
          },
          {
            "id": 101,
            "code": "TI",
            "name": "Tirol"
          },
          {
            "id": 103,
            "code": "VB",
            "name": "Vorarlberg"
          },
          {
            "id": 95,
            "code": "WI",
            "name": "Wien"
          }
        ]
      }
    ]
  }
}

In this example, You will get all the countries list of your Magento system. The available_regions attribute value will be null if the country does not have any regions available. Otherwise, it contains an array of the country’s regions.


You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.

How to Get Country List Using GraphQL in Magento 2 Click To Tweet

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!

You May Also Like

Editorial Staff

About the Author: Editorial Staff

Editorial Staff at the MageBeginners is a team of Magento experts writing about Magento Tutorials, Themes, Extensions, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *