- 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 | 0.12 |
I was wondering if we could come up with some dynamically generated queries and/or mutations.
With the new annotation system, it's really easy to map Doctrine Entities with GraphQL types.
Now, I'd need to be able to generate, based on config, queries & mutations for my Doctrine Entities.
For example, given an Entity name MyEntity, mapped as GraphQL type MyEntity, I'd like to generate a root query like getMyEntities (resolved by the repository method findAll) and getMyEntity($id) (resolved by the repository method find).
This bundle generate and dump the type classes for us based on configuration.
I'm not sure what would be the best way to achieve something like this:
- Should we use a "Fields Builder" (kind of the same way the Field Builder work but to generate multiple fields) and add this "FieldsBuilder" to graphql types.
- Add an additional PHP Parser to be able to return type (but we wouldn't be able to add fields to types config generated by an other parser).
- Add a
@GQL\Crudannotation to be use with the annotations parser (but it would be very specific to annotation & doctrine entities / repositories) - Add a Schema Extension system, that would allow to declare extensions able to modify the types configs generated.
Maybe the solution number 1 is the more flexible and convenient. We would just have to add a property like that:
Query: type: object config: fieldsBuilder: - class: CrudsBuilder config: entities: [MyEntity1, MyEntity2] fields: ... and for example, a Fields Builder like that:
class CrudsFieldsBuilder { public function generateFields(array $config) { $fields = []; foreach($config['entities'] as $entity) { $fields['get' . $entity] = [ 'type' => $entity, 'resolve' =>"@=resolver(...)" ... ]; } return $fields; } } What do you think about this @mcg-web ?