-
-
Notifications
You must be signed in to change notification settings - Fork 566
Add ObjectTypeConfig and ArgConfig #74
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
Conversation
@vladar can you review this please? if OK for you i'll add tests to cover remaining code |
Hey by the way - will be very glad to see this feature in our lib. Thanks for this work! |
} | ||
|
||
public function addField($name, $type, callable $resolve = null, $description = null, ArgsConfig $args = null, callable $complexity = null, $deprecationReason = null) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that we must also cover case when fields and interfaces are defined via Closure. I guess addField is not enough here. I only see following as a solution, but maybe you have other ideas:
$config = ObjectTypeConfig::create()
->name('Test')
->fields(function() {
return FieldsConfig::create()
->addField('name', Type::string(), null, null, ArgsConfig::create()
->addArg('arg1')
->addArg('arg2')
)
);
);
Then we can re-use FieldsConfig for interface type
Edit: another possible approach:
$config = ObjectTypeConfig::create()
->name('Test')
->fields(function(ObjectTypeConfig $conf) {
return $conf
->addField('name', Type::string(), null, null, ArgsConfig::create()
->addArg('arg1')
->addArg('arg2')
)
);
);
Not sure what complications it might cause though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing to consider is if we should put resolve
as 3rd argument. The reason is that we also have resolveField
callback in type config which makes resolve
unnecessary (I personally prefer to use it vs resolve
).
Do you have any objections if we put $resolve
after $args
so that all definitions go first and callbacks after them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also suggest to introduce addDeprecatedField()
to make it visually different from regular fields. Then we'll have two methods:
addField($name, $type, $description = null, ArgsConfig $args = null, callable $resolve = null, callable $complexity = null)
addDeprecatedField($name, $type, $description = null, ArgsConfig $args = null, $deprecationReason, callable $resolve = null, callable $complexity = null)
Please let me know if it makes sense for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And yet another idea is to have some facade class which will allow us to avoid remembering ObjectTypeConfig, FieldsConfig, ArgsConfig, etc.
Maybe some Config::objectType()
, Config::fields()
, Config::args()
etc. Then we only need to use
one class and can rely on autocomplete for different config sections. If it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok no prob for the order of the addField Arguments, also +1 for the addDeprecatedField
. we must be careful of reusing fields definition in closure because same instance will be share in interface and object. I'll work on all this latter. Thanks for the review :)
Feel free to merge it yourself when ready. One thing that is missing though is documentation. New docs are stored in /docs folder. Please add new file about builder when you have a chance. I guess it makes sense to explicitly mention that it is experimental API which will likely to change (docs are powered by mkdocs, so documentation site structure is defined in Also just a friendly request - can you avoid Traits? I know it is opinionated view, but if we can avoid them without major impact on codebase - I'd appreciate it. If not - I can still live with it. |
Ok i'll work on this later 👍 |
Can we get this merged? Even without documentation the builders are quite clear from the testcase and I'd like to use them. |
I completely forgot this PR, I will add documentation this week end so we can merge it 👍 |
Introduce optional ConfigBuilder (see webonyx#70)
31cdc0b
to
758294a
Compare
@mcg-web Awesome! 👍 |
So, any progress? :-) |
I'm Improving the coverage to be sure to don't miss nothing... I'll submit my changes this morning. |
@vladar this can be merge in master or we must wait for next major release? |
Please wait for a bit. I dug a bit deeper into it and I think we might want to use a different approach. I'm writing an issue right now. |
OK here is the initial issue #70 |
I think I can merge it before the next version release. So just keep it as is. Actually, I am not sure if we do need it at all (since many people introduce their own methods of building types or use framework-specific libs which do it for them). Adding it to the main library may add some confusion about the right way to do things. @mcg-web what do you think about it? Will you guys use these builders for symfony bundle? |
No in the bundle we using the generator types so no need of this. We can close this. Less codes to maintain :D. |
Introduce optional ConfigBuilder (see #70)