-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Cloud code validation #226
Cloud code validation #226
Conversation
This is very cool, @codegefluester! 👍 |
If you could write up a post/docs about this, we should host it somewhere.. |
Sure thing @gfosco, what would be the best place to put this? |
@codegefluester from what I understand, this doesn't enable multiple required parameters right? Do you think that returning an array of params is a great idea? I see that currently it only checks for one value, what would make an array not an option. |
@natanrolnik You can actually verify as many parameters as you want. We pass in the complete object of parameters of the request and all you need to do is returning true or false. I just used one parameter in the example to simplify it a bit. I also noticed that it probably would be better to pass in the complete request as the current implementation would not contain |
Implemented in #468 |
If your Cloud Functions have required parameters, you can do this today:
OR
Depending on the approach you use you might end up duplicating code or writing more if-not-valid-return-error kind of code all over the place.
This PR introduces the option to provide a Validator function for a Cloud Function which runs before the actual Cloud Function runs and validates the input parameters of the request. If the validation fails, it will return an error or executes the Cloud Function if the validation succeeds.
Example
OR for multiple functions that share a validator
This PR is just a foundation for other work that can be done around here, for example multiple validators per function, global validators that are only registered once by calling something like
Parse.Cloud.validate(...)
and returning detailed validation errors etc.I added two test in
ParseAPI.spec.js:L547