상속: implements Youshido\GraphQL\Validator\ConfigValidator\ConfigValidatorInterface, use trait Youshido\GraphQL\Validator\ErrorContainer\ErrorContainerTrait
예제 #1
0
 /**
  * @return ConfigValidator
  */
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new self();
     }
     self::$instance->clearErrors();
     return self::$instance;
 }
예제 #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());
         }
     }
 }
예제 #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)));
     }
 }
예제 #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());
 }
예제 #5
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testWithoutValueParams()
 {
     $enumField = new EnumType(['values' => [['name' => 'TEST_ENUM']]]);
     ConfigValidator::getInstance()->assertValidConfig($enumField->getConfig());
 }
예제 #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());
 }
예제 #7
0
 /**
  * @dataProvider invalidInputFieldProvider
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidInputFieldParams($fieldConfig)
 {
     $field = new InputField($fieldConfig);
     ConfigValidator::getInstance()->assertValidConfig($field->getConfig());
 }
예제 #8
0
 public function __construct(AbstractSchema $schema)
 {
     $validator = ConfigValidator::getInstance();
     $validator->addRule('type', new TypeValidationRule($validator));
     parent::__construct($schema);
 }
예제 #9
0
 protected function setUp()
 {
     $this->rule = new TypeValidationRule(ConfigValidator::getInstance());
 }
예제 #10
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testConfigNoResolve()
 {
     ConfigValidator::getInstance()->assertValidConfig(new InterfaceTypeConfig(['name' => 'Test', 'fields' => ['id' => new IntType()]], null, true));
 }
예제 #11
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidFieldsParam()
 {
     $type = new ObjectType(['name' => 'SomeName', 'fields' => []]);
     ConfigValidator::getInstance()->assertValidConfig($type->getConfig());
 }
예제 #12
0
 /**
  * @expectedException Youshido\GraphQL\Exception\ConfigurationException
  */
 public function testInvalidConfigInvalidInterface()
 {
     ConfigValidator::getInstance()->assertValidConfig(new ObjectTypeConfig(['name' => 'Test', 'interfaces' => ['Invalid interface']], null, false));
 }