Skip to content
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

Merged
merged 1 commit into from
Mar 9, 2019
Merged

add queryplan #436

merged 1 commit into from
Mar 9, 2019

Conversation

keulinho
Copy link
Contributor

@keulinho keulinho commented Feb 1, 2019

Provide the possibility to lookahead the Query Execution.
This one adds the API proposed in #65.
From #65:

  1. What sub-fields were requested (regardless of fragment types)? -> still possible
  2. What types were referenced by fragments? -> could be added
  3. What sub-fields were requested for given type? -> possible
  4. What args/directives were set for given field? -> possible for args, directives could be added

self::assertEquals($expectedReferencedFields, $queryPlan->referencedFields());
self::assertEquals(['url', 'width', 'height'], $queryPlan->subFields('Image'));

static::assertTrue($queryPlan->hasField('url'));
Copy link
Contributor

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 🤔

Copy link
Contributor Author

@keulinho keulinho Feb 1, 2019

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

@keulinho keulinho force-pushed the add-queryplan branch 2 times, most recently from 85bdb8b to 3e8d848 Compare February 1, 2019 20:29
* @param mixed[] $variableValues
* @param FragmentDefinitionNode[] $fragments
*
* @throws Error
Copy link
Collaborator

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.


public function hasType(string $type) : bool
{
return count(array_filter($this->referencedTypes(), static function ($element) use ($type) {
Copy link
Collaborator

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

/**
* @return string[]
*/
public function referencedTypes() : array
Copy link
Collaborator

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

/**
* @return string[]
*/
public function referencedFields() : array
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefix get as well.


public function hasField(string $field) : bool
{
return count(array_filter($this->referencedFields(), static function ($element) use ($field) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return count(array_filter($this->referencedFields(), static function ($element) use ($field) {
return count(array_filter($this->referencedFields(), static function (string $referencedField) use ($field) {

} elseif ($selectionNode instanceof FragmentSpreadNode) {
$spreadName = $selectionNode->name->value;
if (isset($this->fragments[$spreadName])) {
/** @var FragmentDefinitionNode $fragment */
Copy link
Collaborator

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?

@@ -99,6 +99,13 @@ class ResolveInfo
*/
public $variableValues = [];

/**
* @internal
Copy link
Collaborator

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

*
* @var QueryPlan
*/
private $queryPlan = null;
Copy link
Collaborator

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

@@ -179,6 +186,22 @@ public function getFieldSelection($depth = 0)

return $fields;
}

public function lookahead() : QueryPlan
Copy link
Collaborator

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

use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;

class QueryPlanTest extends TestCase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class QueryPlanTest extends TestCase
final class QueryPlanTest extends TestCase

@vladar
Copy link
Member

vladar commented Feb 4, 2019

This is great! I need some time to digest it before I can post any feedback or merge. Thanks!

],
array_keys((array) $info)
);

Copy link
Member

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?

Copy link
Contributor Author

@keulinho keulinho Feb 26, 2019

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants