Fixed codestyle in benchmarks

This commit is contained in:
Vladimir Razuvaev 2018-11-27 17:22:29 +07:00
parent c45fa1a4b1
commit 627cc786a5
3 changed files with 28 additions and 26 deletions

View File

@ -1,10 +1,11 @@
<?php
namespace GraphQL\Benchmarks;
use GraphQL\GraphQL;
use GraphQL\Benchmarks\Utils\QueryGenerator;
use GraphQL\Benchmarks\Utils\SchemaGenerator;
use GraphQL\GraphQL;
use GraphQL\Type\Schema;
use GraphQL\Type\SchemaConfig;
/**
* @BeforeMethods({"setUp"})
@ -15,16 +16,12 @@ use GraphQL\Type\Schema;
*/
class HugeSchemaBench
{
/**
* @var SchemaGenerator
*/
/** @var SchemaGenerator */
private $schemaBuilder;
private $schema;
/**
* @var string
*/
/** @var string */
private $smallQuery;
public function setUp()
@ -33,7 +30,7 @@ class HugeSchemaBench
'totalTypes' => 600,
'fieldsPerType' => 8,
'listFieldsPerType' => 2,
'nestingLevel' => 10
'nestingLevel' => 10,
]);
$this->schema = $this->schemaBuilder->buildSchema();
@ -46,8 +43,7 @@ class HugeSchemaBench
{
$this->schemaBuilder
->buildSchema()
->getTypeMap()
;
->getTypeMap();
}
public function benchSchemaLazy()
@ -69,7 +65,7 @@ class HugeSchemaBench
private function createLazySchema()
{
return new Schema(
\GraphQL\Type\SchemaConfig::create()
SchemaConfig::create()
->setQuery($this->schemaBuilder->buildQueryType())
->setTypeLoader(function ($name) {
return $this->schemaBuilder->loadType($name);

View File

@ -1,5 +1,6 @@
<?php
namespace GraphQL\Benchmarks;
use GraphQL\GraphQL;
use GraphQL\Tests\StarWarsSchema;
use GraphQL\Type\Introspection;

View File

@ -13,6 +13,9 @@ use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\WrappingType;
use GraphQL\Type\Schema;
use GraphQL\Utils\Utils;
use function count;
use function max;
use function round;
class QueryGenerator
{
@ -30,9 +33,11 @@ class QueryGenerator
$totalFields = 0;
foreach ($schema->getTypeMap() as $type) {
if ($type instanceof ObjectType) {
$totalFields += count($type->getFields());
if (! ($type instanceof ObjectType)) {
continue;
}
$totalFields += count($type->getFields());
}
$this->maxLeafFields = max(1, round($totalFields * $percentOfLeafFields));
@ -44,13 +49,12 @@ class QueryGenerator
$qtype = $this->schema->getQueryType();
$ast = new DocumentNode([
'definitions' => [
new OperationDefinitionNode([
'definitions' => [new OperationDefinitionNode([
'name' => new NameNode(['value' => 'TestQuery']),
'operation' => 'query',
'selectionSet' => $this->buildSelectionSet($qtype->getFields())
])
]
'selectionSet' => $this->buildSelectionSet($qtype->getFields()),
]),
],
]);
return Printer::doPrint($ast);
@ -58,12 +62,13 @@ class QueryGenerator
/**
* @param FieldDefinition[] $fields
*
* @return SelectionSetNode
*/
public function buildSelectionSet($fields)
{
$selections[] = new FieldNode([
'name' => new NameNode(['value' => '__typename'])
'name' => new NameNode(['value' => '__typename']),
]);
$this->currentLeafFields++;
@ -87,12 +92,12 @@ class QueryGenerator
$selections[] = new FieldNode([
'name' => new NameNode(['value' => $field->name]),
'selectionSet' => $selectionSet
'selectionSet' => $selectionSet,
]);
}
$selectionSet = new SelectionSetNode([
'selections' => $selections
'selections' => $selections,
]);
return $selectionSet;