Skip to Content

countries

Retrieve a list of all available countries for the store.

Query Structure

query { countries { id name code } }

Arguments

This query does not accept any arguments.

ArgumentTypeDescriptionRequiredDefault
No arguments available for this queryNoN/A

Return Type

countries returns an array of Country objects.

Country Type Fields

FieldTypeDescription
idIntUnique identifier of the country
nameStringFull name of the country
codeStringISO country code (e.g., “US”)

Examples

Basic Query

query { countries { id name } }

Advanced Query

query { countries { id name code } }

Field Selection

query { countries { name code } }

cURL Example

curl -X POST https://www.mystoreurl.com/graphql/0.8.0 \ -H "Content-Type: application/json" \ -d '{"query":"query { countries { id name code } }"}'

JavaScript Example

async function fetchCountries() { const query = ` query { countries { id name code } } `; try { const response = await fetch('https://www.mystoreurl.com/graphql/0.8.0', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ query }), }); const { data, errors } = await response.json(); if (errors) { console.error('GraphQL errors:', errors); return null; } return data.countries; } catch (error) { console.error('Network error:', error); return null; } }

Response Format

The response contains a countries field with an array of country objects:

{ "data": { "countries": [ { "id": 1, "name": "United States", "code": "US" }, { "id": 2, "name": "Canada", "code": "CA" } // ... more countries ] } }

Error Handling

Error CodeDescriptionHandling Recommendation
400Bad Request - malformed queryVerify query syntax and structure
500Internal Server ErrorRetry after some time or contact support
Network ErrorFailure to reach the API endpointCheck network connectivity and endpoint URL

GraphQL errors will be returned in the errors array in the response JSON. Always check for errors before processing data.

Performance Considerations

  • The countries query returns all countries without pagination; response size is typically small and performant.
  • Avoid requesting unnecessary fields to reduce payload size.
  • Cache the list of countries on the client side as this data changes infrequently.
  • Rate limiting may apply; handle HTTP 429 responses gracefully by implementing retries with exponential backoff.

Authentication

This API currently does not require authentication. However, authentication requirements may be introduced in future versions. Monitor API updates for any changes to authentication requirements.

Country

FieldTypeDescription
idIntUnique identifier of the country
nameStringFull name of the country
codeStringISO country code (e.g., “US”)

Notes

  • The countries query provides a simple way to retrieve all countries supported by the store.
  • Since no arguments are accepted, filtering or pagination is not available for this query.
  • Use this query to populate country selectors or validate country inputs in your application.
Last updated on