-
-
Notifications
You must be signed in to change notification settings - Fork 266
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] Querying same field multiple times causes an error #537
Conversation
@edgarsn thanks for the contribution and sorry for the confusion upfront, please remove all styleci fixes and just completely ignored styleci. It's a current known issue and we're just waiting for it's integration being removed 🙏 |
Oh ok. Styles removed 👍 |
@edgarsn please add a test for this change, this also helps me better review / understand the intention of the PR, thank you! |
Sorry. Tests added 😉 |
@edgarsn when I run the test with your code changes reverted (the array casts), the test still works 🧐 My expectation here would be that the test breaks when I test it without them |
You have to revert not only array casts, but replace |
🤦♂️ Sorry for the noise, need more ☕️ |
@@ -130,11 +130,11 @@ private function foldSelectionSet(SelectionSetNode $selectionSet, int $descend): | |||
$spreadName = $selectionNode->name->value; | |||
if (isset($this->info->fragments[$spreadName])) { | |||
$fragment = $this->info->fragments[$spreadName]; | |||
$fields = array_merge_recursive($this->foldSelectionSet($fragment->selectionSet, $descend), | |||
$fields = (array) array_replace_recursive($this->foldSelectionSet($fragment->selectionSet, $descend), |
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 do we need the casts?
Seems to me it works without them?
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.
At some point, phpstan failed because of not having cast. array_replace_recursive
can return array or null (in case of error, but I couldn't find more details about when that happens and why), but array_merge_recursive
always returns array. So at the end, we need casting to array now.
Co-Authored-By: Markus Podar <markus@fischer.name>
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.
P.s. I'm an amateur of pull-requests. I hope I described everything well.
I'd say that was a perfect first PR 🥇
Additionally I added a changelog entry for this fix.
Thank you!
Summary
Querying same field (e.g. id) multiple times causes an error because of array_merge_recursive merging values into array.
Failing GraphQL example:
as you can see -
id
is queried 3 times and that's causing an error shown below.Laravel Error response
... and this is why:
becomes
which then is "understood" as relation type of field, trying to select fields
0
and1
from relationshipid
. Solution to this problem is usingarray_replace_recursive
.Type of change
Checklist
composer fix-tyle
P.s. I'm an amateur of pull-requests. I hope I described everything well.