Automattic\WooCommerce\Vendor\GraphQL\Executor

ReferenceExecutor::getOperationRootTypeprotectedWC 1.0

Extracts the root type of the operation from the schema.

Method of the class: ReferenceExecutor{}

No Hooks.

Returns

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->getOperationRootType( $schema, $operation ): ObjectType;
$schema(Schema) (required)
.
$operation(OperationDefinitionNode) (required)
.

ReferenceExecutor::getOperationRootType() code WC 10.9.1

protected function getOperationRootType(Schema $schema, OperationDefinitionNode $operation): ObjectType
{
    switch ($operation->operation) {
        case 'query':
            $queryType = $schema->getQueryType();
            if ($queryType === null) {
                throw new Error('Schema does not define the required query root type.', [$operation]);
            }

            return $queryType;

        case 'mutation':
            $mutationType = $schema->getMutationType();
            if ($mutationType === null) {
                throw new Error('Schema is not configured for mutations.', [$operation]);
            }

            return $mutationType;

        case 'subscription':
            $subscriptionType = $schema->getSubscriptionType();
            if ($subscriptionType === null) {
                throw new Error('Schema is not configured for subscriptions.', [$operation]);
            }

            return $subscriptionType;

        default:
            throw new Error('Can only execute queries, mutations and subscriptions.', [$operation]);
    }
}