Automattic\WooCommerce\Internal\Api

QueryCache::resolvepublicWC 1.0

Resolve a query string (and optional APQ extensions) into a DocumentNode.

Returns a DocumentNode on success, or a GraphQL-shaped error array on failure.

Method of the class: QueryCache{}

No Hooks.

Returns

DocumentNode|Array.

Usage

$QueryCache = new QueryCache();
$QueryCache->resolve( ?string $query, $extensions );
?string $query(required)
.
$extensions(array) (required)
The request extensions (may contain persistedQuery).

QueryCache::resolve() code WC 10.9.4

public function resolve( ?string $query, array $extensions ) {
	$apq      = $extensions['persistedQuery'] ?? null;
	$apq_hash = is_array( $apq ) ? ( $apq['sha256Hash'] ?? null ) : null;

	if ( Main::is_apq_enabled()
		&& is_array( $apq )
		&& 1 === ( $apq['version'] ?? null )
		&& is_string( $apq_hash )
		&& 1 === preg_match( '/^[a-f0-9]{64}$/', $apq_hash ) ) {
		return $this->resolve_apq( $query, $apq_hash );
	}

	// Standard query — no APQ.
	if ( empty( $query ) ) {
		return $this->error_response( 'No query provided.', 'BAD_REQUEST' );
	}

	// APQ keeps using the cache; it has its own settings toggle.
	if ( ! $this->is_caching_enabled() ) {
		return $this->parse( $query );
	}

	$hash = hash( 'sha256', $query );
	$doc  = $this->get_cached_document( $hash );
	if ( false !== $doc ) {
		return $doc;
	}

	return $this->parse_and_cache( $query, $hash );
}