Using input in laravel 9 / lighthouse 6 app:
input VoteCategoryInput {
name: String! @rules(apply: ["string", "min:2", "max:255", "unique:vote_categories"]),
active: Boolean!,
in_subscriptions: Boolean!,
meta_description: String,
meta_keywords: [String],
}
extend type Mutation {
createVoteCategory(
input: VoteCategoryInput! @spread
): VoteCategory! @create
and running mutation :
mutation {
createVoteCategory (
input: {
name: "Vote Category name"
active: true
in_subscriptions: true
meta_keywords: ["meta_keywords 1", "meta_keywords 2"]
}
) {
id
name
slug
in_subscriptions
meta_description
meta_keywords
created_at
}
}
I got error :
"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'input.name' in 'where clause'
(SQL: select count(*) as aggregate from `vote_categories` where `input`.`name` = Vote Category name)",
Which syntax have I to use to exclude “input.” in sql-statement ?
The Lighthouse docs describe a caveat with the unique
rule here: https://lighthouse-php.com/master/security/validation.html#validating-input-objects
Using the unique
validation rule can be a bit tricky.
If the argument is nested within an input object, the argument path will not match the column name, so you have to specify the column name explicitly.
input CreateUserInput {
email: String @rules(apply: ["unique:users,email_address"])
}