-
Notifications
You must be signed in to change notification settings - Fork 223
Description
| Q | A |
|---|---|
| Bug report? | no |
| Feature request? | yes |
| BC Break report? | no |
| RFC? | no |
| Version/Branch | 1.0.0 |
I'm currently working on a pretty big corporate application. So I have many entities with cruds, forms, etc... So a lot of code is "automatic" and it's great. I know feel the same need expressed here : #683
The use case is quite simple. When I create a form for an entity (and I have many), I describe my Input with foreign key id as Int and I have to convert them back to entities in my resolver.
For example:
HeroInput:
type: input-object
config:
fields:
name:
type: "String!"
partnerId:
type: "Int"And in my resolver, I have to do something like :
function resolve($input) {
$hero = new Hero();
$hero->setName($input['name']);
$partner = $this->getEntityManager()->getRepository(Hero::class)->find($input['partnerId']);
$hero->setPartner($partner);
}So, I have to be specific for each different entity (one resolver by entity), preventing me from having a single generic resolve function.
If we could automatically generate scalars to represent each entity, we could save a lot of time.
The Input would become:
HeroInput:
type: input-object
config:
fields:
name:
type: "String!"
partnerId:
type: "HeroId"and the resolver :
function resolve($input) {
$hero = new Hero();
$hero->setName($input['name']);
$hero->setPartner($input['partner']);
}and the generated scalar would simply be a id to entity converter like #683 (comment) for example.
The option could be opt in by simply adding a "generateScalar" boolean option on the @GQL\Type annotation. I'm not sure how we could implement this out of annotation.
Let me know what you think.