Create nested doctine objects with one GraphQl query with API Platform

I have a basic Entity in my symfony application:

/**
* @ApiResource()
* @ORMEntity(repositoryClass=CardRepository::class)
*/
class Card
{
   /**
    * @ORMId()
    * @ORMGeneratedValue()
    * @ORMColumn(type="integer")
    */
    private $id;

    /**
     * @ORMOneToMany(targetEntity=CardReference::class, mappedBy="card", orphanRemoval=true)
 */
    private $cardReferences;

    /**
    * @ORMColumn(type="string", length=255, nullable=true)
    */
   private $name;

As you can see – there is another Entity: CardReference with a OneToMany Relationship.

So now – when I create a new Card:

mutation AddCard($name: String!) {
    createCard(input: { name: $name }) {
        card {
            name
        }
    }
}

I wonder what way to go for creating also a CardReference.
Because this comes everytime hand in hand. Every Card needs at least one CardReference – so a default one should be created on creation of the card.

Ist the right way to do it with another GraphQL query afterwards?
Or is this an usecase for writing a custom resolver?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *