GraphQL_Processor
This class is responsible for handling GraphQL requests in the BigCommerce API context.
It includes methods to fetch various data types like terms, products, product reviews, and customer wishlists. It communicates with the GraphQL API using pre-defined queries and returns the results in a structured format. The class utilizes a configuration object for API settings and a query object for constructing GraphQL queries.
- Full name:
\BigCommerce\GraphQL\GraphQL_Processor - Parent class:
\BigCommerce\GraphQL\BaseGQL
Properties
query
protected mixed $queryMethods
__construct
Constructor to initialize the GraphQL processor with a configuration and query.
public __construct(\BigCommerce\Api\v3\Configuration $config, mixed $query): voidParameters:
| Parameter | Type | Description |
|---|---|---|
$config | \BigCommerce\Api\v3\Configuration | The configuration object that holds API settings and other parameters. |
$query | mixed | The GraphQL query object or string to be used for making requests. This could be an array, string, or other types depending on the implementation. |
request_terms
Retrieve taxonomy terms for either categories or brands.
public request_terms(string $slug, string $taxonomy = 'category'): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$slug | string | Taxonomy term slug |
$taxonomy | string | The taxonomy type (category or brand) |
request_paginated_products
Retrieve a paginated list of products.
public request_paginated_products(int $size = 50): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$size | int | Number of products per page (default: 50) |
request_product
Retrieve a product by its slug.
public request_product(string $slug): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$slug | string | Product’s URL slug |
request_product_reviews
Retrieve product reviews for a given product.
public request_product_reviews(int $product_id): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$product_id | int | The product’s ID |
products_loop_request
Retrieve paginated product listings.
public products_loop_request(int $limit = 12, string $cursor = ''): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$limit | int | Number of products to fetch per page |
$cursor | string | Pagination cursor (default: empty string) |
get_customer_wishlist
Retrieve the wishlist for a specific customer.
public get_customer_wishlist(int $customer_id, array $entityIds, bool $public = false): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$customer_id | int | The customer’s ID |
$entityIds | array | List of product entity IDs to fetch for wishlist |
$public | bool | Whether to retrieve public wishlist (default: false) |
get_customer_wishlists
Retrieve all wishlists for a specific customer.
public get_customer_wishlists(int $customer_id): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$customer_id | int | The customer’s ID |
get_graph_ql_query_from_file
Retrieve GraphQL query from file.
public get_graph_ql_query_from_file(string $file = ''): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$file | string | The query file name (without extension) |
Throws:
get_category_tree
Retrieve the category tree.
public get_category_tree(): mixedThrows:
get_brands
Retrieve a list of brands.
public get_brands(string $cursor = '', int $page_size = 50): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$cursor | string | Pagination cursor |
$page_size | int | Number of brands to retrieve per page |
Inherited methods
__construct
Constructor.
public __construct(\BigCommerce\Api\v3\Configuration $config): mixedInitializes the BaseGQL instance with the provided configuration and retrieves the tokens.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$config | \BigCommerce\Api\v3\Configuration | The configuration object used for API requests. |
get_channel_id
Retrieves the current channel ID from the site transient or connections.
protected get_channel_id(): intReturn Value:
The channel ID.
get_token
Retrieves the current GraphQL token, requesting a new one if necessary.
protected get_token(): mixedReturn Value:
The current token.
get_impersonation_token
Retrieves the current impersonation token, requesting a new one if necessary.
protected get_impersonation_token(): mixedReturn Value:
The current impersonation token.
request_im_token
Requests a new impersonation token from the API and stores it in a transient.
protected request_im_token(): voidrequest_token
Requests a new GraphQL token from the API and stores it in a transient.
protected request_token(): voidmake_request
Makes a POST request to the GraphQL API with the provided data, headers, and URL.
public make_request(mixed $data, array $headers = [], string $url = ''): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$data | mixed | The data to send in the request body. |
$headers | array | The headers for the request. |
$url | string | The URL for the request. |
Return Value:
The parsed response data.
Throws:
If the request fails or the response is invalid.
parse_response
Parses the response from the GraphQL API.
protected parse_response(array $result): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$result | array | The raw response data. |
Return Value:
The parsed response data.
Throws:
If the response is invalid.
get_store_hash
Retrieves the store hash from the configuration host URL.
protected get_store_hash(): stringReturn Value:
The store hash.
get_endpoint_url
Retrieves the endpoint URL for the GraphQL request.
protected get_endpoint_url(): stringReturn Value:
The full GraphQL endpoint URL.
get_origin
Retrieves the origin (site URL) for the request.
protected get_origin(): stringReturn Value:
The origin URL.
get_auth_bearer
Constructs the authorization bearer string for the request.
protected get_auth_bearer(bool $impersonation = false): stringParameters:
| Parameter | Type | Description |
|---|---|---|
$impersonation | bool | Whether to use the impersonation token. |
Return Value:
The authorization header value.
validate_token
Validates whether the current token is still valid and not expired.
protected validate_token(): boolReturn Value:
Whether the token is valid.
get_headers
Constructs the headers for the GraphQL request, including authorization.
protected get_headers(bool $impersonation = false): arrayParameters:
| Parameter | Type | Description |
|---|---|---|
$impersonation | bool | Whether to use the impersonation token. |
Return Value:
The request headers.
Automatically generated on 2025-01-21