On laravel site with lighthouse I need to make custom query with some filters and some output fields formatted in custom way
Checking all lighthouse commands :
php artisan lighthouse
I create custom query :
php artisan lighthouse:query Items
But I am not sure how have I to change graphql file and query request? In file graphql/item.graphql I changed :
extend type Query {
# I suppose that to remove @paginate directive
# items [Item!]! @paginate(defaultCount: 10)
items: [Item!]
and query request string:
{
items (filterByStatus: 'a' ) {
id
name
}
}
But in graphql-playground I do not see any errors/messages and no logs activity on laravel side.
Which way is valid and how can I debug such issue ?
As with query request string above graphql-playground does does not triggered at all, but it works ok :
{
items {
id
name
}
}
"laravel/framework": "^9.48.0",
"nuwave/lighthouse": "^6.6"
Thanks in advance
To check if your schema is correct and valid, use the command:
php artisan lighthouse:validate-schema
. See in lighthouse docs more info.
To add that filter filterByStatus
, you need to change your query file graphql/item.graphql
.
extend type Query {
items(
filterByStatus: String @where(key: "status", operator: "like") #I assume is string by the 'a', your key on BD is status and operadtor is like. You can use other directives like @in, @whereIn, @whereKey etc..
): [Item!]
}
All lighthouse directives are in here. If you want to explore more, on lighthouse usage, you have a general example of a query with filters.