ProductQuery
Description
Retrieves a single product based on specified criteria. This query is useful when you need to fetch detailed information about a specific product.
Endpoint
query product($handle: [QueryArgument], $yuiId: [QueryArgument], $id: [QueryArgument]) {
product(handle: $handle, yuiId: $yuiId, id: $id) {
# Return fields
}
}
Arguments
| Argument | Type | Required | Description |
|---|---|---|---|
| handle | [QueryArgument] | No | Narrows the query results based on the handle on the product. |
| yuiId | [QueryArgument] | No | Narrows the query results based on the YUI ID on the product. |
| price | [QueryArgument] | No | Narrows the query results based on the price on the product. |
| price_incl_tax | [QueryArgument] | No | Narrows the query results based on the price including tax on the product. |
| price_excl_tax | [QueryArgument] | No | Narrows the query results based on the price excluding tax on the product. |
| specialPrice | [QueryArgument] | No | Narrows the query results based on the special price on the product. |
| special_price_incl_tax | [QueryArgument] | No | Narrows the query results based on the special price including tax on the product. |
| special_price_excl_tax | [QueryArgument] | No | Narrows the query results based on the special price excluding tax on the product. |
| type | [String] | No | Narrows the query results based on the product type the products belong to per the product type's handles. |
Common Element Arguments
In addition to the specific arguments above, this query also supports common element arguments:
| Argument | Type | Required | Description |
|---|---|---|---|
| id | [QueryArgument] | No | Narrows the query results based on the element's ID. |
| uid | [String] | No | Narrows the query results based on the element's UID. |
| status | [String] | No | Narrows the query results based on the element's status. |
| title | [String] | No | Narrows the query results based on the element's title. |
| slug | [String] | No | Narrows the query results based on the element's slug. |
| siteId | Int | No | Determines which site to fetch results from. |
Return Values
The query returns a single Product object with the following fields:
| Field | Type | Description |
|---|---|---|
| id | ID | The unique identifier for the product. |
| title | String | The title of the product. |
| handle | String | The handle of the product. |
| yuiId | String | The YUI ID of the product. |
| price | Float | The base price of the product. |
| price_incl_tax | Float | The price including tax of the product. |
| price_excl_tax | Float | The price excluding tax of the product. |
| specialPrice | Float | The special price of the product, if applicable. |
| special_price_incl_tax | Float | The special price including tax of the product, if applicable. |
| special_price_excl_tax | Float | The special price excluding tax of the product, if applicable. |
| type | String | The type of the product. |
| url | String | The URL of the product. |
| ... | ... | Additional fields depending on the product type. |
Usage Example
query {
product(handle: "sample-product-1") {
id
title
handle
price
price_incl_tax
url
}
}
Example Response
{
"data": {
"product": {
"id": "123",
"title": "Sample Product 1",
"handle": "sample-product-1",
"price": 19.99,
"price_incl_tax": 23.99,
"url": "/products/sample-product-1"
}
}
}
Notes
- This query returns a single product. If multiple products match the criteria, only the first one will be returned.
- It's recommended to use a unique identifier like
id,handle, oryuiIdto ensure you get the specific product you're looking for. - If no product matches the criteria, the query will return
null. - The
QueryArgumenttype allows for various comparison operators, but when querying for a single product, it's usually best to use exact matching. - The available fields in the response depend on the product type and may include custom fields defined in your product types.