-
Notifications
You must be signed in to change notification settings - Fork 104
Description
So, I've been playing with trying to get Factories up and running with input types in a sensible dir structure. It's been quite challenging and I think far more challenging than it should have been. Here are a couple things I've noticed and some ideas for improvement.
- When defining the
@Factory(name="Whatever")
, if it's not "WhateverInput", meaning it doesn't end in "Input", then when referenced from the controller usingUseInputType(for="$input", inputType="Whatever")
, GraphQLite throws the Exception:
$input, in [controller method], type "Whatever" must be an input type
- I find that the multi-directional annotations and Factory associations to be very confusing. It'd be far better if these were defined mostly from a single direction (ala the controller), and there were little constraints. IMO, there is far too many assumptions and automagic going on here and it makes implementation difficult, but also means that, down the road, customization is going to be challenging, assuming that's needed.
Just throwing something out here, but I think the following would be better:
class Mutation
{
/**
* Does something.
*
* @GraphQLite\Mutation()
* Could have a "factory" and "method" arg below as well if that syntax is confusing
* @GraphQLite\HandleInputType(
* param="input",
* factory="App\Namespace\Factory::create"
* schemaName="ThingInput"
* )
*
* @param Thing $input
*/
public function doSomething(Thing $input): Result
{
return new Result();
}
}
Then, the Factory class doesn't really need to do anything special at all. In fact, it just needs to be able to be called via the FQCN from the container and is validated to return a type that matches what's expected from the mutation's method signature.
Additionally, this eliminates the need for this recommendation:
We recommend that you put the factories in the same directories as the types.
I'm finding that having multiple methods within a factory, for a given set of operations is the most natural way of handling things. The default
setting is very confusing as well.