mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-21 20:36:05 +03:00
Fixed codestyle in benchmarks
This commit is contained in:
parent
c45fa1a4b1
commit
627cc786a5
@ -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,12 +30,12 @@ class HugeSchemaBench
|
||||
'totalTypes' => 600,
|
||||
'fieldsPerType' => 8,
|
||||
'listFieldsPerType' => 2,
|
||||
'nestingLevel' => 10
|
||||
'nestingLevel' => 10,
|
||||
]);
|
||||
|
||||
$this->schema = $this->schemaBuilder->buildSchema();
|
||||
|
||||
$queryBuilder = new QueryGenerator($this->schema, 0.05);
|
||||
$queryBuilder = new QueryGenerator($this->schema, 0.05);
|
||||
$this->smallQuery = $queryBuilder->buildQuery();
|
||||
}
|
||||
|
||||
@ -46,8 +43,7 @@ class HugeSchemaBench
|
||||
{
|
||||
$this->schemaBuilder
|
||||
->buildSchema()
|
||||
->getTypeMap()
|
||||
;
|
||||
->getTypeMap();
|
||||
}
|
||||
|
||||
public function benchSchemaLazy()
|
||||
@ -69,9 +65,9 @@ class HugeSchemaBench
|
||||
private function createLazySchema()
|
||||
{
|
||||
return new Schema(
|
||||
\GraphQL\Type\SchemaConfig::create()
|
||||
SchemaConfig::create()
|
||||
->setQuery($this->schemaBuilder->buildQueryType())
|
||||
->setTypeLoader(function($name) {
|
||||
->setTypeLoader(function ($name) {
|
||||
return $this->schemaBuilder->loadType($name);
|
||||
})
|
||||
);
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
namespace GraphQL\Benchmarks;
|
||||
|
||||
use GraphQL\GraphQL;
|
||||
use GraphQL\Tests\StarWarsSchema;
|
||||
use GraphQL\Type\Introspection;
|
||||
|
@ -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,12 +33,14 @@ 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));
|
||||
$this->maxLeafFields = max(1, round($totalFields * $percentOfLeafFields));
|
||||
$this->currentLeafFields = 0;
|
||||
}
|
||||
|
||||
@ -44,13 +49,12 @@ class QueryGenerator
|
||||
$qtype = $this->schema->getQueryType();
|
||||
|
||||
$ast = new DocumentNode([
|
||||
'definitions' => [
|
||||
new OperationDefinitionNode([
|
||||
'name' => new NameNode(['value' => 'TestQuery']),
|
||||
'operation' => 'query',
|
||||
'selectionSet' => $this->buildSelectionSet($qtype->getFields())
|
||||
])
|
||||
]
|
||||
'definitions' => [new OperationDefinitionNode([
|
||||
'name' => new NameNode(['value' => 'TestQuery']),
|
||||
'operation' => 'query',
|
||||
'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;
|
||||
|
Loading…
Reference in New Issue
Block a user