Automattic\WooCommerce\Vendor\GraphQL\Utils

BuildClientSchema::buildSchemapublicWC 1.0

Method of the class: BuildClientSchema{}

No Hooks.

Returns

null. Nothing (null).

Usage

$BuildClientSchema = new BuildClientSchema();
$BuildClientSchema->buildSchema(): Schema;

BuildClientSchema::buildSchema() code WC 10.9.1

public function buildSchema(): Schema
{
    if (! array_key_exists('__schema', $this->introspection)) {
        $missingSchemaIntrospection = Utils::printSafeJson($this->introspection);
        throw new InvariantViolation("Invalid or incomplete introspection result. Ensure that you are passing \"data\" property of introspection response and no \"errors\" was returned alongside: {$missingSchemaIntrospection}.");
    }

    $schemaIntrospection = $this->introspection['__schema'];

    $builtInTypes = array_merge(
        Type::builtInScalars(),
        Introspection::getTypes()
    );

    foreach ($schemaIntrospection['types'] as $typeIntrospection) {
        if (! isset($typeIntrospection['name'])) {
            throw self::invalidOrIncompleteIntrospectionResult($typeIntrospection);
        }

        $name = $typeIntrospection['name'];
        if (! is_string($name)) {
            throw self::invalidOrIncompleteIntrospectionResult($typeIntrospection);
        }

        // Use the built-in singleton types to avoid reconstruction
        $this->typeMap[$name] = $builtInTypes[$name]
            ?? $this->buildType($typeIntrospection);
    }

    $description = isset($schemaIntrospection['description'])
        ? $schemaIntrospection['description']
        : null;

    $queryType = isset($schemaIntrospection['queryType'])
        ? $this->getObjectType($schemaIntrospection['queryType'])
        : null;

    $mutationType = isset($schemaIntrospection['mutationType'])
        ? $this->getObjectType($schemaIntrospection['mutationType'])
        : null;

    $subscriptionType = isset($schemaIntrospection['subscriptionType'])
        ? $this->getObjectType($schemaIntrospection['subscriptionType'])
        : null;

    $directives = isset($schemaIntrospection['directives'])
        ? array_map(
            [$this, 'buildDirective'],
            $schemaIntrospection['directives']
        )
        : [];

    return new Schema(
        (new SchemaConfig())
            ->setDescription($description)
            ->setQuery($queryType)
            ->setMutation($mutationType)
            ->setSubscription($subscriptionType)
            ->setTypes($this->typeMap)
            ->setDirectives($directives)
            ->setAssumeValid($this->options['assumeValid'] ?? false)
    );
}