GraphQL Reference
This section describes the GraphQL schema provided by the Improved Sorting extension for managing pinned products functionality.
For general information about GraphQL in Magento, refer to the GraphQL Developer Guide.
Extended Magento Objects
The extension adds new fields to standard Magento GraphQL types.
ProductInterface
The ProductInterface is extended with the following fields:
| Field | Description | Data Type |
|---|---|---|
| pinned_category_ids | Array of category IDs where the product is pinned to top. | [Int] |
| pin_to_top | Indicates if the product is pinned to top in the current category context. Returns null if no category context is available. | Boolean |
CategoryInterface / CategoryTree
The CategoryInterface and CategoryTree types are extended with the following field:
| Field | Description | Data Type |
|---|---|---|
| pinned_product_ids | Array of product IDs that are pinned to top in the category. | [Int] |
Sorting Input
The extension adds sorting options to the ProductAttributeSortInput type:
| Field | Description | Data Type |
|---|---|---|
| mst_sort | Apply a custom sorting criterion by code. | MstSortCriteria |
| mst_pin | When set to true, pinned products are returned first. | Boolean |
MstSortCriteria
| Input | Description | Data Type |
|---|---|---|
| code | The code of the sorting criterion to apply. | String |
| dir | Sort direction: ASC or DESC. | SortEnum |
Mutations
The extension provides two mutations for managing pinned products. Both mutations require admin authorization with the Mirasvit_Sorting::sorting ACL resource.
setPinnedCategories
Sets the categories where a product should be pinned to top.
Input:
| Field | Description | Data Type |
|---|---|---|
| product_id | The product ID. | Int! |
| category_ids | Array of category IDs where the product should be pinned. | [Int!]! |
Output (PinnedCategoriesOutput):
| Field | Description | Data Type |
|---|---|---|
| success | Indicates if the operation was successful. | Boolean! |
| message | Result message. | String |
| product_id | The product ID. | Int |
| category_ids | Updated array of category IDs where the product is pinned. | [Int] |
setPinnedProducts
Sets the products that should be pinned to top in a category.
Input:
| Field | Description | Data Type |
|---|---|---|
| category_id | The category ID. | Int! |
| product_ids | Array of product IDs to pin in the category. | [Int!]! |
Output (PinnedProductsOutput):
| Field | Description | Data Type |
|---|---|---|
| success | Indicates if the operation was successful. | Boolean! |
| message | Result message. | String |
| category_id | The category ID. | Int |
| product_ids | Updated array of pinned product IDs. | [Int] |
Usage Examples
Query pinned products in a category
Retrieve a category with its pinned product IDs:
query {
category(id: 10) {
id
name
pinned_product_ids
}
}
Response:
{
"data": {
"category": {
"id": 10,
"name": "Gear",
"pinned_product_ids": [42, 58, 103]
}
}
}
Query product with pinned categories
Retrieve a product and see which categories it is pinned in:
query {
products(filter: { sku: { eq: "24-MB01" } }) {
items {
id
name
sku
pinned_category_ids
}
}
}
Response:
{
"data": {
"products": {
"items": [
{
"id": 1,
"name": "Joust Duffle Bag",
"sku": "24-MB01",
"pinned_category_ids": [3, 10]
}
]
}
}
}
Query products with pin_to_top status
When querying products within a category context, the pin_to_top field indicates if each product is pinned:
query {
products(
filter: { category_id: { eq: "10" } }
sort: { mst_pin: true }
) {
items {
id
name
pin_to_top
}
}
}
Response:
{
"data": {
"products": {
"items": [
{
"id": 42,
"name": "Affirm Water Bottle",
"pin_to_top": true
},
{
"id": 58,
"name": "Sprite Yoga Strap",
"pin_to_top": true
},
{
"id": 15,
"name": "Compete Track Tote",
"pin_to_top": false
}
]
}
}
}
Pin a product to categories
Pin product ID 42 to categories 3 and 10:
mutation {
setPinnedCategories(
input: {
product_id: 42
category_ids: [3, 10]
}
) {
success
message
product_id
category_ids
}
}
Response:
{
"data": {
"setPinnedCategories": {
"success": true,
"message": "Pinned categories updated successfully.",
"product_id": 42,
"category_ids": [3, 10]
}
}
}
Pin products to a category
Pin products 42, 58, and 103 to category ID 10:
mutation {
setPinnedProducts(
input: {
category_id: 10
product_ids: [42, 58, 103]
}
) {
success
message
category_id
product_ids
}
}
Response:
{
"data": {
"setPinnedProducts": {
"success": true,
"message": "Pinned products updated successfully.",
"category_id": 10,
"product_ids": [42, 58, 103]
}
}
}
Remove all pins from a product
To unpin a product from all categories, pass an empty array:
mutation {
setPinnedCategories(
input: {
product_id: 42
category_ids: []
}
) {
success
message
category_ids
}
}
Authorization
The setPinnedCategories and setPinnedProducts mutations require:
- An authenticated admin user (integration token)
- The
Mirasvit_Sorting::sortingACL resource permission
Attempting to execute these mutations without proper authorization returns an error:
{
"errors": [
{
"message": "The current user is not authorized to manage pinned products."
}
]
}
Query operations (pinned_category_ids, pinned_product_ids, pin_to_top) do not require authentication and can be used in storefront applications.