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

Better arguments and inputs validation #799

Closed
gustavovnicius opened this issue Jun 20, 2017 · 5 comments
Closed

Better arguments and inputs validation #799

gustavovnicius opened this issue Jun 20, 2017 · 5 comments

Comments

@gustavovnicius
Copy link

gustavovnicius commented Jun 20, 2017

It would be good to have something similar to how grape validates and coerce parameters: https://github.com/ruby-grape/grape#parameter-validation-and-coercion
Things like: mutually_exclusive, exactly_one_of, and custom validators

@rmosolgo
Copy link
Owner

Thanks for the suggestion! Best of all would be to implement these via query analyzers, so you can run validation before starting to execute the query.

@modosc
Copy link
Contributor

modosc commented Jun 26, 2018

@rmosolgo do you have an example of accessing parameters inside of a QueryAnalyzer? i can find the giant params object but i can't figure out how to go from a given irep_node to the supplied value.

@modosc
Copy link
Contributor

modosc commented Jun 27, 2018

sorry - i should be more specific. i see how to get access to the single arguments object passed in but i don't want to parse that tree again since it's already been done once in static validation. would it be possible to get the irep_node in the static validation proc?

@rmosolgo
Copy link
Owner

No, it's not possible to get the irep_node during validation, because it hasn't been built yet! InternalRepresentation::Rewrite actually tags along behind the validation visitors, building irep_nodes as validation finishes.

@modosc
Copy link
Contributor

modosc commented Jun 28, 2018

hah, i figured this out the hard way yesterday - accessing the parameters in a debugger totally worked but doing it in code caused stack too deep exceptions.

it would be cool to have the equivalent of a coerce_input callback with the irep_node (maybe analyze_input?) - this would make it cleaner to write validations that are conditional based on other sibling / parent nodes or nodes that have to be coerced first. i think that would make some code like this cleaner - right now i'm writing a giant FooValidationAnalyzer for a FooInputType - i expected i'll have to continue this pattern along even though a lot of the logic could be shared via the field.

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

No branches or pull requests

3 participants