【发布时间】:2020-11-10 11:34:33
【问题描述】:
我在 Doctrine 和 Api Platform 之间遇到了问题
我需要一些帮助来序列化嵌入/可嵌入的学说。
从现在开始,我们使用 REST 方法的 Api 平台,但我们想用 GraphQL 制作一个项目,但有些字段没有显示。
我在这里做了一个测试仓库https://github.com/tattali/apip-graphql
当我查询时
{
__type(name: "User") {
name
fields {
name
}
}
}
我只得到未嵌入的字段
{
"data": {
"__type": {
"name": "User",
"fields": [
{
"name": "id"
},
{
"name": "_id"
},
{
"name": "firstname"
},
{
"name": "lastname"
}
]
}
}
}
这是我的实体
<?php
declare(strict_types=1);
namespace App\Entity;
use ApiPlatform\Core\Annotation as Api;
use App\Repository\UserRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @Api\ApiResource
* @ORM\Entity(repositoryClass=UserRepository::class)
*/
class User
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
*/
private $lastname;
/**
* @ORM\Embedded(class="App\Entity\Remuneration")
*/
private $actualRemuneration;
/**
* @ORM\Embedded(class="App\Entity\Remuneration")
*/
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 App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Embeddable
*/
class Remuneration
{
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $fixedSalary;
/**
* @ORM\Column(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;
}
}
【问题讨论】:
标签: symfony doctrine-orm graphql doctrine api-platform.com