|
22 | 22 | use ApiPlatform\Metadata\Exception\RuntimeException; |
23 | 23 | use ApiPlatform\Metadata\Get; |
24 | 24 | use ApiPlatform\Metadata\GetCollection; |
| 25 | +use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation; |
25 | 26 | use ApiPlatform\Metadata\HttpOperation; |
26 | 27 | use ApiPlatform\Metadata\IdentifiersExtractorInterface; |
27 | 28 | use ApiPlatform\Metadata\IriConverterInterface; |
@@ -87,24 +88,30 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation |
87 | 88 | throw new InvalidArgumentException(\sprintf('The iri "%s" does not reference the correct resource.', $iri)); |
88 | 89 | } |
89 | 90 |
|
90 | | - $operation = $parameters['_api_operation'] = $this->resourceMetadataCollectionFactory->create($parameters['_api_resource_class'])->getOperation($parameters['_api_operation_name']); |
| 91 | + $routeOperation = $parameters['_api_operation'] = $this->resourceMetadataCollectionFactory->create($parameters['_api_resource_class'])->getOperation($parameters['_api_operation_name']); |
91 | 92 |
|
92 | | - if ($operation instanceof CollectionOperationInterface) { |
| 93 | + if ($routeOperation instanceof CollectionOperationInterface) { |
93 | 94 | throw new InvalidArgumentException(\sprintf('The iri "%s" references a collection not an item.', $iri)); |
94 | 95 | } |
95 | 96 |
|
96 | | - if (!$operation instanceof HttpOperation) { |
| 97 | + if (!$routeOperation instanceof HttpOperation) { |
97 | 98 | throw new RuntimeException(\sprintf('The iri "%s" does not reference an HTTP operation.', $iri)); |
98 | 99 | } |
99 | 100 | $attributes = AttributesExtractor::extractAttributes($parameters); |
100 | 101 |
|
101 | 102 | try { |
102 | | - $uriVariables = $this->getOperationUriVariables($operation, $parameters, $attributes['resource_class']); |
| 103 | + $uriVariables = $this->getOperationUriVariables($routeOperation, $parameters, $attributes['resource_class']); |
103 | 104 | } catch (InvalidIdentifierException|InvalidUriVariableException $e) { |
104 | 105 | throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e); |
105 | 106 | } |
106 | 107 |
|
107 | | - if ($item = $this->provider->provide($operation, $uriVariables, $context)) { |
| 108 | + // If a caller-provided GraphQl operation carries its own provider, dispatch through it |
| 109 | + // so the user-defined Query(provider: X) wins over the route-matched HTTP operation. |
| 110 | + $dispatchOperation = ($operation instanceof GraphQlOperation && null !== $operation->getProvider()) |
| 111 | + ? $operation |
| 112 | + : $routeOperation; |
| 113 | + |
| 114 | + if ($item = $this->provider->provide($dispatchOperation, $uriVariables, $context)) { |
108 | 115 | return $item; |
109 | 116 | } |
110 | 117 |
|
|
0 commit comments