How to generate Customer token GraphQL Query Magento 2?

Generate Customer Token GraphQL mutation for any query that requires customer authentication to load data using GraphQL.

generateCustomerToken() mutation is used to create a token.

You just have to pass your email id and password to the mutation to create a customer token. Continue reading “How to generate Customer token GraphQL Query Magento 2?”

How to Get Cross Sell Product GraphQL Query Magento 2?

Cross-Sell Product GraphQL Query in Magento 2 to get all the cross-sell items as an output with GraphQL response.

You can fetch the Cross-sell Product from the Product GraphQL Query by applying the product SKU as a filter name.

Before going with the current article, Check full details of Product Query, Brief details of Product Query GraphQL in Magento.

Cross-Sell Product GraphQL Query Magento 2 Payload,

{
  products(filter: { sku: { eq: "24-MB01" } }) {
    items {
      id
      name
      crosssell_products {
        id
        sku
        stock_status
        short_description {
          html
        }
        url_key
        name
        special_price
        price_range {
          minimum_price {
            final_price {
              value
              currency
            }
          }
          maximum_price {
            final_price {
              value
              currency
            }
          }
        }
      }
    }
  }
}

crosssell_products{} field used to retrieve cross-sell items of the product. You can set any field to retrieve as output from the Product Query.

Output for the Magento Sample Data,

{
  "data": {
    "products": {
      "items": [
        {
          "id": 1,
          "name": "Joust Duffle Bag",
          "crosssell_products": [
            {
              "id": 20,
              "sku": "24-UG01",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "quest-lumaflex-trade-band",
              "name": "Quest Lumaflex™ Band",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 19,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 19,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 32,
              "sku": "24-WG083-blue",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "sprite-stasis-ball-75-cm-blue",
              "name": "Sprite Stasis Ball 75 cm",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 32,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 32,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 34,
              "sku": "24-WG086",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "sprite-yoga-strap-8-foot",
              "name": "Sprite Yoga Strap 8 foot",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 17,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 17,
                    "currency": "USD"
                  }
                }
              }
            },
            {
              "id": 51,
              "sku": "24-WG085_Group",
              "stock_status": "IN_STOCK",
              "short_description": {
                "html": ""
              },
              "url_key": "set-of-sprite-yoga-straps",
              "name": "Set of Sprite Yoga Straps",
              "special_price": null,
              "price_range": {
                "minimum_price": {
                  "final_price": {
                    "value": 14,
                    "currency": "USD"
                  }
                },
                "maximum_price": {
                  "final_price": {
                    "value": 14,
                    "currency": "USD"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  }
}

You can add/remove the field based on your requirement in the product Query. This is the demonstration purpose only.

You can also interested to read GraphQL Query,

  1. Get Related Product GraphQL Query in Magento 2.
  2. Get Upsell Product GraphQL Query Magento 2.

How to Use cmsPage and cmsBlocks GraphQL Query in Magento 2?

cmsPage and cmsBlocks GraphQL Query Magento used to display CMS related information.

You can use cmsPage for the CMS Page related data whereas cmsBlock used to display CMS Static Block related information.

schema.graphql file for the CMS module will be available on file, vendor/magento/module-cms-graph-ql/etc/schema.graphqls Continue reading “How to Use cmsPage and cmsBlocks GraphQL Query in Magento 2?”