api-platform / api-platform

🕸️ Create REST and GraphQL APIs, scaffold Jamstack webapps, stream changes in real-time.
https://api-platform.com
MIT License
8.7k stars 962 forks source link

Graphql schema changed to NestedInputs on related entities after v3 Update #2295

Open lcottingham opened 2 years ago

lcottingham commented 2 years ago

API Platform version(s) affected: 3.0.0 + 2.7.2 (w/ webonyx/graphql-php: "^14.0" (v14.11.8 installed))

Description
After updating to both 2.7 and 3.0 and toggling metadata_backward_compatibility_layer: false to enable the new metadata system, the GraphQL mutation schema has changed for entity relations (ManyToOne + OneToOne). Now, rather than allowing having a mutation input type of relatedField: String, it now shows relatedField: createRelatedFieldNestedInput. This change is undocumented as far as I can see and only happens once I make the change to the new metadata layer.

How to reproduce
Entity class basic setup

#[ApiResource]
class Book {
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(nullable: false)]
    private ?string $name = null;

    {{ ... some extra columns ... }}

    #[ORM\ManyToOne]
    private ?Author $author = null
}
#[ApiResource]
class Author {
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    {{ ... some extra columns ... }}

    #[ORM\Column(nullable: false)]
    private ?string $authorName = null;
}

GraphQL Mutation Input BEFORE metadata update

input createBookInput (
    clientMutationId: String
    name: String!
    author: String // <--- this changes
)

GraphQL Mutation Input AFTER metadata update

input createBookInput (
    clientMutationId: String
    name: String!
    author: createAuthorNestedInput! // <--- to this?
    ....
)
input createAuthorNestedInput (
    clientMutationId: String
    name: String!
    ....
)

Possible Solution
Honestly, I'm not sure! I have tried being more explicit with the new metadata annotations. Out of ideas.

Additional Context
This is of course an example based on the typically documented Book/Author demos, but the entity markup matches the code I am working with on the project. I have also omitted all specific operations with the assumption that (according to the docs), all item and graphql operations are enabled by default. I also do not have any graphql specific markup in my api_platform.yaml file.

HalfFalcon commented 2 years ago

This is causing an issue for me too. Having to stay at 2.6 is frustrating.