Skip to content

[fix] inverse ternary operator statements #7085

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

Open
wants to merge 1 commit into
base: 3.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/GraphQl/Type/TypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getResourceObjectType(ResourceMetadataCollection $resourceMetada

if ('item_query' === $operationName || 'collection_query' === $operationName) {
// Test if the collection/item has different groups
if ($resourceMetadataCollection->getOperation($operation instanceof CollectionOperationInterface ? 'item_query' : 'collection_query')->getNormalizationContext() !== $operation->getNormalizationContext()) {
if ($resourceMetadataCollection->getOperation($operation instanceof CollectionOperationInterface ? 'collection_query' : 'item_query')->getNormalizationContext() !== $operation->getNormalizationContext()) {
Copy link
Member

Choose a reason for hiding this comment

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

this is wanted see above comment

Copy link
Author

Choose a reason for hiding this comment

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

You mean this "Test if the collection/item has different groups" ? It's not very explicit.

Sorry for not explained with more details but I thought it was obvious to understand. If you don't inverse as I suggest you'll need to allow QueryCollection operation if you only set Query operation. Same for the inverse (Query operation only will need QueryCollection operation). That's because the ternary operator is wrong.

It's history for me as I fixed it locally but I get the message 'Operation "item_query" not found for resource "Project"' from #api-platform/api-platform#2434 which was my case.

Copy link
Member

Choose a reason for hiding this comment

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

In API Platform if a collection operation, an item operation must exist. So probably that the correct fix for this would be to always create an empty item_query if we couldn't find any here.

$shortName .= $operation instanceof CollectionOperationInterface ? 'Collection' : 'Item';
}
}
Expand Down
Loading