menus
Retrieve all link lists (navigation menus) available in the store.
Query Structure
query {
menus {
id
title
items {
id
title
url
type
}
}
}
Arguments
Argument | Type | Description | Required | Default |
---|---|---|---|---|
None | This query does not accept any arguments. | No | N/A |
Return Type
menus
returns a list of Menu
objects. Each Menu
contains the following fields:
id
(Integer): Unique identifier of the menu.title
(String): The display title of the menu.items
(Array ofMenuItem
): List of menu items belonging to the menu.
Each MenuItem
includes:
id
(Integer): Unique identifier of the menu item.title
(String): The display title of the menu item.url
(String): The URL the menu item points to.type
(String): The type of the menu item (e.g., “link”, “collection”, “product”).
Examples
Basic Query
query {
menus {
id
title
}
}
Advanced Query
query {
menus {
id
title
items {
id
title
url
type
}
}
}
Field Selection
query {
menus {
title
items {
title
url
}
}
}
cURL Example
curl -X POST https://www.mystoreurl.com/graphql/0.8.0/ \
-H "Content-Type: application/json" \
-d '{"query":"query { menus { id title items { id title url type } } }"}'
JavaScript Example
async function fetchMenus() {
const query = `
query {
menus {
id
title
items {
id
title
url
type
}
}
}
`;
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.menus;
} catch (error) {
console.error('Network error:', error);
return null;
}
}
// Usage example
fetchMenus().then(menus => {
if (menus) {
console.log('Menus:', menus);
}
});
Response Format
The response contains a data
object with a menus
array. Each element in the array is a Menu
object with its fields and nested items
array.
Example response snippet:
{
"data": {
"menus": [
{
"id": 1,
"title": "Main Menu",
"items": [
{
"id": 101,
"title": "Home",
"url": "/",
"type": "link"
},
{
"id": 102,
"title": "Shop",
"url": "/collections/all",
"type": "collection"
}
]
},
{
"id": 2,
"title": "Footer Menu",
"items": [
{
"id": 201,
"title": "Contact Us",
"url": "/contact",
"type": "link"
}
]
}
]
}
}
Error Handling
Possible errors when querying menus
include:
Error Code | Description | Resolution |
---|---|---|
400 | Malformed query or invalid syntax | Verify query structure and syntax correctness. |
500 | Internal server error | Retry after some time or contact support. |
429 | Rate limit exceeded | Slow down request frequency and retry later. |
If the response contains an errors
array, inspect the error messages for details.
Performance Considerations
- The
menus
query returns all menus and their items in a single request. For stores with a large number of menus or menu items, consider selecting only necessary fields to reduce payload size. - There is no built-in pagination or filtering for this query; avoid requesting unnecessary nested fields to optimize response time.
- Rate limits apply to all API requests; implement exponential backoff or retry logic on
429
errors. - Responses may be cached on the client side to reduce repeated requests for menu data that changes infrequently.
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
Menu
Field | Type | Description |
---|---|---|
id | Int | Unique identifier of the menu. |
title | String | Display title of the menu. |
items | [MenuItem] | List of menu items. |
MenuItem
Field | Type | Description |
---|---|---|
id | Int | Unique identifier of the menu item. |
title | String | Display title of the menu item. |
url | String | URL the menu item points to. |
type | String | Type of menu item (e.g., link). |
Notes
- This query does not accept any arguments; it returns all menus.
- Use field selection to limit the data returned and improve performance.
- The
type
field inMenuItem
helps determine how to handle or display the menu item in client applications. - Because menus typically change infrequently, consider caching the results on the client side.
Last updated on