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

Fix args in sub queries #327

Merged
merged 27 commits into from
Jun 19, 2019
Merged

Fix args in sub queries #327

merged 27 commits into from
Jun 19, 2019

Conversation

sowork
Copy link
Contributor

@sowork sowork commented Jun 15, 2019

This PR fixes nested field arguments being properly passed to custom queries.

Previously the query arguments where used everywhere, no matter the nesting, for custom queries or privacy callbacks => now the field local ones are used.

Fixes #314

@mfn
Copy link
Collaborator

mfn commented Jun 17, 2019

@sowork thanks for the pull request!

Some tests are still failing, can you take a look?

@codecov-io
Copy link

codecov-io commented Jun 18, 2019

Codecov Report

Merging #327 into master will increase coverage by 0.4%.
The diff coverage is 82%.

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #327     +/-   ##
===========================================
+ Coverage     71.44%   71.85%   +0.4%     
- Complexity      318      333     +15     
===========================================
  Files            21       22      +1     
  Lines           837      874     +37     
===========================================
+ Hits            598      628     +30     
- Misses          239      246      +7
Impacted Files Coverage Δ Complexity Δ
src/Support/ResolveInfoFieldsAndArguments.php 79.41% <79.41%> (ø) 15 <15> (?)
src/Support/SelectFields.php 71.11% <87.5%> (+0.65%) 79 <11> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae556fc...204e591. Read the comment docs.

@mfn
Copy link
Collaborator

mfn commented Jun 18, 2019

Nice, tests are looking good!

I hope to find time for the review soon!

@mfn
Copy link
Collaborator

mfn commented Jun 19, 2019

@sowork I see you are still working on the PR.

Please ping me once you're done.

Oh, and don't worry too much about the static analyzer errors, I can take care of them.

@sowork
Copy link
Contributor Author

sowork commented Jun 19, 2019

@mfn tks, nested parameter problem solved, leaving some static analysis errors

mfn added 6 commits June 19, 2019 22:51
- there's always an 'args' (it may be empty)
- it's logically wrong to provide a nested query with the top level
  arguments; that's the bug we're trying to fix here
…methods

It's the same as with arguments for custom queries, the fallback to the
top level arguments are logically wrong.

This removes the ::$args field for good.
Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

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

This looks pretty good, the behaviour is correct now 👍

However the fact that self::$args is still used means we still incorrectly pass the query arguments to field specific operations.

I'll remedy this and my other feedback in follow-up commits.

if ($customQuery) {
$query = $customQuery(self::$args, $query);
$query = $customQuery($requestedFields['args'] ?? self::$args, $query);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The fallback to self::$args doesn't look right.

First: in what case when ['args'] be null (or not present)? Given the getFieldSelection code, I don't think it's possible.

Second: why should this default to self::$args? This is in fact the bug we're trying to fix; passing none or wrong arguments to the custom query.

IMHO the whole ?? part isn't necessary.

return $fields;
}

private function foldSelectionSet(SelectionSetNode $selectionSet, $descend)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole logic shouldn't be intermixed within this class.

Extracting the field/argument datastructure is a separate concern.

@@ -357,4 +417,9 @@ public function getRelations(): array
{
return $this->relations;
}

public function getResolveInfo(): ResolveInfo
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't necessary: ResolveInfo is solely here consumed by the class; any query/mutation resolver it as a separate argument anyway

@mfn mfn merged commit aecf9c7 into rebing:master Jun 19, 2019
@mfn
Copy link
Collaborator

mfn commented Jun 19, 2019

@sowork many thanks for your contribution, solid! 👍

mfn added a commit that referenced this pull request Jul 1, 2019
This _probably_ got broken after #327 landed.

There were no tests before, so it didn't got noticed.
mfn added a commit that referenced this pull request Jul 1, 2019
This _probably_ got broken after #327 landed.

There were no tests before, so it didn't got noticed.
mfn added a commit that referenced this pull request Jul 1, 2019
This _probably_ got broken after #327 landed.

There were no tests before, so it didn't got noticed.
mfn added a commit that referenced this pull request Jul 1, 2019
This _probably_ got broken after #327 landed.

There were no tests before, so it didn't got noticed.
believe2world added a commit to believe2world/graphql_admin_laravel that referenced this pull request Apr 6, 2023
This _probably_ got broken after rebing/graphql-laravel#327 landed.

There were no tests before, so it didn't got noticed.
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.

SelectFields: $args on sub-fields are not considered in custom 'query' configuration
3 participants