WooCommerce Code Reference

ObjectType.php

Source code

<?php

declare(strict_types=1);

namespace Automattic\WooCommerce\Api\Infrastructure\Schema;

/**
 * Stable subclass of the underlying GraphQL engine's ObjectType, used by
 * autogenerated output types, pagination types and root Query/Mutation types.
 *
 * The constructor accepts the same associative-array config the current
 * engine (webonyx) documents (keys: `name`, `description`, `fields`,
 * `interfaces`). The `fields` entry is either an array or a callable
 * returning an array of field definitions.
 *
 * The wrapper also recognises a `metadata` key — an associative array
 * mapping metadata `name` => scalar `value` — that ApiBuilder emits for
 * types carrying {@see \Automattic\WooCommerce\Api\Attributes\Metadata}
 * attributes. The engine ignores unknown config keys, so this rides through
 * untouched and is surfaced by {@see self::get_metadata()}.
 */
class ObjectType extends \Automattic\WooCommerce\Vendor\GraphQL\Type\Definition\ObjectType {
	/**
	 * Type-level metadata entries declared in the config, keyed by name.
	 *
	 * @return array<string, bool|int|float|string|null>
	 */
	public function get_metadata(): array {
		return $this->config['metadata'] ?? array();
	}
}