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

Revert "Allow to use non-empty constructor for input types" #734

Merged
merged 1 commit into from
Aug 16, 2020

Conversation

mcg-web
Copy link
Member

@mcg-web mcg-web commented Aug 16, 2020

Reverts #656

@mcg-web mcg-web requested a review from Vincz August 16, 2020 16:18
@Vincz
Copy link
Collaborator

Vincz commented Aug 16, 2020

@mcg-web So the idea is that the Arguments Transformer will try to populate Input classes with incoming data. Usually, this Input classes just serve as data objects to handle validation. So, the Arguments Transformer used to instantiate with new InputClass() and It breaks if there is required parameters in the constructor. Instantiating the input class without the constructor prevents this.
But I agree, it's not ideal either to just not call the constructor and can lead to errors. Let's revert it.
There is two options : Maybe when type guessing, we could raise an exception indicating that the Input class cannot be automatically instantiated cause it has required constructor arguments.
Or Maybe we could add a way to add constructor arguments with @GQL\Arg, something like:


class SuperInput {
    constructor(int $superLevel) {
        ....
    }

and use it like that: 

@GQL\Arg(type="SuperInput", constructor={2})

@Vincz Vincz merged commit e5d1cab into master Aug 16, 2020
@mcg-web mcg-web deleted the revert-656-mo-olsavmic-patch-1 branch December 25, 2020 17:38
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.

2 participants