Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
d0c9ee7
Replace Utils::map() with array_map where possible
spawnia Aug 4, 2020
812aff3
Fix codestyle
spawnia Aug 4, 2020
6d2da6f
Add type
spawnia Aug 4, 2020
b8e9dfa
Fix style
spawnia Aug 4, 2020
872220b
Remove Utils::map()
spawnia Aug 4, 2020
bc46742
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Mar 27, 2021
9a16f76
Fix benchmarks
spawnia Mar 27, 2021
22f48f8
Fix codestyle
spawnia Mar 27, 2021
8d53b9e
Fix changed parts
spawnia Mar 27, 2021
5f78146
Fix missing location
spawnia Mar 27, 2021
d4b8aaa
Add BuildSchemaBench.php
spawnia Mar 27, 2021
33c6006
1000 iterations
spawnia Mar 27, 2021
9651fea
Fix codestyle
spawnia Mar 27, 2021
2b2574c
Fix ci
spawnia Mar 27, 2021
04ad2dc
Replace with foreach
spawnia May 30, 2021
539db88
Merge branch 'master' into replace-utils-map-with-array-map
spawnia May 30, 2021
44a7eb0
Strict typing
spawnia May 30, 2021
58984d1
Simplify
spawnia May 30, 2021
0222347
foreach
spawnia May 30, 2021
8900d7e
err
spawnia May 30, 2021
e49dd0c
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 18, 2021
10f25c2
fix codestyle
spawnia Jul 18, 2021
562c5a3
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 18, 2021
e9d9e7e
Fix tests
spawnia Jul 18, 2021
88264ab
format
spawnia Jul 18, 2021
c41bc9a
Replace more instances
spawnia Jul 18, 2021
60793d3
moar
spawnia Jul 18, 2021
127decf
cl
spawnia Jul 18, 2021
78409c2
quicken bench
spawnia Jul 18, 2021
37b22be
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 26, 2021
9eb50b1
short fn
spawnia Jul 26, 2021
02e2b38
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 26, 2021
fd3ce86
fix merge
spawnia Jul 26, 2021
ca11372
Update src/Type/Definition/ObjectType.php
spawnia Jul 28, 2021
7c5c933
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 28, 2021
f67da31
Restore short array_map
spawnia Jul 28, 2021
6793899
revert example
spawnia Jul 28, 2021
c0c6d75
Merge branch 'master' into replace-utils-map-with-array-map
spawnia Jul 28, 2021
d95d7d9
Update generate-class-reference.php
spawnia Jul 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ You can find and compare releases at the [GitHub release page](https://github.co
### Optimized

- Use recursive algorithm for printer and improve its performance
- Use `foreach` over slower functions `array_map()` and `Utils::map()`

### Fixed

- Avoid QueryPlan crash when multiple $fieldNodes are present
- Clarify error when attempting to coerce anything but `array` or `stdClass` to an input object
- Allow directives on variable definitions
- Handle `null` parent of list in `ValuesOfCorrectType::getVisitor`

### Removed
Expand Down
74 changes: 74 additions & 0 deletions benchmarks/BuildSchemaBench.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace GraphQL\Benchmarks;

use GraphQL\Utils\BuildSchema;

use function range;

/**
* @BeforeMethods({"makeSchemaString"})
* @OutputTimeUnit("milliseconds", precision=3)
* @Warmup(2)
* @Revs(10)
* @Iterations(2)
*/
class BuildSchemaBench
{
private string $schema = /** @lang GraphQL */ <<<GRAPHQL
type Query {
foo: Foo
}

interface F {
foo: ID
}

type Foo implements F {
foo: ID
}

type Bar {
bar: ID
}
GRAPHQL;

public function makeSchemaString(): void
{
foreach (range(1, 100) as $i) {
$this->schema .= /** @lang GraphQL */ <<<GRAPHQL
union U{$i} = Foo | Bar

directive @d{$i} on
| QUERY
| MUTATION
| SUBSCRIPTION
| FIELD
| FRAGMENT_DEFINITION
| FRAGMENT_SPREAD
| INLINE_FRAGMENT
| VARIABLE_DEFINITION
| SCHEMA
| SCALAR
| OBJECT
| FIELD_DEFINITION
| ARGUMENT_DEFINITION
| INTERFACE
| UNION
| ENUM
| ENUM_VALUE
| INPUT_OBJECT
| INPUT_FIELD_DEFINITION


GRAPHQL;
}
}

public function benchBuildSchema(): void
{
BuildSchema::build($this->schema);
}
}
42 changes: 23 additions & 19 deletions generate-class-reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@
];

function renderClassMethod(ReflectionMethod $method) {
$args = Utils::map($method->getParameters(), function(ReflectionParameter $p) {
$type = ltrim($p->getType() . " ");
$def = $type . '$' . $p->getName();

if ($p->isDefaultValueAvailable()) {
$val = $p->isDefaultValueConstant()
? $p->getDefaultValueConstantName()
: $p->getDefaultValue();
$def .= " = " . Utils::printSafeJson($val);
}

return $def;
});
$args = array_map(
static function (ReflectionParameter $p): string {
$type = ltrim($p->getType() . " ");
$def = $type . '$' . $p->getName();

if ($p->isDefaultValueAvailable()) {
$val = $p->isDefaultValueConstant()
? $p->getDefaultValueConstantName()
: $p->getDefaultValue();
$def .= " = " . Utils::printSafeJson($val);
}

return $def;
},
$method->getParameters()
);
$argsStr = implode(", ", $args);
if (strlen($argsStr) >= 80) {
$argsStr = "\n " . implode(",\n ", $args) . "\n";
Expand Down Expand Up @@ -82,7 +85,7 @@ function renderClass(ReflectionClass $class, $options) {

if (!empty($options['constants'])) {
$constants = $class->getConstants();
$constants = Utils::map($constants, 'renderConstant');
$constants = array_map('renderConstant', $constants);
if (!empty($constants)) {
$constants = "```php\n" . implode("\n", $constants) . "\n```";
$content .= "**$label Constants:** \n$constants\n\n";
Expand All @@ -93,7 +96,7 @@ function renderClass(ReflectionClass $class, $options) {
$props = $class->getProperties(ReflectionProperty::IS_PUBLIC);
$props = Utils::filter($props, 'isApi');
if (!empty($props)) {
$props = Utils::map($props, 'renderProp');
$props = array_map('renderProp', $props);
$props = "```php\n" . implode("\n\n", $props) . "\n```";
$content .= "**$label Props:** \n$props\n\n";
}
Expand All @@ -103,7 +106,7 @@ function renderClass(ReflectionClass $class, $options) {
$methods = $class->getMethods(ReflectionMethod::IS_PUBLIC);
$methods = Utils::filter($methods, 'isApi');
if (!empty($methods)) {
$renderedMethods = Utils::map($methods, 'renderClassMethod');
$renderedMethods = array_map('renderClassMethod', $methods);
$renderedMethods = implode("\n\n", $renderedMethods);
$content .= "**$label Methods:** \n{$renderedMethods}\n";
}
Expand All @@ -130,9 +133,10 @@ function unwrapDocblock($docBlock, $stripAnnotations = true) {

function unpadDocblock($docBlock) {
$lines = explode("\n", $docBlock);
$lines = \GraphQL\Utils\Utils::map($lines, function($line) {
return ' ' . trim($line);
});
$lines = array_map(
static fn(string $line): string => ' ' . trim($line),
$lines
);
return trim(implode("\n", $lines));
}

Expand Down
Loading