Skip to content

add queryplan#436

Merged
vladar merged 1 commit into
webonyx:masterfrom
keulinho:add-queryplan
Mar 9, 2019
Merged

add queryplan#436
vladar merged 1 commit into
webonyx:masterfrom
keulinho:add-queryplan

Conversation

@keulinho

@keulinho keulinho commented Feb 1, 2019

Copy link
Copy Markdown
Contributor

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

Comment thread tests/Type/QueryPlanTest.php Outdated
self::assertEquals($expectedReferencedFields, $queryPlan->referencedFields());
self::assertEquals(['url', 'width', 'height'], $queryPlan->subFields('Image'));

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

Copy link
Copy Markdown
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 🤔

@keulinho keulinho Feb 1, 2019

Copy link
Copy Markdown
Contributor Author

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
Comment thread src/Type/Definition/QueryPlan.php Outdated
* @param mixed[] $variableValues
* @param FragmentDefinitionNode[] $fragments
*
* @throws Error

Copy link
Copy Markdown
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.

Comment thread src/Type/Definition/QueryPlan.php Outdated

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

Copy link
Copy Markdown
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

Comment thread src/Type/Definition/QueryPlan.php Outdated
/**
* @return string[]
*/
public function referencedTypes() : array

Copy link
Copy Markdown
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

Comment thread src/Type/Definition/QueryPlan.php Outdated
/**
* @return string[]
*/
public function referencedFields() : array

Copy link
Copy Markdown
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.

Comment thread src/Type/Definition/QueryPlan.php Outdated

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

Copy link
Copy Markdown
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) {

Comment thread src/Type/Definition/QueryPlan.php Outdated
} elseif ($selectionNode instanceof FragmentSpreadNode) {
$spreadName = $selectionNode->name->value;
if (isset($this->fragments[$spreadName])) {
/** @var FragmentDefinitionNode $fragment */

Copy link
Copy Markdown
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?

Comment thread src/Type/Definition/ResolveInfo.php Outdated
public $variableValues = [];

/**
* @internal

Copy link
Copy Markdown
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

Comment thread src/Type/Definition/ResolveInfo.php Outdated
*
* @var QueryPlan
*/
private $queryPlan = null;

Copy link
Copy Markdown
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

Comment thread src/Type/Definition/ResolveInfo.php Outdated
return $fields;
}

public function lookahead() : QueryPlan

Copy link
Copy Markdown
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

Comment thread tests/Type/QueryPlanTest.php Outdated
use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;

class QueryPlanTest extends TestCase

Copy link
Copy Markdown
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

vladar commented Feb 4, 2019

Copy link
Copy Markdown
Member

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
Copy Markdown
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?

@keulinho keulinho Feb 26, 2019

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
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