ClassesBigCommerceGraphQLGraphQL Processor

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.

Properties

query

protected mixed $query

Methods

__construct

Constructor to initialize the GraphQL processor with a configuration and query.

public __construct(\BigCommerce\Api\v3\Configuration $config, mixed $query): void

Parameters:

ParameterTypeDescription
$config\BigCommerce\Api\v3\ConfigurationThe configuration object that holds API settings and other parameters.
$querymixedThe 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'): array

Parameters:

ParameterTypeDescription
$slugstringTaxonomy term slug
$taxonomystringThe taxonomy type (category or brand)

request_paginated_products

Retrieve a paginated list of products.

public request_paginated_products(int $size = 50): array

Parameters:

ParameterTypeDescription
$sizeintNumber of products per page (default: 50)

request_product

Retrieve a product by its slug.

public request_product(string $slug): array

Parameters:

ParameterTypeDescription
$slugstringProduct’s URL slug

request_product_reviews

Retrieve product reviews for a given product.

public request_product_reviews(int $product_id): array

Parameters:

ParameterTypeDescription
$product_idintThe product’s ID

products_loop_request

Retrieve paginated product listings.

public products_loop_request(int $limit = 12, string $cursor = ''): array

Parameters:

ParameterTypeDescription
$limitintNumber of products to fetch per page
$cursorstringPagination 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): array

Parameters:

ParameterTypeDescription
$customer_idintThe customer’s ID
$entityIdsarrayList of product entity IDs to fetch for wishlist
$publicboolWhether to retrieve public wishlist (default: false)

get_customer_wishlists

Retrieve all wishlists for a specific customer.

public get_customer_wishlists(int $customer_id): array

Parameters:

ParameterTypeDescription
$customer_idintThe customer’s ID

get_graph_ql_query_from_file

Retrieve GraphQL query from file.

public get_graph_ql_query_from_file(string $file = ''): string

Parameters:

ParameterTypeDescription
$filestringThe query file name (without extension)

Throws:


get_category_tree

Retrieve the category tree.

public get_category_tree(): mixed

Throws:


get_brands

Retrieve a list of brands.

public get_brands(string $cursor = '', int $page_size = 50): array

Parameters:

ParameterTypeDescription
$cursorstringPagination cursor
$page_sizeintNumber of brands to retrieve per page

Inherited methods

__construct

Constructor.

public __construct(\BigCommerce\Api\v3\Configuration $config): mixed

Initializes the BaseGQL instance with the provided configuration and retrieves the tokens.

Parameters:

ParameterTypeDescription
$config\BigCommerce\Api\v3\ConfigurationThe configuration object used for API requests.

get_channel_id

Retrieves the current channel ID from the site transient or connections.

protected get_channel_id(): int

Return Value:

The channel ID.


get_token

Retrieves the current GraphQL token, requesting a new one if necessary.

protected get_token(): mixed

Return Value:

The current token.


get_impersonation_token

Retrieves the current impersonation token, requesting a new one if necessary.

protected get_impersonation_token(): mixed

Return 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(): void

request_token

Requests a new GraphQL token from the API and stores it in a transient.

protected request_token(): void

make_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 = ''): mixed

Parameters:

ParameterTypeDescription
$datamixedThe data to send in the request body.
$headersarrayThe headers for the request.
$urlstringThe 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): mixed

Parameters:

ParameterTypeDescription
$resultarrayThe 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(): string

Return Value:

The store hash.


get_endpoint_url

Retrieves the endpoint URL for the GraphQL request.

protected get_endpoint_url(): string

Return Value:

The full GraphQL endpoint URL.


get_origin

Retrieves the origin (site URL) for the request.

protected get_origin(): string

Return Value:

The origin URL.


get_auth_bearer

Constructs the authorization bearer string for the request.

protected get_auth_bearer(bool $impersonation = false): string

Parameters:

ParameterTypeDescription
$impersonationboolWhether 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(): bool

Return Value:

Whether the token is valid.


get_headers

Constructs the headers for the GraphQL request, including authorization.

protected get_headers(bool $impersonation = false): array

Parameters:

ParameterTypeDescription
$impersonationboolWhether to use the impersonation token.

Return Value:

The request headers.



Automatically generated on 2025-01-21