Examples

Introduction

In the following sections you'll find several sample queries ready to execute in the GraphQL playground. Remember to set the headers section with the connector and authorization entries as explained in the GraphQL Schema page.

You may experiment with the GraphQL playground using the Bloomreach Content public developer environment and Bloomreach Discovery Connector by specifying the following connector and br-acct-env headers in the HEADERS tab below the playground's query input field:

{
  "connector":"brsm",
  "br-acct-env": "developers"
}

Enter your query and click on Try It! and you should see the response as in the following screenshot:

897

Find items by keyword

Search for all the products by a specified keyword. Return 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:

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 } } }  }}"}'

Result:

{
  "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

Return a list of all product categories

Query:

query ListAllCategories {
  findCategories {
    id
    parentId
    displayName
    path
  }
}

cURL:

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 } }"}'

Result:

{
  "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

Add an item and the corresponding quantity to the shopping cart. As result, return the cart content.

🚧

Limitation:

The cart operations can be only executed against the commerce backends. In this case, it is necessary to set the right HTTP header value for "connector" and "Authorization".

Query:

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
  }
}

Result:

{
  "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

Return the cart content with all the necessary information to build the 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" }

Result:

{
  "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"
        }
      ]
    }
  }
}