/** * Entry point for the `walkQuery` routine. Execution bounces between here, where the reducer's ->visit() method * is invoked, and `walkQuery` where we send in the scores from the `visit` call. * * @param Query $query * @param AbstractType $currentLevelSchema * @param AbstractQueryVisitor $reducer */ protected function doVisit(Query $query, $currentLevelSchema, $reducer) { if (!$currentLevelSchema instanceof AbstractObjectType || !$currentLevelSchema->hasField($query->getName())) { return; } if ($operationField = $currentLevelSchema->getField($query->getName())) { $coroutine = $this->walkQuery($query, $operationField); if ($results = $coroutine->current()) { $queryCost = 0; while ($results) { // initial values come from advancing the generator via ->current, subsequent values come from ->send() list($queryField, $astField, $childCost) = $results; /** * @var Query|FieldAst $queryField * @var Field $astField */ $cost = $reducer->visit($queryField->getKeyValueArguments(), $astField->getConfig(), $childCost); $queryCost += $cost; $results = $coroutine->send($cost); } } } }
protected function resolveQuery(AstQuery $query) { $schema = $this->executionContext->getSchema(); $type = $query instanceof AstMutation ? $schema->getMutationType() : $schema->getQueryType(); $field = new Field(['name' => $query instanceof AstMutation ? 'mutation' : 'query', 'type' => $type]); if (self::TYPE_NAME_QUERY == $query->getName()) { return [$this->getAlias($query) => $type->getName()]; } $this->resolveValidator->assetTypeHasField($type, $query); $value = $this->resolveField($field, $query); return [$this->getAlias($query) => $value]; }
public function testQuery() { $arguments = [new Argument('limit', new Literal('10', new Location(1, 1)), new Location(1, 1))]; $fields = [new Field('id', null, [], new Location(1, 1))]; $query = new Query('ships', 'lastShips', $arguments, $fields, new Location(1, 1)); $this->assertEquals('ships', $query->getName()); $this->assertEquals('lastShips', $query->getAlias()); $this->assertEquals($arguments, $query->getArguments()); $this->assertEquals(['limit' => '10'], $query->getKeyValueArguments()); $this->assertEquals($fields, $query->getFields()); $this->assertTrue($query->hasArguments()); $this->assertTrue($query->hasFields()); $query->setFields([]); $query->setArguments([]); $this->assertEmpty($query->getArguments()); $this->assertEmpty($query->getFields()); $this->assertEmpty($query->getKeyValueArguments()); $this->assertFalse($query->hasArguments()); $this->assertFalse($query->hasFields()); $query->addArgument(new Argument('offset', new Literal(10, new Location(1, 1)), new Location(1, 1))); $this->assertTrue($query->hasArguments()); }