public function testPassesOnTheIntrospectionSchema() { $schema = new Schema(Introspection::_schema()); $validationResult = SchemaValidator::validate($schema); $this->assertSame(true, $validationResult->isValid); $this->assertSame(null, $validationResult->errors); }
public function getTypeMap() { if (null === $this->_typeMap) { $map = []; foreach ([$this->getQueryType(), $this->getMutationType(), Introspection::_schema()] as $type) { $this->_extractTypes($type, $map); } $this->_typeMap = $map + Type::getInternalTypes(); } return $this->_typeMap; }
public function __construct(Type $querySchema = null, Type $mutationSchema = null) { Utils::invariant($querySchema || $mutationSchema, "Either query or mutation type must be set"); $this->querySchema = $querySchema; $this->mutationSchema = $mutationSchema; // Build type map now to detect any errors within this schema. $map = []; foreach ([$this->getQueryType(), $this->getMutationType(), Introspection::_schema()] as $type) { $this->_extractTypes($type, $map); } $this->_typeMap = $map + Type::getInternalTypes(); // Enforce correct interface implementations foreach ($this->_typeMap as $typeName => $type) { if ($type instanceof ObjectType) { foreach ($type->getInterfaces() as $iface) { $this->assertObjectImplementsInterface($type, $iface); } } } }
/** * @param array $config */ protected function init(array $config) { $config += ['query' => null, 'mutation' => null, 'subscription' => null, 'types' => [], 'directives' => [], 'validate' => true]; if ($config['query'] instanceof DefinitionContainer) { $config['query'] = $config['query']->getDefinition(); } if ($config['mutation'] instanceof DefinitionContainer) { $config['mutation'] = $config['mutation']->getDefinition(); } if ($config['subscription'] instanceof DefinitionContainer) { $config['subscription'] = $config['subscription']->getDefinition(); } 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; } } } }
public function testPassesOnTheIntrospectionSchema() { $schema = new Schema(Introspection::_schema()); $errors = SchemaValidator::validate($schema); $this->assertEmpty($errors); }
public function testPassesOnTheIntrospectionSchema() { $this->expectPasses(['query' => Introspection::_schema()]); }