Skip to content

Get Countries

About

The countries query retrieves all available countries and their states/provinces configured in your Bagisto store. Use this query to:

  • Build country/region selector dropdowns for addresses
  • Display available shipping destinations
  • Create address form fields with country and state options
  • Implement multi-language country names and state names
  • Display shipping country restrictions
  • Build geographic-based features and configurations
  • Populate checkout address forms with country and state data
  • Support currency and language selection based on country

This query returns comprehensive country data including all states, translations for countries and states, and pagination support for large country lists.

Arguments

ArgumentTypeDescription
firstIntNumber of countries to return (forward pagination). Max: 100.
afterStringPagination cursor for forward navigation.
lastIntNumber of countries for backward pagination. Max: 100.
beforeStringPagination cursor for backward navigation.

Possible Returns

FieldTypeDescription
idID!Unique country API identifier.
_idInt!Numeric country ID.
codeString!ISO 3166-1 alpha-2 country code (e.g., 'US', 'GB', 'AE').
nameString!Country name in default language.
statesCountryStateCollection!States/provinces for this country.
states.edges[Edge!]!State edges with cursors.
states.edges.nodeCountryState!Individual state information.
states.edges.node.idID!State API identifier.
states.edges.node._idInt!Numeric state ID.
states.edges.node.codeStringState code (e.g., 'CA' for California).
states.edges.node.defaultNameString!State name in default language.
states.edges.node.countryIdInt!Associated country ID.
states.edges.node.countryCodeString!Associated country code.
states.edges.node.translationCountryStateTranslation!State translation in current locale.
states.edges.node.translation.idID!Translation identifier.
states.edges.node.translation._idInt!Numeric translation ID.
states.edges.node.translation.countryStateIdInt!Associated state ID.
states.edges.node.translation.localeString!Language locale code.
states.edges.node.translation.defaultNameString!State name in locale language.
states.edges.node.translationsStateTranslationCollection!All state translations.
states.edges.node.translations.edges[Edge!]!Translation edges.
states.edges.node.translations.edges.node.idID!Translation ID.
states.edges.node.translations.edges.node.localeString!Locale code.
states.edges.node.translations.edges.node.defaultNameString!Translated state name.
states.pageInfoPageInfo!Pagination info for states.
states.pageInfo.hasNextPageBoolean!More states available.
states.pageInfo.hasPreviousPageBoolean!Previous states available.
states.pageInfo.startCursorStringFirst state cursor.
states.pageInfo.endCursorStringLast state cursor.
states.totalCountInt!Total states for this country.
translationsCountryTranslationCollection!All country translations.
translations.edges[Edge!]!Translation edges with cursors.
translations.edges.nodeCountryTranslation!Individual translation.
translations.edges.node.idID!Translation identifier.
translations.edges.node._idInt!Numeric translation ID.
translations.edges.node.countryIdInt!Associated country ID.
translations.edges.node.localeString!Language locale code (e.g., 'en', 'ar', 'fr').
translations.edges.node.nameString!Country name in locale language.
translations.edges.cursorString!Pagination cursor for this translation.
translations.pageInfoPageInfo!Pagination information for translations.
translations.totalCountInt!Total translations for this country.
pageInfoPageInfo!Pagination information.
pageInfo.hasNextPageBoolean!More countries available.
pageInfo.hasPreviousPageBoolean!Previous countries available.
pageInfo.startCursorStringFirst country cursor.
pageInfo.endCursorStringLast country cursor.
totalCountInt!Total countries in system.

Use Cases

1. Address Form

Use the "For Address Form" example to populate country and state dropdowns in checkout forms.

2. Multi-Language Support

Use the "With All Translations" example to display country names in all supported languages.

3. Shipping Configuration

Use the "Basic" example to get all available shipping destinations.

4. Pagination

Use the "With Pagination" example to handle large country lists efficiently.

5. Complete Data

Use the "With States" example to get all country and state information at once.

Best Practices

  1. Cache Countries Data - Countries rarely change, cache the entire list
  2. Load Countries on App Init - Fetch and store countries when application starts
  3. Support State Selection - Always fetch states for proper address forms
  4. Use Translations - Fetch translations for all supported languages
  5. Optimize Field Selection - Request only fields needed for your use case
  6. Pagination for Mobile - Use pagination on mobile to reduce data transfer
  7. Sort by Frequency - Display most-used countries first in UI

State Availability

Some countries may have states configured, while others may not:

  • Countries with states: US (50+), Canada, India, etc.
  • Countries without states: Many smaller countries return empty states collection
  • Always check totalCount to determine if states are available

Released under the MIT License.