Automattic\WooCommerce\Vendor\GraphQL\Type

Introspection::_directivepublic staticWC 1.0

Method of the class: Introspection{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = Introspection::_directive(): ObjectType;

Introspection::_directive() code WC 10.9.1

public static function _directive(): ObjectType
{
    return self::$cachedInstances[self::DIRECTIVE_OBJECT_NAME] ??= new ObjectType([ // @phpstan-ignore missingType.checkedException (static configuration is known to be correct)
        'name' => self::DIRECTIVE_OBJECT_NAME,
        'isIntrospection' => true,
        'description' => 'A Directive provides a way to describe alternate runtime execution and '
            . 'type validation behavior in a Automattic\WooCommerce\Vendor\GraphQL document.'
            . "\n\nIn some cases, you need to provide options to alter GraphQL's "
            . 'execution behavior in ways field arguments will not suffice, such as '
            . 'conditionally including or skipping a field. Directives provide this by '
            . 'describing additional information to the executor.',
        'fields' => [
            'name' => [
                'type' => Type::nonNull(Type::string()),
                'resolve' => static fn (Directive $directive): string => $directive->name,
            ],
            'description' => [
                'type' => Type::string(),
                'resolve' => static fn (Directive $directive): ?string => $directive->description,
            ],
            'isRepeatable' => [
                'type' => Type::nonNull(Type::boolean()),
                'resolve' => static fn (Directive $directive): bool => $directive->isRepeatable,
            ],
            'locations' => [
                'type' => Type::nonNull(Type::listOf(Type::nonNull(
                    self::_directiveLocation()
                ))),
                'resolve' => static fn (Directive $directive): array => $directive->locations,
            ],
            'args' => [
                'type' => Type::nonNull(Type::listOf(Type::nonNull(self::_inputValue()))),
                'args' => [
                    'includeDeprecated' => [
                        'type' => Type::nonNull(Type::boolean()),
                        'defaultValue' => false,
                    ],
                ],
                'resolve' => static function (Directive $directive, $args): array {
                    $values = $directive->args;

                    if (! $args['includeDeprecated']) {
                        return array_filter(
                            $values,
                            static fn (Argument $value): bool => ! $value->isDeprecated(),
                        );
                    }

                    return $values;
                },
            ],
        ],
    ]);
}