Automattic\WooCommerce\Internal\Api

QueryCache::resolve_apqprivateWC 1.0

Handle an APQ request (hash present in extensions).

Method of the class: QueryCache{}

No Hooks.

Returns

DocumentNode|Array.

Usage

// private - for code of main (parent) class only
$result = $this->resolve_apq( ?string $query, $apq_hash );
?string $query(required)
.
$apq_hash(string) (required)
The sha256 hash from the persistedQuery extension.

QueryCache::resolve_apq() code WC 10.9.1

private function resolve_apq( ?string $query, string $apq_hash ) {
	if ( ! empty( $query ) ) {
		// Registration: query + hash provided.
		if ( hash( 'sha256', $query ) !== $apq_hash ) {
			return $this->error_response(
				'provided sha does not match query',
				'PERSISTED_QUERY_HASH_MISMATCH'
			);
		}

		$doc = $this->get_cached_document( $apq_hash, true );
		if ( false !== $doc ) {
			return $doc;
		}

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

	// Hash-only lookup.
	$doc = $this->get_cached_document( $apq_hash, true );
	if ( false !== $doc ) {
		return $doc;
	}

	return $this->error_response( 'PersistedQueryNotFound', 'PERSISTED_QUERY_NOT_FOUND' );
}