Skip to content

Custom Validators

Pre-release
Pre-release
Compare
Choose a tag to compare
@chrissm79 chrissm79 released this 10 Apr 22:19
· 3556 commits to master since this release

First, create a class that extends the new validator

// app/Http/GraphQL/Validators/MyCustomValidator.php

use Nuwave\Lighthouse\Support\Validator\Validator;

class MyCustomValidator extends Validator
{
    public function rules()
    {
        // return array of rules...
    }
}

Add validate directive to your schema:

extend type Mutation {
  createFoo(input: FooInput!): FooPayload
    @validate(validator: "App\\Http\\GraphQL\\Validators\\MyCustomValidator")
}