GraphQL Examples

Info: This feature in Bloomreach Content requires a standard or premium license. Contact Bloomreach for licensing details.

Overview

This page provides example GraphQL queries for common commerce operations. You can execute these queries in the GraphQL Playground. Before running the examples, configure the required HTTP headers for the connector and authorization as described on the GraphQL Schema page.

Find Items by Keyword

This query searches for products matching a specified keyword and returns a paginated result set.

Query

query FindItemsByKeyword($text: String!, $offset: Int!, $limit: Int!) { findItemsByKeyword(text: $text, offset: $offset, limit: $limit) { offset limit count total queryHint { autoCorrectQuery autoCorrectQuerySet redirectHint { url query newQuery } } items { itemId { id code } displayName description imageSet { original { link { href } } thumbnail { link { href } } } listPrice { moneyAmounts { currency amount displayValue } } purchasePrice { moneyAmounts { currency amount displayValue } } salePriceRange priceRange customAttrs { name values } } facetResult { fields { id name values { id parentId name count } } } } }

Parameters

{
  "text": "bolt",
  "offset": 0,
  "limit": 2
}

cURL Example

curl 'https://graphql.eng-demo.bloomreach.io/graphql' \
  -H 'connector: brsm' \
  -H 'content-type: application/json' \
  -d '{"operationName":"FindItemsByKeyword","variables":{"text":"bolt","offset":0,"limit":1},"query":"query FindItemsByKeyword($text: String!, $offset: Int, $limit: Int) {  findItemsByKeyword(text: $text, offset: $offset, limit: $limit) { offset limit count    total    queryHint { autoCorrectQuery      autoCorrectQuerySet      redirectHint { url query newQuery } }items { itemId { id code } displayName description imageSet { original { link { href } } thumbnail { link { href }}} listPrice { moneyAmounts { currency amount displayValue } }  purchasePrice { moneyAmounts {currency amount displayValue}} salePriceRange priceRange customAttrs { name values } } facetResult { fields { id name values {  id  parentId name count } } }  }}"}' 

Sample Response

{ "data": { "findItemsByKeyword": { "offset": 0, "limit": 2, "count": 2, "total": 62, "queryHint": { "autoCorrectQuery": null, "autoCorrectQuerySet": [], "redirectHint": null }, "items": [ { "itemId": { "id": "4427935", "code": "4427935" }, "displayName": "Cully 1/4 x 3 Hanger Bolt", "description": "Cully 66148J 1/4 x 3 Hanger Bolt, Zinc (100/Jar)", "imageSet": { "original": { "link": { "href": "https://pacific-demo-data.bloomreach.cloud/supply/images/thumbimage_pid_4427935.jpg" } }, "thumbnail": { "link": { "href": "https://pacific-demo-data.bloomreach.cloud/supply/images/thumbimage_pid_4427935.jpg" } } }, "listPrice": { "moneyAmounts": [ { "currency": null, "amount": 5.48, "displayValue": "5.48" } ] }, "purchasePrice": { "moneyAmounts": [ { "currency": null, "amount": 3.46, "displayValue": "3.46" } ] }, "salePriceRange": [ 3.46, 3.46 ], "priceRange": [ 5.48, 5.48 ], "customAttrs": [] }, //...SNIP... ], "facetResult": { "fields": [ { "id": "category", "name": "category", "values": [ { "id": "PNB250881031400", "parentId": "PNB250881030000", "name": "Open-End Wrenches", "count": 1 }, //...SNIP... ] }, { "id": "sizes", "name": "sizes", "values": [ { "id": ".750 x 20", "parentId": null, "name": ".750 x 20", "count": 1 }, //...SNIP... ] }, { "id": "brand", "name": "brand", "values": [ { "id": "Greenlee", "parentId": null, "name": "Greenlee", "count": 11 }, //...SNIP... ] }, { "id": "colors", "name": "colors", "values": [ { "id": "silver", "parentId": null, "name": "silver", "count": 10 } ] } ] } } } }

List All Categories

This query retrieves all product categories.

Query

query ListAllCategories { findCategories { id parentId displayName path } }

cURL Example

curl 'https://graphql.eng-demo.bloomreach.io/graphql' \
  -H 'connector: brsm' \
  -H 'content-type: application/json' \
  -d '{"operationName":"ListAllCategories","variables":{}, "query":"query ListAllCategories { findCategories { id parentId displayName path } }"}'

Sample Response

{ "data": { "findCategories": [ { "id": "a41b6ba2-ce57-4ce5-b5c2-bcd0ff084b6e", "parentId": "4a6bab71-ec37-49d5-a1a7-f7d9eb782994", "displayName": "Low-Carb & Keto", "path": null }, { "id": "b4b51d56-b587-408f-9cb8-f5c21ef54e58", "parentId": "cbd0c34b-61e1-4a27-b1f8-9cb101d01013", "displayName": "Accessories", "path": null }, { "id": "b7121b70-443d-4085-9728-81f117ac3eba", "parentId": "7ab87c3e-f6b9-405f-b48a-291375d4029a", "displayName": "Saute & Chef Pans", "path": null }, // ...SNIP... ] } }

Add an Item to the Cart

This mutation adds a specified item and quantity to the shopping cart. The response includes the updated cart content.

Cart operations are supported only for configured commerce backends. Set the correct values for the connector and Authorization HTTP headers.

Mutation

mutation AddToCart($addToCartInput: AddToCartInput!) { addToCart(addToCartInput: $addToCartInput) { code success message cart { id totalQuantity revision entries { id quantity items { itemId { id code } displayName } } } } }

Parameters

{
  "addToCartInput": {
    "itemId": "var1-d8489100-e89c-470a-a12a-d3bf1b521851___IN17642",
    "quantity": 3
  }
}

Sample Response

{ "data": { "addToCart": { "code": "200", "success": true, "message": "Successfully added to cart", "cart": { "id": "e6e94ef4-9370-4729-84c4-72bc85112dd7", "totalQuantity": 9, "revision": 61, "entries": [ { "id": "e9e3596c-a597-438b-ba2f-fa09ff4dd31a", "quantity": 8, "items": [ { "itemId": { "id": "var1-d8489100-e89c-470a-a12a-d3bf1b521851", "code": "IN17642" }, "displayName": "VINTAGE CAP" } ] }, { "id": "d2e68cf3-43bb-41ba-95d2-112ebbfc3e70", "quantity": 1, "items": [ { "itemId": { "id": "var1-f0ceb81b-a588-445c-9b0f-eb9c4d709099", "code": "LeCreuset_Frypan" }, "displayName": "Le Creuset Cast Iron Frypan" } ] } ] } } } }

Get the Cart Content

This query returns the contents of a shopping cart, including all details required to render the cart page.

Query

query GetCart ($cartId: String){ getCart(id: $cartId) { id totalQuantity orderId revision active state entries { id quantity items { itemId { id code } displayName imageSet { original { link { href } } thumbnail { link { href } } } listPrice { moneyAmounts { currency amount } } } } totalListPrice { moneyAmounts { currency amount } } totalPurchasePrice { moneyAmounts { currency amount } } discounts { code targetIds type } } }

Parameters

{ "cartId": "e6e94ef4-9370-4729-84c4-72bc85112dd7" }

Sample Response

{ "data": { "getCart": { "id": "e6e94ef4-9370-4729-84c4-72bc85112dd7", "totalQuantity": 18, "orderId": null, "revision": 67, "active": true, "state": "Active", "entries": [ { "id": "e9e3596c-a597-438b-ba2f-fa09ff4dd31a", "quantity": 17, "items": [ { "itemId": { "id": "var1-d8489100-e89c-470a-a12a-d3bf1b521851", "code": "IN17642" }, "displayName": "VINTAGE CAP", "imageSet": { "original": { "link": { "href": "https://acc545be1d5fd66d9268-e6ee5bd70ad552747c060c238eaa7bc8.ssl.cf3.rackcdn.com/in17642-a-hXwF_lvK.jpg" } }, "thumbnail": { "link": { "href": "https://acc545be1d5fd66d9268-e6ee5bd70ad552747c060c238eaa7bc8.ssl.cf3.rackcdn.com/in17642-a-hXwF_lvK.jpg" } } }, "listPrice": { "moneyAmounts": [ { "currency": "USD", "amount": 21 }, { "currency": "EUR", "amount": 18 } ] } } ] }, { "id": "d2e68cf3-43bb-41ba-95d2-112ebbfc3e70", "quantity": 1, "items": [ { "itemId": { "id": "var1-f0ceb81b-a588-445c-9b0f-eb9c4d709099", "code": "LeCreuset_Frypan" }, "displayName": "Le Creuset Cast Iron Frypan", "imageSet": { "original": { "link": { "href": "https://acc545be1d5fd66d9268-e6ee5bd70ad552747c060c238eaa7bc8.ssl.cf3.rackcdn.com/Le-Creuset-Cast-Iron-v9WN1BKB.jpg" } }, "thumbnail": { "link": { "href": "https://acc545be1d5fd66d9268-e6ee5bd70ad552747c060c238eaa7bc8.ssl.cf3.rackcdn.com/Le-Creuset-Cast-Iron-DRv6e_Cq.jpg" } } }, "listPrice": { "moneyAmounts": [ { "currency": "EUR", "amount": 229 }, { "currency": "USD", "amount": 300 } ] } } ] } ], "totalListPrice": { "moneyAmounts": [ { "currency": "USD", "amount": 657 } ] }, "totalPurchasePrice": { "moneyAmounts": [ { "currency": "USD", "amount": 657 } ] }, "discounts": [ { "code": "5396f9cd-6f95-438e-8f2b-802a15dc1fa3", "targetIds": [], "type": "Promotion" } ] } } }
Share Feedback
Page: /frontend/commerce-accelerator/brx-graphql-service/gql-examples
Section: Frontend
Category *
GraphQL Examples | Bloomreach Content Documentation