daniel-de-wit / lighthouse-sanctum

Laravel Sanctum support for Laravel Lighthouse
MIT License
57 stars 9 forks source link

Replace "exists:users,id" validation with logic in mutation #21

Closed wimski closed 3 years ago

wimski commented 3 years ago

The following definition exists with validation for user existence.

input VerifyEmailInput {
    id: ID! @rules(apply: ["required", "exists:users,id"])
    hash: String! @rules(apply: ["required", "string"])
}

Although the table name for the authenticatable model is users in 99% of cases, someone could change this in config. The validation for user existence therefore has to be done in the mutation, where it can be done independent of knowing the table name.

$user = $userProvider->retrieveById($args['id']);

if (! $user) {
    // validation exception
}