Inheritance: extends Youshido\GraphQL\Config\AbstractConfig, use trait Youshido\GraphQL\Config\Traits\ArgumentsAwareConfigTrait
Example #1
0
 protected function getConfigValue($key, $defaultValue = null)
 {
     if (array_key_exists($key, $this->configCache)) {
         return $this->configCache[$key];
     }
     $this->configCache[$key] = !empty($this->config) ? $this->config->get($key, $defaultValue) : $defaultValue;
     return $this->configCache[$key];
 }
Example #2
0
 public function testInvalidParams()
 {
     $fieldConfig = new FieldConfig(['name' => 'FirstName', 'type' => new StringType(), 'resolve' => function ($value, $args = [], $type = null) {
         return 'John';
     }]);
     $this->assertEquals('FirstName', $fieldConfig->getName());
     $this->assertEquals(new StringType(), $fieldConfig->getType());
     $resolveFunction = $fieldConfig->getResolveFunction();
     $this->assertEquals('John', $resolveFunction([]));
 }
 /**
  * {@inheritdoc}
  */
 public function visit(array $args, FieldConfig $fieldConfig, $childScore = 0)
 {
     $cost = $fieldConfig->get('cost');
     if (is_callable($cost)) {
         $cost = $cost($args, $fieldConfig, $childScore);
     }
     $cost = $cost ?: $this->defaultScore;
     $this->memo += $cost;
     if ($this->memo > $this->maxScore) {
         throw new \Exception('query exceeded max allowed complexity of ' . $this->maxScore);
     }
     return $cost;
 }
Example #4
0
 public function build(FieldConfig $config)
 {
     $config->addArgument(new InputField(['name' => 'name', 'type' => new NonNullType(new StringType())]));
 }
 public function testArguments()
 {
     $argsData = ['id' => new IntType()];
     $config = new FieldConfig(['name' => 'UserType', 'type' => new IntType(), 'args' => $argsData]);
     $this->assertTrue($config->hasArguments());
     $this->assertEquals(['id' => new InputField(['name' => 'id', 'type' => new IntType()])], $config->getArguments());
     $config->addArgument('name', new StringType());
     $this->assertEquals(['id' => new InputField(['name' => 'id', 'type' => new IntType()]), 'name' => new InputField(['name' => 'name', 'type' => new StringType()])], $config->getArguments());
     $config->removeArgument('id');
     $this->assertEquals(['name' => new InputField(['name' => 'name', 'type' => new StringType()])], $config->getArguments());
     $config->addArguments(['id' => new InputField(['name' => 'id', 'type' => new IntType()])]);
     $this->assertEquals(['name' => new InputField(['name' => 'name', 'type' => new StringType()]), 'id' => new InputField(['name' => 'id', 'type' => new IntType()])], $config->getArguments());
     $config->addArguments([new InputField(['name' => 'level', 'type' => new IntType()])]);
     $this->assertEquals(['name' => new InputField(['name' => 'name', 'type' => new StringType()]), 'id' => new InputField(['name' => 'id', 'type' => new IntType()]), 'level' => new InputField(['name' => 'level', 'type' => new IntType()])], $config->getArguments());
 }
Example #6
0
 public function build(FieldConfig $config)
 {
     $config->addArguments(['id' => new NonNullType(new IdType())]);
 }
Example #7
0
 public function build(FieldConfig $config)
 {
     $config->addArgument(new InputField(['name' => 'id', 'type' => new NonNullType(new IdType()), 'description' => 'The ID of an object']));
 }
Example #8
0
 public function build(FieldConfig $config)
 {
     $config->addArgument('id', new NonNullType(new IntType()));
 }
Example #9
0
 public function build(FieldConfig $config)
 {
     $config->addArguments(['field' => ['type' => new StringType(), 'default' => 'image']]);
 }