Skip to content

No mapping found for field <field> on class <class> on graphql request when adding a getter with the same return type as a doctrine association #5200

Description

@Megumin42

API Platform version(s) affected: 3.0.4

Description
When an entity has a getter with the same type as a relation the Link generated by the LinkFactory gets overriden by the link detected via the getter in LinkResourceMetadataCollectionFactory::mergeLinks.

How to reproduce

  1. Take api-platform demo app
  2. Add the following getter to Book.php
public function getSomeImportantReview(): Review
{
    return new Review();
}
  1. Execute the following graphql query
{
  books {
    edges {
      node {
        id
        reviews {
          edges {
            node {
              id
            }
          }
        }
      }
    }
  }
}
  1. You should receive the following error message
"No mapping found for field 'someImportantReview' on class 'App\\Entity\\Book'.",

Possible Solution
Depending on whether this usage should be supported the Links generated by LinkFactory::createLinksFromRelations should only include doctrine relations and no relations detected by getter only.

Additional Context

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions