Doctrine Embedded not show with GraphQL (Api Platform)

I have an issue between Doctrine and Api Platform

I would like some help to serialize doctrine embedded/embeddable.

From now we are using Api Platform with the REST method but we would like to make a project with GraphQL, but some of the field are not showing.

I made a test repository here https://github.com/tattali/apip-graphql

And when I query

{
  __type(name: "User") {
    name
    fields {
      name
    }
  }
}

I get only the fields not embedded

{
  "data": {
    "__type": {
      "name": "User",
      "fields": [
        {
          "name": "id"
        },
        {
          "name": "_id"
        },
        {
          "name": "firstname"
        },
        {
          "name": "lastname"
        }
      ]
    }
  }
}

Here are my entities

<?php

declare(strict_types=1);

namespace AppEntity;

use ApiPlatformCoreAnnotation as Api;
use AppRepositoryUserRepository;
use DoctrineORMMapping as ORM;

/**
 * @ApiApiResource
 * @ORMEntity(repositoryClass=UserRepository::class)
 */
class User
{
    /**
     * @ORMId
     * @ORMGeneratedValue
     * @ORMColumn(type="integer")
     */
    private $id;

    /**
     * @ORMColumn(type="string", length=255)
     */
    private $firstname;

    /**
     * @ORMColumn(type="string", length=255)
     */
    private $lastname;

    /**
     * @ORMEmbedded(class="AppEntityRemuneration")
     */
    private $actualRemuneration;

    /**
     * @ORMEmbedded(class="AppEntityRemuneration")
     */
    private $expectedRemuneration;

    public function __construct()
    {
        $this->actualRemuneration = new Remuneration();
        $this->expectedRemuneration = new Remuneration();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getFirstname(): ?string
    {
        return $this->firstname;
    }

    public function setFirstname(string $firstname): self
    {
        $this->firstname = $firstname;

        return $this;
    }

    public function getLastname(): ?string
    {
        return $this->lastname;
    }

    public function setLastname(string $lastname): self
    {
        $this->lastname = $lastname;

        return $this;
    }

    public function getActualRemuneration(): ?Remuneration
    {
        return $this->actualRemuneration;
    }

    public function setActualRemuneration(Remuneration $actualRemuneration): self
    {
        $this->actualRemuneration = $actualRemuneration;

        return $this;
    }

    public function getExpectedRemuneration(): ?Remuneration
    {
        return $this->expectedRemuneration;
    }

    public function setExpectedRemuneration(Remuneration $expectedRemuneration): self
    {
        $this->expectedRemuneration = $expectedRemuneration;

        return $this;
    }
}
<?php

declare(strict_types=1);

namespace AppEntity;

use DoctrineORMMapping as ORM;

/**
 * @ORMEmbeddable
 */
class Remuneration
{
    /**
     * @ORMColumn(type="integer", nullable=true)
     */
    private $fixedSalary;

    /**
     * @ORMColumn(type="integer", nullable=true)
     */
    private $fullPackage;

    public function getFixedSalary(): ?int
    {
        return $this->fixedSalary;
    }

    public function setFixedSalary(?int $fixedSalary): self
    {
        $this->fixedSalary = $fixedSalary;

        return $this;
    }

    public function getFullPackage(): ?int
    {
        return $this->fullPackage;
    }

    public function setFullPackage(?int $fullPackage): self
    {
        $this->fullPackage = $fullPackage;

        return $this;
    }
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *