Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Embeddable classes #28

Open
popovserhii opened this issue Jun 18, 2019 · 2 comments
Open

Support Embeddable classes #28

popovserhii opened this issue Jun 18, 2019 · 2 comments

Comments

@popovserhii
Copy link
Contributor

popovserhii commented Jun 18, 2019

Doctrine 2 has a great feature named as Embeddable classes.
I try to use it in the pair with graphql-doctrine and got error No type registered with key Position. Either correct the usage, or register it in your custom types container when instantiating GraphQL\Doctrine\Types, where Position is a simple object

namespace Stagem\Product\Model\Monitor;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Embeddable
 */
class Position
{
    /**
     * @ORM\Column(type="integer")
     */
    private $line = 1;

    /**
     * @ORM\Column(type="integer")
     */
    private $column = 1;
    // ...
}

and RankMonitor model

namespace Stagem\Product\Model;

use Doctrine\ORM\Mapping as ORM;
use GraphQL\Doctrine\Annotation as API;
use Stagem\Product\Model\Monitor\Position;

/**
 * @ORM\Entity()
 * @ORM\Table(name="product_rank_monitor")
 */
class RankMonitor
{
    /**
     * @var int
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * @ORM\Column(type="integer", options={"unsigned":true})
     */
    private $id;

    /**
     * @var Position
     * @ORM\Embedded(class="Stagem\Product\Model\Monitor\Position", columnPrefix="position_")
     */
    private $position;
    // ...
}

Do you plan to add native support for Embeddable classes or maybe can explain how to implement this feature?

@PowerKiKi
Copy link
Member

I was not aware of the Embeddable feature. That sounds like it could be quite useful for some our use-cases as well, (storing money with value and currency, or time and timezone). While I do not have plan to implement it right now, it could be implemented some day if we end up using it.

In the meantime, I assume you could workaround the limitation by implementing a custom GraphQL type and declaring it when creating an instance of Types.

As I don't have experience working with Embeddable I cannot give good advice on how to implement it properly. Maybe the workaround is enough ? Maybe there could be a way to automate it in a similar way that we do for entities ?

@popovserhii
Copy link
Contributor Author

Implementing a custom GraphQL type require much manual work which is redundant when there are many Embeddable entities that's why I discarded from it, but automation is the exactly what many will expect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants