Skip to content

GraphQL operations definition with yml does not work #5318

@klobastov

Description

@klobastov

API Platform version(s) affected: 3.0.8

Description
GraphQL documents are not generated.

Also, when I remove the use of the configuration mapping "%kernel.project_dir%/config/api_platform", then GraphQL documents are generated successfully.

But when I try to use entity annotation, then they are ignored. This way I can describe either an openapi schema for the API in yml or describe operations for GraphQL in php.

image

How to reproduce
When I try to perform a graphql operation, I get an error
ApiPlatform\Metadata\Resource\Factory\LinkFactory::createLinksFromRelations(): Argument #1 ($operation) must be of type ApiPlatform\Metadata\ApiResource|ApiPlatform\Metadata\Operation, array given, called in /app/vendor/api-platform/core/src/Metadata/Resource/Factory/LinkResourceMetadataCollectionFactory.php on line 43

config/api_platform/resources/entity/gate.yaml

    graphQlOperations:
      queries:
        store_house_list:
          class: ApiPlatform\Metadata\GraphQl\QueryCollection

Additional Context
config/packages/api_platform.yaml

  mapping:
    paths:
      - '%kernel.project_dir%/src/Gate/Entity'
      - '%kernel.project_dir%/src/ApiResource/Poco'
      - '%kernel.project_dir%/config/api_platform'

config/api_platform/resources/entity/gate.yaml

resources:
  Gate\Entity\Gate:
    order:
      serialId: ASC

    normalizationContext:
      groups: [ 'gate:output' ]
    denormalizationContext:
      groups: [ 'gate:input' ]

    operations:
      gate_list:
        class: 'ApiPlatform\Metadata\GetCollection'
        filters: [ 'default.id', 'default.name' ]
        security: is_granted('GATE_LIST', object)

      gate_view:
        class: 'ApiPlatform\Metadata\Get'
        security: is_granted('GATE_LIST', object)

      gate_create:
        class: 'ApiPlatform\Metadata\Post'
        security: is_granted('GATE_CREATE', object)

      gate_update:
        class: 'ApiPlatform\Metadata\Put'
        security: is_granted('GATE_UPDATE', object) and (previous_object.getCreatedBy() === user.getUsername() or is_my_storehouse(object.getStoreHouse().getId() ?? null))

      gate_update_partial:
        class: 'ApiPlatform\Metadata\Patch'
        security: is_granted('GATE_UPDATE', object) and (previous_object.getCreatedBy() === user.getUsername() or is_my_storehouse(object.getStoreHouse().getId() ?? null))

      gate_delete:
        class: 'ApiPlatform\Metadata\Delete'
        security: is_granted('GATE_CREATE', object) and (previous_object.getCreatedBy() === user.getUsername() or is_my_storehouse(object.getStoreHouse().getId() ?? null))

Enity:

#[ORM\Entity(repositoryClass: GateRepository::class)]
#[ApiResource]
class Gate
{
    use BlameableEntity;
    use TimestampableEntity;
    use SequencedEntity;

    #[ORM\Id]
    #[ORM\Column(type: UuidType::NAME, unique: true)]
    #[ORM\GeneratedValue(strategy: 'CUSTOM')]
    #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
    private ?Uuid $id = null;
...
}

Generated API resources
image
And Json Schema
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions