Queries
route
What is published at a store path: a product, category, brand, collection or redirect.
route tells you what is published at a store path and returns it in full. Use it in your frontend's catch-all route.
route(path: String!, previewKey: String): UrlResolutionArguments
| Argument | Type | Rule |
|---|---|---|
path | String! | The path, without domain or query. An empty one returns BAD_USER_INPUT. |
previewKey | String | The key from the admin preview link. With a valid key, an unpublished product also comes back. |
If nothing matches, route is null.
UrlResolution
| Field | Type | Description |
|---|---|---|
kind | String! | product, category, brand, collection or redirect. |
url | String! | The resource's current URL. |
handle | String | The resource slug. null with redirect. |
product | ProductDetail | The product page data, with kind: "product". See product. |
category | CategoryDetail | The category, with kind: "category". |
brand | BrandDetail | The brand, with kind: "brand". See brand. |
collection | CollectionItem | The collection, with kind: "collection". See collections. |
- With
redirect, redirect tourlwith a301. It happens with old URLs, uppercase paths or a trailing/. - An unpublished product that comes with
previewKeyhasisPreview: true: don't cache it or index it.
CategoryDetail
| Field | Type | Description |
|---|---|---|
id | String! | Category ID. |
name | String! | Name. |
slug | String! | Slug. |
url | String! | Public path of the category. |
description | String | Description. |
imageUrl | String | Image. |
metaTitle | String | Title for search engines. |
metaDescription | String | Description for search engines. |
parentId | String | ID of the parent category. |
productCount | Int! | Number of products. |
ancestors | [CategoryLink!]! | From the root to the parent, for breadcrumbs. |
children | [CategoryItem!]! | Subcategories. |
products(input: StorefrontProductsInput) | SearchResult! | Products in the category and its subcategories. |
products takes the same input as products and ignores categories.
| Type | Fields |
|---|---|
CategoryLink | id: String!, name: String!, url: String! |
CategoryItem | id: String!, name: String!, slug: String!, url: String!, imageUrl: String, parentId: String, path: String!, order: Int!, productCount: Int! |
Example
query Route($path: String!) {
route(path: $path) {
kind
url
product { id name price }
category {
id
name
ancestors { name url }
products(input: { pageSize: 24, includeFilters: false }) {
totalPages
products { id name url imageUrl price }
}
}
brand { id name }
collection { id name }
}
}curl --request POST "https://storefront.ecomiq.pe/graphql" \
--header "Content-Type: application/json" \
--header "x-Store-Domain: my-store" \
--data-binary '{
"query": "query Route($path: String!) { route(path: $path) { kind url product { id name price } category { id name ancestors { name url } products(input: { pageSize: 24, includeFilters: false }) { totalPages products { id name url imageUrl price } } } brand { id name } collection { id name } } }",
"variables": { "path": "/categories/t-shirts" }
}'{
"data": {
"route": {
"kind": "category",
"url": "/categories/t-shirts",
"product": null,
"category": {
"id": "7204558912004327982",
"name": "T-shirts",
"ancestors": [{ "name": "Men", "url": "/categories/men" }],
"products": {
"totalPages": 1,
"products": [
{
"id": "7204558912004322039",
"name": "Pima cotton T-shirt",
"url": "/products/pima-cotton-t-shirt",
"imageUrl": "https://…/t-shirt.webp",
"price": 59.9
}
]
}
},
"brand": null,
"collection": null
}
}
}Errors
| Code | Cause |
|---|---|
BAD_USER_INPUT | path is empty. |
STORE_CONTEXT_REQUIRED | x-Store-Domain is missing or doesn't match a store. |
REST equivalent
GET / returns the same, without the fields that only GraphQL has, such as products or related. If nothing matches, it returns 404 Url.NotFound.
Last updated: