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.
It seems to have been forgotten.
cc @vincentchalamon.
| </uriVariables> | ||
|
|
||
| <operations> | ||
| <operation class="ApiPlatform\Metadata\GetCollection" name="custom_operation_name"/> |
There was a problem hiding this comment.
It is needed since the IRI converter uses the operation name:
core/src/Symfony/Routing/IriConverter.php
Line 157 in f1ecc30
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.
yes we can change it, it should not be overriden
There was a problem hiding this comment.
but usually the name of the operation is used to define the one inside the router therefore this should work as welll
| } | ||
|
|
||
| if (!$hasQueryOperation) { | ||
| $queryOperation = (new Query())->withNested(true); |
There was a problem hiding this comment.
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.
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.
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
OperationNotFoundexception is not needed anymore.Since operations are "nested", they do not appear as top-level queries.
This PR also improves the XML/YAML compatibility.