Inheritance: implements Youshido\GraphQL\Validator\ConfigValidator\ConfigValidatorInterface, use trait Youshido\GraphQL\Validator\ErrorContainer\ErrorContainerTrait
Exemplo n.º 1
0
 /**
  * @return ConfigValidator
  */
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     self::$instance->clearErrors();
     return self::$instance;
 }
Exemplo n.º 2
0
 /**
  * @param AbstractSchema $schema
  *
  * @throws ConfigurationException
  */
 public function validate(AbstractSchema $schema)
 {
     if (!$schema->getQueryType()->hasFields()) {
         throw new ConfigurationException('Schema has to have fields');
     }
     $this->configValidator = ConfigValidator::getInstance();
     foreach ($schema->getQueryType()->getConfig()->getFields() as $field) {
         $this->configValidator->assertValidConfig($field->getConfig());
         if ($field->getType() instanceof AbstractObjectType) {
             $this->assertInterfaceImplementationCorrect($field->getType());
         }
     }
 }
Exemplo n.º 3
0
 public function validate()
 {
     $validator = ConfigValidator::getInstance();
     if (!$validator->validate($this->data, $this->getContextRules(), $this->extraFieldsAllowed)) {
         throw new ConfigurationException('Config is not valid for ' . ($this->contextObject ? get_class($this->contextObject) : null) . "\n" . implode("\n", $validator->getErrorsArray(false)));
     }
 }
Exemplo n.º 4
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidTypes()
 {
     $type = new UnionType(['name' => 'Car', 'description' => 'Union collect cars types', 'types' => [new IntType()], 'resolveType' => function ($type) {
         return $type;
     }]);
     ConfigValidator::getInstance()->assertValidConfig($type->getConfig());
 }
Exemplo n.º 5
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testWithoutValueParams()
 {
     $enumField = new EnumType(['values' => [['name' => 'TEST_ENUM']]]);
     ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
 }
Exemplo n.º 6
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testEnumConfig()
 {
     $enumType = new EnumType(['name' => 'Status', 'values' => [['name' => 'ACTIVE', 'values' => 1]]]);
     $object = new ObjectType(['name' => 'Project', 'fields' => ['id' => new IdType(), 'status' => $enumType]]);
     ConfigValidator::getInstance()->assertValidConfig($object->getConfig());
 }
Exemplo n.º 7
0
 /**
  * @dataProvider invalidInputFieldProvider
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidInputFieldParams($fieldConfig)
 {
     $field = new InputField($fieldConfig);
     ConfigValidator::getInstance()->assertValidConfig($field->getConfig());
 }
Exemplo n.º 8
0
 public function __construct(AbstractSchema $schema)
 {
     $validator = ConfigValidator::getInstance();
     $validator->addRule('type', new TypeValidationRule($validator));
     parent::__construct($schema);
 }
Exemplo n.º 9
0
 protected function setUp()
 {
     $this->rule = new TypeValidationRule(ConfigValidator::getInstance());
 }
Exemplo n.º 10
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testConfigNoResolve()
 {
     ConfigValidator::getInstance()->assertValidConfig(new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, true));
 }
Exemplo n.º 11
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidFieldsParam()
 {
     $type = new ObjectType(['name' => 'SomeName', 'fields' => []]);
     ConfigValidator::getInstance()->assertValidConfig($type->getConfig());
 }
Exemplo n.º 12
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidConfigInvalidInterface()
 {
     ConfigValidator::getInstance()->assertValidConfig(new ObjectTypeConfig(['name' => 'Test', 'interfaces' => ['Invalid interface']], null, false));
 }