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

validate field arguments #608

Merged
merged 12 commits into from
Apr 20, 2020
Merged

Conversation

crissi
Copy link
Contributor

@crissi crissi commented Mar 21, 2020

Summary

Fixes #602

Rules never worked in field arguments.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • Code style has been fixed via composer fix-style

@crissi
Copy link
Contributor Author

crissi commented Mar 21, 2020

Depth is hardcoded, would adding a static setter be sufficient?

ResolveInfoFieldsAndArguments is fired twice if you are also using SelectField, maybe this could be moved, out, any suggestion to how you would do that @mfn ?

@crissi crissi changed the title [WIP] validate field arguments validate field arguments Mar 26, 2020
@mfn
Copy link
Collaborator

mfn commented Mar 26, 2020

@crissi ready for review?

@crissi
Copy link
Contributor Author

crissi commented Mar 26, 2020

yes

Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depth is hardcoded, would adding a static setter be sufficient?

ResolveInfoFieldsAndArguments is fired twice if you are also using SelectField, maybe this could be moved, out, any suggestion to how you would do that @mfn ?

Thanks for pointing this out.

IMHO yes, we definitely should improve this; ResolveInfoFieldsAndArguments can be quite costly.

Since validation is an "always on" feature, we have to resolve this anyway so we can do it already before calling validateFieldArguments and keep a reference to the result, which we then also pass to instanciateSelectFields() and we can already pass it directly into \Rebing\GraphQL\Support\SelectFields::__construct, removing/refactoring \Rebing\GraphQL\Support\SelectFields::getFieldSelection

Regarding the depth: maybe we need to change this approach:

  • we keep the default of 5 hardcoded
  • but add a config to override that default
  • and add the ability to define the depth optionally on the query => would that be possible (just as config option on the graphql query type?)

Does that make sense?


I might have more feedback but we should sort out the high-level stuff first, thanks!

src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks great!

A few minor feedbacks but after that and update with master it's good to merge from my side, thank you!

@@ -123,6 +145,11 @@ protected function getResolver(): ?Closure
}
}

$fieldsAndArguments = (new ResolveInfoFieldsAndArguments($arguments[3]))->getFieldsAndArgumentsSelection($this->depth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No the big prize question: how can we avoid resolving this if there aren't going to be any validations (they're optional after all)? Do you see any way to achieve this?

Seems like a catch-22: only when we run RulesInFields for which we already have to extract "fields and arguments" we can then know that we wouldn't have to run it 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could probably write a function that checks if any arguments exists that would be less costly than the ResolveInfoFieldsAndArguments, and then only run ResolveInfoFieldsAndArguments if using selectfields and arguments... but not sure how much it will actually give.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, let's scrap that for now!

CHANGELOG.md Show resolved Hide resolved
src/Support/Field.php Show resolved Hide resolved
src/Support/Field.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/RulesInFields.php Outdated Show resolved Hide resolved
src/Support/SelectFields.php Outdated Show resolved Hide resolved
@crissi crissi force-pushed the add_subquery_args_validations branch from afdaa6e to 427d6d9 Compare April 20, 2020 18:48
@mfn
Copy link
Collaborator

mfn commented Apr 20, 2020

The job with the integration test is failing, I'll restart it

@mfn
Copy link
Collaborator

mfn commented Apr 20, 2020

hm, nope, fails too https://travis-ci.org/github/rebing/graphql-laravel/jobs/677399766#L380 :

PHP Fatal error:  Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar:///home/travis/.phpenv/versions/7.3.17/bin/composer/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

That's 1.6GB so no point in bumping the memory_limit, something is off here.

My first idea maybe something in composer changed, a newer version, but https://travis-ci.org/github/rebing/graphql-laravel/jobs/677399766#L148

Composer version 1.8.4 2019-02-11 10:52:10

I pushed a commit to see how it goes when we composer self-update

@mfn
Copy link
Collaborator

mfn commented Apr 20, 2020

https://travis-ci.org/github/rebing/graphql-laravel/jobs/677442929#L152

Composer version 1.10.5 2020-04-10 11:44:22

$ composer self-update
You are already using composer version 1.10.5 (stable channel).

Ach #fail

Meh, must be something else as the trace comes from within the resolver…

I'll try the composer 2.0 preview, maybe we're lucky :)

@mfn
Copy link
Collaborator

mfn commented Apr 20, 2020

I'll try the composer 2.0 preview, maybe we're lucky :)

We were 🍀 !

@mfn mfn merged commit 81ed042 into rebing:master Apr 20, 2020
mfn added a commit that referenced this pull request Apr 23, 2020
@mfn
Copy link
Collaborator

mfn commented Apr 23, 2020

@crissi you might already noticed, this added a regression see #627

Please feel free to "revert my revert" and apply a fix (probably the InvariantException thingy, 95% sure)

Thanks!

(and sorry for my feedback: pretty sure I was the reason why we removed it)

@crissi
Copy link
Contributor Author

crissi commented Apr 23, 2020 via email

crissi pushed a commit to crissi/graphql-laravel that referenced this pull request Jun 8, 2020
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.

Subquery args validations
2 participants