<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php declare(strict_types=1);

namespace Automattic\WooCommerce\Vendor\GraphQL\Executor;

use Automattic\WooCommerce\Vendor\GraphQL\Error\Error;
use Automattic\WooCommerce\Vendor\GraphQL\Executor\Promise\PromiseAdapter;
use Automattic\WooCommerce\Vendor\GraphQL\Language\AST\FragmentDefinitionNode;
use Automattic\WooCommerce\Vendor\GraphQL\Language\AST\OperationDefinitionNode;
use Automattic\WooCommerce\Vendor\GraphQL\Type\Schema;

/**
 * Data that must be available at all points during query execution.
 *
 * Namely, schema of the type system that is currently executing,
 * and the fragments defined in the query document.
 *
 * @phpstan-import-type FieldResolver from Executor
 * @phpstan-import-type ArgsMapper from Executor
 */
class ExecutionContext
{
    public Schema $schema;

    /** @var array<string, FragmentDefinitionNode> */
    public array $fragments;

    /** @var mixed */
    public $rootValue;

    /** @var mixed */
    public $contextValue;

    public OperationDefinitionNode $operation;

    /** @var array<string, mixed> */
    public array $variableValues;

    /**
     * @var callable
     *
     * @phpstan-var FieldResolver
     */
    public $fieldResolver;

    /**
     * @var callable
     *
     * @phpstan-var ArgsMapper
     */
    public $argsMapper;

    /** @var list<Error> */
    public array $errors;

    public PromiseAdapter $promiseAdapter;

    /**
     * @param array<string, FragmentDefinitionNode> $fragments
     * @param mixed $rootValue
     * @param mixed $contextValue
     * @param array<string, mixed> $variableValues
     * @param list<Error> $errors
     *
     * @phpstan-param FieldResolver $fieldResolver
     */
    public function __construct(
        Schema $schema,
        array $fragments,
        $rootValue,
        $contextValue,
        OperationDefinitionNode $operation,
        array $variableValues,
        array $errors,
        callable $fieldResolver,
        callable $argsMapper,
        PromiseAdapter $promiseAdapter
    ) {
        $this->schema = $schema;
        $this->fragments = $fragments;
        $this->rootValue = $rootValue;
        $this->contextValue = $contextValue;
        $this->operation = $operation;
        $this->variableValues = $variableValues;
        $this->errors = $errors;
        $this->fieldResolver = $fieldResolver;
        $this->argsMapper = $argsMapper;
        $this->promiseAdapter = $promiseAdapter;
    }

    public function addError(Error $error): void
    {
        $this->errors[] = $error;
    }
}
