Skip to content

Get Country States

About

The countryStates query retrieves all states/provinces for a specific country. Use this query to:

  • Populate state/province dropdowns in address forms
  • Display available states for a selected country
  • Get state translations for multi-language support
  • Build location-based features and configurations
  • Retrieve state codes and names for validation
  • Support dynamic form field population
  • Display state-specific shipping and tax information

This query returns all states for a given country with optional translations and pagination support.

Arguments

ArgumentTypeDescription
countryIdInt!Numeric country ID to fetch states for.
firstIntNumber of states to return (forward pagination). Max: 100.
afterStringPagination cursor for forward navigation.
lastIntNumber of states for backward pagination. Max: 100.
beforeStringPagination cursor for backward navigation.

Possible Returns

FieldTypeDescription
idID!Unique state API identifier.
_idInt!Numeric state ID.
codeStringState code (e.g., 'CA' for California, 'ON' for Ontario).
defaultNameString!State name in default language.
countryIdInt!Associated country ID.
countryCodeString!Associated country code.
translationsStateTranslationCollection!All state translations.
translations.edges[Edge!]!Translation edges.
translations.edges.nodeStateTranslation!Individual translation.
translations.edges.node.idID!Translation ID.
translations.edges.node.localeString!Language locale code.
translations.edges.node.defaultNameString!Translated state name.
translations.totalCountInt!Total translations for this state.
edges[Edge!]!State edges with cursors.
edges.nodeCountryState!Individual state.
edges.cursorString!Pagination cursor.
pageInfoPageInfo!Pagination information.
pageInfo.hasNextPageBoolean!More states available.
pageInfo.hasPreviousPageBoolean!Previous states available.
pageInfo.startCursorStringFirst state cursor.
pageInfo.endCursorStringLast state cursor.
totalCountInt!Total states for this country.

Use Cases

1. Address Form State Dropdown

Use the "For Dropdown Form" example to populate state dropdown when user selects a country.

2. Multi-Language Support

Use the "With Translations" example to display state names in user's language.

3. Large State Lists

Use the "With Pagination" example for countries with many states (e.g., US with 50 states).

Best Practices

  1. Fetch on Country Selection - Load states dynamically when user selects a country
  2. Cache Per Country - Cache states for each country to reduce API calls
  3. Include Translations - Always fetch translations for multi-language forms
  4. Handle Empty States - Some countries have no states, handle gracefully
  5. Use State Code - Store state code, not just name, for consistency
  6. Sort Alphabetically - Present states in alphabetical order in dropdowns
  7. Minimize Fields - Request only code and name for dropdown optimization

State Codes

Common state code formats:

  • US States: 2-letter codes (AL, AK, AZ)
  • Canadian Provinces: 2-letter codes (ON, BC, QC)
  • European Regions: Various formats
  • Other Countries: May vary by country

Released under the MIT License.