private function init(array $config)
{
$config += ['query' => null, 'mutation' => null, 'subscription' => null, 'types' => [], 'directives' => [], 'validate' => true];
Utils::invariant($config['query'] instanceof ObjectType, "Schema query must be Object Type but got: " . Utils::getVariableType($config['query']));
$this->queryType = $config['query'];
Utils::invariant(!$config['mutation'] || $config['mutation'] instanceof ObjectType, "Schema mutation must be Object Type if provided but got: " . Utils::getVariableType($config['mutation']));
$this->mutationType = $config['mutation'];
Utils::invariant(!$config['subscription'] || $config['subscription'] instanceof ObjectType, "Schema subscription must be Object Type if provided but got: " . Utils::getVariableType($config['subscription']));
$this->subscriptionType = $config['subscription'];
Utils::invariant(!$config['types'] || is_array($config['types']), "Schema types must be Array if provided but got: " . Utils::getVariableType($config['types']));
Utils::invariant(!$config['directives'] || is_array($config['directives']) && Utils::every($config['directives'], function ($d) {
return $d instanceof Directive;
}), "Schema directives must be Directive[] if provided but got " . Utils::getVariableType($config['directives']));
$this->directives = $config['directives'] ?: GraphQL::getInternalDirectives();
// Build type map now to detect any errors within this schema.
$initialTypes = [$config['query'], $config['mutation'], $config['subscription'], Introspection::_schema()];
if (!empty($config['types'])) {
$initialTypes = array_merge($initialTypes, $config['types']);
}
foreach ($initialTypes as $type) {
$this->extractTypes($type);
}
$this->typeMap += Type::getInternalTypes();
// Keep track of all implementations by interface name.
$this->implementations = [];
foreach ($this->typeMap as $typeName => $type) {
if ($type instanceof ObjectType) {
foreach ($type->getInterfaces() as $iface) {
$this->implementations[$iface->name][] = $type;
}
}
}
}