Thank you by advance for your help ! Before detailing my need, let me introduce the context :
Project stack:
tech/lib | version |
---|---|
php | 8.1 |
symfony | v6.1 |
api-platform | v2.6 |
webonyx/graphql-php | v14.11 |
Doctrine model/entities
To simplify the example, I've used the example found in this doc.
My Event class is abstract :
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: "event")]
#[ORM\InheritanceType("SINGLE_TABLE")]
#[ApiResource]
abstract class Event
{
//...
}
The others (Concert, Festival and Conference) are extending it :
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ApiResource]
class Concert extends Event
{
//...
}
and so on for the others.
My goal
I want to use inline fragment to get in a single query my concrete events :
query {
events {
edges {
node {
id
name
minAgeRestriction
startsAt
... on Festival {
performers
}
... on Concert {
performingBand
}
... on Conference {
speakers
workshops
}
}
}
}
}
The error I get
Fragment cannot be spread here as objects of type "Event" can never be of type "Concert".
How to tell GraphqlPhp through ApiPlatform to generate union type ? Did I missed something ? Is it not possible yet with api-platform ?
I'm not expert at all on GraphQL but I don't see anything about inline fragment in api-platform while graphql-php looks to support it w: https://webonyx.github.io/graphql-php/type-definitions/unions/
Could be related : https://github.com/api-platform/api-platform/issues/2105 What do you think ? Any clue ?