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

Support custom rule classes in @rules and @rulesForArray #812

Merged
merged 15 commits into from
May 26, 2019
Prev Previous commit
Next Next commit
Move docs for new feature to master
  • Loading branch information
spawnia committed May 26, 2019
commit 25e088a0a72e4dc54eee3d10381c70d21bd3d16b
13 changes: 0 additions & 13 deletions docs/3.6/api-reference/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -1049,17 +1049,6 @@ input CreatePostInput {
}
```

You can also pass your own custom rules, like so:
```bash
php artisan make:rule MyCustomRule
```
Then you can assign the namespace to your rules.
```graphql
input CreatePostInput {
title: String @rules(apply: ["required", "App\\Rules\\MyCustomRule"])
}
```

You can customize the error message for a particular argument.

```graphql
Expand Down Expand Up @@ -1090,8 +1079,6 @@ type Mutation {
}
```

`Note`: You can also use custom rules when defining your @rulesForArray directive. See: [@rules](../api-reference/directives.md#rules) for more info.

## @scalar

Point Lighthouse to your scalar definition class.
Expand Down
22 changes: 16 additions & 6 deletions docs/master/api-reference/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ directive @rename(

## @rules

Validate an argument using [Laravel's built-in validation rules](https://laravel.com/docs/validation#available-validation-rules).
Validate an argument using [Laravel built-in validation](https://laravel.com/docs/validation).

```graphql
type Query {
Expand All @@ -1643,14 +1643,16 @@ type Query {

```graphql
"""
Validate an argument using [Laravel's built-in validation rules](https://laravel.com/docs/validation#available-validation-rules).
Validate an argument using [Laravel built-in validation](https://laravel.com/docs/validation).
"""
directive @rules(
"""
Specify the validation rules to apply to the field.
This can either be a reference to any of Laravel's built-in validation rules: https://laravel.com/docs/validation#available-validation-rules,
or the fully qualified class name of a custom validation rule.
"""
apply: [String!]

"""
Specify the messages to return if the validators fail.
Specified as an input object that maps rules to messages,
Expand All @@ -1677,9 +1679,15 @@ You can customize the error message for a particular argument.
@rules(apply: ["max:140"], messages: { max: "Tweets have a limit of 140 characters"})
```

Reference custom validation rules by their fully qualified class name.

```graphql
@rules(apply: ["App\\Rules\\MyCustomRule"])
```

## @rulesForArray

Run validation on an array itself, using [Laravel's built-in validation rules](https://laravel.com/docs/validation#available-validation-rules).
Run validation on an array itself, using [Laravel built-in validation](https://laravel.com/docs/validation).

```graphql
type Mutation {
Expand All @@ -1693,14 +1701,16 @@ type Mutation {

```graphql
"""
Run validation on an array itself, using [Laravel's built-in validation rules](https://laravel.com/docs/validation#available-validation-rules).
Run validation on an array itself, using [Laravel built-in validation](https://laravel.com/docs/validation).
"""
directive @rulesForArray(
"""
Specify the validation rules to apply to the field.
This can either be a reference to any of Laravel's built-in validation rules: https://laravel.com/docs/validation#available-validation-rules,
or the fully qualified class name of a custom validation rule.
"""
apply: [String!]

"""
Specify the messages to return if the validators fail.
Specified as an input object that maps rules to messages,
Expand Down