ClassesBigCommerceGraphQLBasegql

BaseGQL

Handles interactions with the BigCommerce GraphQL API, including token management, making authenticated requests, and handling store-related information.

  • Full name: \BigCommerce\GraphQL\BaseGQL

Constants

ConstantVisibilityTypeValue
GQL_BASEpublicstringhttps://store-%s-%s.mybigcommerce.com/graphql'
GQL_ACCEPTpublicstring’application/json’
TOKEN_EXPIRATIONpublicstring’bigcommerce_gql_expire_at’
GQL_TOKENpublicstring’bigcommerce_gql_token’
GQL_IMPERSONATION_TOKENpublicstring’bigcommerce_gql_im_token’
GQL_BASE_URLpublicstringhttps://api.bigcommerce.com/stores/%s/v3/storefront/api-token'
GQL_IMPERSONATION_URLpublicstringhttps://api.bigcommerce.com/stores/%s/v3/storefront/api-token-customer-impersonation'

Properties

token

protected string $token

impersonation_token

protected string $impersonation_token

config

protected \BigCommerce\Api\v3\Configuration $config

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