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

fix(docs): Correct documentation for validateSync and validateWithSync #9080

Merged
merged 4 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/docs/services.md
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ validate(input.value, 'Value', {
```
### validateWithSync()

`validateWith()` is simply given a function to execute. This function should throw with a message if there is a problem, otherwise do nothing.
`validateWithSync()` is simply given a function to execute. This function should throw with a message if there is a problem, otherwise do nothing.

```jsx
validateWithSync(() => {
Expand All @@ -636,14 +636,14 @@ validateWithSync(() => {

Either of these errors will be caught and re-thrown as a `ServiceValidationError` with your text as the `message` of the error (although technically you should always throw errors with `new Error()` like in the second example).

You could just write your own function and throw whatever you like, without using `validateWith()`. But, when accessing your Service function through GraphQL, that error would be swallowed and the user would simply see "Something went wrong" for security reasons: error messages could reveal source code or other sensitive information so most are hidden. Errors thrown by Service Validations are considered "safe" and allowed to be shown to the client.
You could just write your own function and throw whatever you like, without using `validateWithSync()`. But, when accessing your Service function through GraphQL, that error would be swallowed and the user would simply see "Something went wrong" for security reasons: error messages could reveal source code or other sensitive information so most are hidden. Errors thrown by Service Validations are considered "safe" and allowed to be shown to the client.

### validateWithSync()
### validateWith()

The same behavior as `validateWithSync()` but works with Promises.
The same behavior as `validateWithSync()` but works with Promises. Remember to `await` the validation.

```jsx
validateWithSync(async () => {
await validateWith(async () => {
if (await db.products.count() >= 100) {
throw "There can only be a maximum of 100 products in your store"
}
Expand Down