core
core copied to clipboard
Declare GetCollection operation only on resource
Considering the following resource:
#[ApiResource(graphQlOperations: [], operations: [new GetCollection])]
class Foo
{
public function __construct(
#[ApiProperty(identifier: false)]
private string $id
) {}
}
The collection is not able to generate an iri for each items cause no item operation is available. The trick should be to add a new Get operation with a NotFoundAction::class controller...
The cleanest way to handle it would be separate the Collection resource from the Item resource, but let's be real: it's not the best DX. The solution is to automatically add an operation (NotExposed) if no item operation is found on the resource, which helps to generate the item iri, and if no identifier is available on the resource use a skolem iri (and don't expose it in Symfony routing).
Version impacted: 2.7