-
-
Notifications
You must be signed in to change notification settings - Fork 903
fix(graphql): use default nested query operations #5174
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(graphql): use default nested query operations #5174
Conversation
356a6f5
to
10389cc
Compare
$collection = $this->phpize($operation, 'collection', 'bool', false); | ||
if (Query::class === $class && $collection) { | ||
$class = QueryCollection::class; | ||
} | ||
|
||
$delete = $this->phpize($operation, 'delete', 'bool', false); | ||
if (Mutation::class === $class && $delete) { | ||
$class = DeleteMutation::class; | ||
} |
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.
It seems to have been forgotten.
cc @vincentchalamon.
@@ -15,7 +15,7 @@ | |||
</uriVariables> | |||
|
|||
<operations> | |||
<operation class="ApiPlatform\Metadata\GetCollection" name="custom_operation_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.
It is needed since the IRI converter uses the operation name:
core/src/Symfony/Routing/IriConverter.php
Line 157 in f1ecc30
return $this->router->generate($operation->getName(), $identifiers, $operation->getUrlGenerationStrategy() ?? $referenceType); |
In the previous version of the
ExtractorResourceMetadataCollectionFactory
, the name was overridden. The AttributesResourceMetadataCollectionFactory
does not do that.Does it mean we cannot customize the operation name @soyuka?
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.
yes we can change it, it should not be overriden
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.
but usually the name of the operation is used to define the one inside the router therefore this should work as welll
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.
Fixed!
} | ||
|
||
if (!$hasQueryOperation) { | ||
$queryOperation = (new Query())->withNested(true); |
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.
mb comment on Nested or here that this operation is then use when we fetch a query through another query
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.
Isn't the comment on the method sufficient?
This is way better! Minor changes but then we can merge this! |
35b266b
to
908ad4d
Compare
Instead of relying on a resource metadata factory to retrieve a "dynamic" nested query operation, this PR adds default nested query operations if the resource does not have one. It simplifies a lot of things and catching the OperationNotFound exception is not needed anymore. Since operations are "nested", they do not appear as top-level queries. This PR also improves the XML/YAML compatibility.
908ad4d
to
c1032e9
Compare
foreach ($resource->getOperations() ?? $this->getDefaultHttpOperations($resource) as $i => $operation) { | ||
[$key, $operation] = $this->getOperationWithDefaults($resource, $operation, $resource->getOperations() ? false : true); | ||
$operations[$key] = $operation; | ||
if (null === $resource->getOperations()) { |
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.
This was causing issues with the XML/YAML extractor (operations added twice), I think this modification improves the code (getOperationWithDefaults
never called twice!).
thanks @alanpoulain ! |
i currently have the issue, that i query a single item with an id with nested Items.
Example Query:
Is that related or a new issue? |
Instead of relying on a resource metadata factory to retrieve a "dynamic" nested query operation, this PR adds default nested query operations if the resource does not have one.
It simplifies a lot of things and catching the
OperationNotFound
exception is not needed anymore.Since operations are "nested", they do not appear as top-level queries.
This PR also improves the XML/YAML compatibility.