Reputation: 1828
I have an Doctrine Entity Class identified by an iso_code attribute :
/**
* @ApiResource(
* graphql={
* "item_query",
* "collection_query"
* }
* )
*
* @ORM\Entity(repositoryClass="App\Repository\LanguageRepository")
* @ORM\HasLifecycleCallbacks
*/
class Language extends BaseEntity
{
/**
* @var string
* @ApiProperty(identifier=true)
*
* @ORM\Id()
* @ORM\Column(type="string", length=2, unique=true)
*/
private $iso_code;
public function getId(): string
{
return $this->iso_code;
}
public function getIsoCode(): string
{
return $this->iso_code;
}
}
When I try to access a list through a GET requests /api/v2/languages?pages=1
, I got "No identifiers defined for resource of type \"App\\Entity\\Language\""
error.
When I try to access an item through a GET requests /api/v2/languages/en
, I got Invalid identifier value or configuration
Configuration: - api platform v2.5.6 - php 7.4 - symfony 4.4
Upvotes: 1
Views: 5083
Reputation: 41
Solved similar issue by setting identifier @ApiProperty(identifier=true) on top of the getter function
Upvotes: 2
Reputation: 46
You have to add
App\Entity\Language
properties:
id:
identifier: false
iso_code:
identifier: true
Upvotes: 2
Reputation: 1828
Changing the name of the identifier to $id
did the trick.
But I can't get why it's not possible to use $iso_code
Upvotes: -2