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.
Argument | Type | Description | Required | Default |
---|---|---|---|---|
— | — | No arguments available for this query | No | N/A |
Return Type
countries
returns an array of Country
objects.
Country Type Fields
Field | Type | Description |
---|---|---|
id | Int | Unique identifier of the country |
name | String | Full name of the country |
code | String | ISO 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 Code | Description | Handling Recommendation |
---|---|---|
400 | Bad Request - malformed query | Verify query syntax and structure |
500 | Internal Server Error | Retry after some time or contact support |
Network Error | Failure to reach the API endpoint | Check 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.
Related Types
Country
Field | Type | Description |
---|---|---|
id | Int | Unique identifier of the country |
name | String | Full name of the country |
code | String | ISO 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