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]; }
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; }
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()); }
public function build(FieldConfig $config) { $config->addArguments(['id' => new NonNullType(new IdType())]); }
public function build(FieldConfig $config) { $config->addArgument(new InputField(['name' => 'id', 'type' => new NonNullType(new IdType()), 'description' => 'The ID of an object'])); }
public function build(FieldConfig $config) { $config->addArgument('id', new NonNullType(new IntType())); }
public function build(FieldConfig $config) { $config->addArguments(['field' => ['type' => new StringType(), 'default' => 'image']]); }