Automattic\WooCommerce\Vendor\GraphQL\Utils

BuildClientSchema::buildFieldDefMapprivateWC 1.0

Method of the class: BuildClientSchema{}

No Hooks.

Returns

Array. UnnamedFieldDefinitionConfig>

Usage

// private - for code of main (parent) class only
$result = $this->buildFieldDefMap( $typeIntrospection ): array;
$typeIntrospection(array) (required)
.

BuildClientSchema::buildFieldDefMap() code WC 10.9.1

private function buildFieldDefMap(array $typeIntrospection): array
{
    if (! array_key_exists('fields', $typeIntrospection)) {
        $safeType = Utils::printSafeJson($typeIntrospection);
        throw new InvariantViolation("Introspection result missing fields: {$safeType}.");
    }

    /** @var array<string, UnnamedFieldDefinitionConfig> $map */
    $map = [];
    foreach ($typeIntrospection['fields'] as $field) {
        if (! array_key_exists('args', $field)) {
            $safeField = Utils::printSafeJson($field);
            throw new InvariantViolation("Introspection result missing field args: {$safeField}.");
        }

        $map[$field['name']] = [
            'description' => $field['description'],
            'deprecationReason' => $field['deprecationReason'],
            'type' => $this->getOutputType($field['type']),
            'args' => $this->buildInputValueDefMap($field['args']),
        ];
    }

    // @phpstan-ignore-next-line unless the returned name was numeric, this works
    return $map;
}