-
-
Notifications
You must be signed in to change notification settings - Fork 565
add queryplan #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add queryplan #436
Conversation
515ba09
to
7b787b5
Compare
tests/Type/QueryPlanTest.php
Outdated
self::assertEquals($expectedReferencedFields, $queryPlan->referencedFields()); | ||
self::assertEquals(['url', 'width', 'height'], $queryPlan->subFields('Image')); | ||
|
||
static::assertTrue($queryPlan->hasField('url')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's up with the self::
vs. static::
calls here?
Maybe it's through out the codebase and I just didn't notice it before 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch 👍
the convention seems to be self::
but i'm used to static::
fixed it
85bdb8b
to
3e8d848
Compare
src/Type/Definition/QueryPlan.php
Outdated
* @param mixed[] $variableValues | ||
* @param FragmentDefinitionNode[] $fragments | ||
* | ||
* @throws Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the @throws anotation can be dropped. I have never found a way how to sustainably maintain those across the whole project.
src/Type/Definition/QueryPlan.php
Outdated
|
||
public function hasType(string $type) : bool | ||
{ | ||
return count(array_filter($this->referencedTypes(), static function ($element) use ($type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can typehint string $element
. And then change variable name to $referencedType
src/Type/Definition/QueryPlan.php
Outdated
/** | ||
* @return string[] | ||
*/ | ||
public function referencedTypes() : array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefix with get
src/Type/Definition/QueryPlan.php
Outdated
/** | ||
* @return string[] | ||
*/ | ||
public function referencedFields() : array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefix get
as well.
src/Type/Definition/QueryPlan.php
Outdated
|
||
public function hasField(string $field) : bool | ||
{ | ||
return count(array_filter($this->referencedFields(), static function ($element) use ($field) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return count(array_filter($this->referencedFields(), static function ($element) use ($field) { | |
return count(array_filter($this->referencedFields(), static function (string $referencedField) use ($field) { |
src/Type/Definition/QueryPlan.php
Outdated
} elseif ($selectionNode instanceof FragmentSpreadNode) { | ||
$spreadName = $selectionNode->name->value; | ||
if (isset($this->fragments[$spreadName])) { | ||
/** @var FragmentDefinitionNode $fragment */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be dropped, no?
src/Type/Definition/ResolveInfo.php
Outdated
@@ -99,6 +99,13 @@ class ResolveInfo | |||
*/ | |||
public $variableValues = []; | |||
|
|||
/** | |||
* @internal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the var is private so I guess we can drop this
src/Type/Definition/ResolveInfo.php
Outdated
* | ||
* @var QueryPlan | ||
*/ | ||
private $queryPlan = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null is default, can be dropped
src/Type/Definition/ResolveInfo.php
Outdated
@@ -179,6 +186,22 @@ public function getFieldSelection($depth = 0) | |||
|
|||
return $fields; | |||
} | |||
|
|||
public function lookahead() : QueryPlan |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If meant as verb, the proper camel case is lookAhead
tests/Type/QueryPlanTest.php
Outdated
use GraphQL\Type\Schema; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class QueryPlanTest extends TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class QueryPlanTest extends TestCase | |
final class QueryPlanTest extends TestCase |
3e8d848
to
5b3f44c
Compare
This is great! I need some time to digest it before I can post any feedback or merge. Thanks! |
], | ||
array_keys((array) $info) | ||
); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why deleting this? Can't you just add queryPlan
key to this list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
queryPlan
is declared private because it should only be loaded lazy when you call lookAhead()
When you cast the resolveInfo
to array now it cpontains some binary string instead of queryPlan
because it is private.
Furthermore i really saw no value added by this test, because every key mentionied there would be used for own assertions, so the test will fail anyway if you remove one of the public properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, missed your reply. Makes sense.
Provide the possibility to lookahead the Query Execution.
This one adds the API proposed in #65.
From #65: