productReview
Fetch product reviews
Signature
declare function productReview(
context: Context,
searchParams?: GetProductSearchParams,
customQuery?: CustomQuery,
customHeaders?: CustomHeaders
): Promise<ApolloQueryResult<ProductsQuery>>;Parameters
| Name | Required | Type | Description |
|---|---|---|---|
context | Required | Context | |
searchParams | Optional | GetProductSearchParams | |
customQuery | Optional | CustomQuery | |
customHeaders | Optional | CustomHeaders |
Referenced Types
- Context
- GetProductSearchParams
- CustomQuery
- CustomHeaders
ApolloQueryResultProductsQuery
Examples
Simple usage:
import { sdk } from '~/sdk.config.ts';
// fetch all products reviews (default pagination limit is 10)
const result = await sdk.magento.productReview({});Fetching reviews for a specific product:
import { sdk } from '~/sdk.config.ts';
const result = await sdk.magento.productReview({ filter: { sku: { eq: '24-MB01' } );Creating a custom GraphQL query
module.exports = {
integrations: {
magento: {
customQueries: {
'product-review-custom-query': ({ variables, metadata }) => ({
variables,
query: `
query productReview($search: String = "", $filter: ProductAttributeFilterInput, $pageSize: Int = 10, $currentPage: Int = 1, $sort: ProductAttributeSortInput) {
products(search: $search, filter: $filter, sort: $sort) {
items {
review_count
reviews(pageSize: $pageSize, currentPage: $currentPage) {
items {
${metadata?.fields}
}
}
}
}
}
`
}),
},
}
}
};Using a custom GraphQL query to change the amount of fields returned by the query:
import { sdk } from '~/sdk.config.ts';
// reduce the amount of fields returned by the query, when compared to the default query
const customQuery = {
productReview: 'product-review-custom-query',
metadata: {
fields: 'average_rating'
}
};
const result = await sdk.magento.productReview({}, customQuery);
// result.data.products.items[0].reviews.items[0] will only contain the average_rating field