1
<?php
2

3
namespace Nuwave\Lighthouse\Validation;
4

5
use Nuwave\Lighthouse\Support\Contracts\ArgDirective;
6

7
class RulesDirective extends BaseRulesDirective implements ArgDirective
8
{
9 1
    public static function definition(): string
10
    {
11
        return /** @lang GraphQL */ <<<'GRAPHQL'
12 1
"""
13
Validate an argument using [Laravel validation](https://laravel.com/docs/validation).
14
"""
15
directive @rules(
16
  """
17
  Specify the validation rules to apply to the field.
18
  This can either be a reference to [Laravel's built-in validation rules](https://laravel.com/docs/validation#available-validation-rules),
19
  or the fully qualified class name of a custom validation rule.
20

21
  Rules that mutate the incoming arguments, such as `exclude_if`, are not supported
22
  by Lighthouse. Use ArgTransformerDirectives or FieldMiddlewareDirectives instead.
23
  """
24
  apply: [String!]!
25

26
  """
27
  Specify a custom attribute name to use in your validation message.
28
  """
29
  attribute: String
30

31
  """
32
  Specify the messages to return if the validators fail.
33
  """
34
  messages: [RulesMessage!]
35
) repeatable on ARGUMENT_DEFINITION | INPUT_FIELD_DEFINITION
36

37
"""
38
Input for the `messages` argument of `@rules`.
39
"""
40
input RulesMessage {
41
    """
42
    Name of the rule, e.g. `"email"`.
43
    """
44
    rule: String!
45

46
    """
47
    Message to display if the rule fails, e.g. `"Must be a valid email"`.
48
    """
49
    message: String!
50
}
51
GRAPHQL;
52
    }
53
}

Read our documentation on viewing source code .

Loading