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

Add ObjectTypeConfig and ArgConfig #74

Closed
wants to merge 4 commits into from

Conversation

mcg-web
Copy link
Collaborator

@mcg-web mcg-web commented Nov 12, 2016

Introduce optional ConfigBuilder (see #70)

@coveralls
Copy link

coveralls commented Nov 12, 2016

Coverage Status

Coverage decreased (-0.1%) to 88.257% when pulling 0fc1759 on mcg-web:type-config-builder into 986eff9 on webonyx:master.

@mcg-web
Copy link
Collaborator Author

mcg-web commented Nov 12, 2016

@vladar can you review this please? if OK for you i'll add tests to cover remaining code

@coveralls
Copy link

coveralls commented Nov 12, 2016

Coverage Status

Coverage increased (+0.06%) to 88.409% when pulling 95b46b7 on mcg-web:type-config-builder into 986eff9 on webonyx:master.

@vladar
Copy link
Member

vladar commented Nov 12, 2016

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)
{
Copy link
Member

@vladar vladar Nov 12, 2016

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

@mcg-web mcg-web Nov 12, 2016

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 :)

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.3%) to 88.068% when pulling 31cdc0b on mcg-web:type-config-builder into 986eff9 on webonyx:master.

@vladar
Copy link
Member

vladar commented Nov 14, 2016

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 mkdocs.yml).

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.

@mcg-web
Copy link
Collaborator Author

mcg-web commented Nov 14, 2016

Ok i'll work on this later 👍

@enumag
Copy link
Contributor

enumag commented Dec 14, 2017

Can we get this merged? Even without documentation the builders are quite clear from the testcase and I'd like to use them.

@mcg-web
Copy link
Collaborator Author

mcg-web commented Dec 14, 2017

I completely forgot this PR, I will add documentation this week end so we can merge it 👍

@enumag
Copy link
Contributor

enumag commented Dec 14, 2017

@mcg-web Awesome! 👍

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 92.745% when pulling 758294a on mcg-web:type-config-builder into a3f18b5 on webonyx:master.

@enumag
Copy link
Contributor

enumag commented Dec 18, 2017

So, any progress? :-)

@mcg-web
Copy link
Collaborator Author

mcg-web commented Dec 18, 2017

I'm Improving the coverage to be sure to don't miss nothing... I'll submit my changes this morning.

@mcg-web mcg-web changed the title [WIP]Add ObjectTypeConfig and ArgConfig Add ObjectTypeConfig and ArgConfig Dec 18, 2017
@mcg-web
Copy link
Collaborator Author

mcg-web commented Dec 18, 2017

@vladar this can be merge in master or we must wait for next major release?

@enumag
Copy link
Contributor

enumag commented Dec 18, 2017

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 92.939% when pulling 691f558 on mcg-web:type-config-builder into a3f18b5 on webonyx:master.

@mcg-web
Copy link
Collaborator Author

mcg-web commented Dec 18, 2017

OK here is the initial issue #70

@vladar
Copy link
Member

vladar commented Dec 18, 2017

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?

@mcg-web
Copy link
Collaborator Author

mcg-web commented Dec 18, 2017

No in the bundle we using the generator types so no need of this. We can close this. Less codes to maintain :D.

@mcg-web mcg-web closed this Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants