core icon indicating copy to clipboard operation
core copied to clipboard

[Question]/[FR] Single Table Inheritance in GraphQL

Open kiler129 opened this issue 6 years ago • 2 comments

There were multiple discussions (e.g. https://github.com/api-platform/core/issues/1071) dealing with STI in REST, but I wasn't able to find anything about GraphQL support for that.

Currently I have a single entity which has various external IDs assigned to it in a single collection. These IDs are typed using STI. When calling using REST I get a result similar to this:

{
  "@context": "/api/contexts/AbstractExternalId",
  "@id": "/api/foo/ba95f76a-6b97-420a-bbfa-fd8c9bf45263/external_ids",
  "@type": "hydra:Collection",
  "hydra:member": [
    {
      "@id": "/api/specific_external_id/a4869b6e-fb83-4148-b287-129177b54636",
      "@type": "SpecificExternalId",
      "externalId": "1225004351",
      "id": "a4869b6e-fb83-4148-b287-129177b54636",
      "someDate": "2016-02-22T15:00:00-03:00",
    }
  ],
  "hydra:totalItems": 1
}

Is there any way to achieve this in GraphQL? From what I see the GraphiQL sees only the AbstractExternalId which:

  1. Makes impossible to access fields defined by children
  2. Distinguish which type of the child I'm dealing with
  3. Filter by type

Is this my missconfiguration somewhere or STI is only supported for REST?

Edit: So far to get at least the information about type userland method can be added to a trait and to all children which looks similar to:

    /**
     * @ApiProperty()
     * @Groups({"GraphQLQuery"})
     */
    public function getStiType(): string
    {
        $class = \get_class($this);
        return \substr($class, strrpos($class, '\\')+1);
    }

but obviously that's not a solution ;)

kiler129 avatar Feb 12 '19 22:02 kiler129

Did you ever get a proper solution to this? This seems like a major limitation to be honest

calbro7 avatar Jan 09 '22 04:01 calbro7

three years later... is this issue considered for resolution? Or are there alternative ways to get the fields of the children?

krstns avatar May 24 '22 22:05 krstns

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 04 '22 21:11 stale[bot]