How can I use meilisearch filters in laravel lighthouse @search directive
I have for example:
type Query {
movies(search: String @search): [Movie!]! @paginate
}
I tried a graphql query with search as a variable but it doesn't work:
{
"search": "'Avengers', ['filter' => 'release_date > 795484800']"
}
Eveything is set up correctly in scout because if I use curl with the example from meilisearch docs everything works correctly! But I cannot figure out how to add filter value to the @search directive in lighthouse.
curl \
-X POST 'http://localhost:7700/indexes/movie_ratings/search' \
-H 'Content-Type: application/json' \
--data-binary '{
"q": "Avengers",
"filter": "release_date > 795484800"
}'
First of all laravel 10.x scout only supports where clauses with
=not with<or>So for the example above I ended up using a local scope that returns a Boolean and I added it to
toSearchableArray().If everything is setup correctly in scout's meilisearch settings (you added
filterableAttributesin theindex-settings) you may use that filter in a where clause inside scout builder.So the query in lighthouse looks like this:
Where
@releasedis a custom directive (arg builder) that implementsScoutBuilderDirectivethat adds to the scout builder: