-
-
Notifications
You must be signed in to change notification settings - Fork 438
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty @search
prevents ScoutBuilderDirective
from executing
#2465
Comments
It is not added when the value is
My understanding was that going from |
Yes, I am using that Middleware.
Seems to be fine with accepting null, and it behaves equally to an empty string, at least for Meilisearch. Tinker: > User::search(null)
= Laravel\Scout\Builder {#8066}
> User::search(null)->get()->count()
= 20
> User::search(null)->get() == User::search('')->get()
= true
You are correct. Leaving the empty value means that the field query still works, but it is no longer using scout. It seems like I didn't check properly. I think it is somewhat counter-intuitive because I definitely need fields that will still search on empty values, but if this is expected behavior I will try to make my own way around this. |
The issue I see is that queries may be written in a way to use Scout or database queries. type Query {
users(name: String @search, email: String @eq): [User!]!
} Given the following query string, let's explore what the different variable configurations would do: query ($name: String, $email: String) {
users(name: $name, email: $email) { ... }
} Anything with {"name": "foo"}
{"name": "foo", "email": "[email protected]"} The following do not use {"email": "[email protected]"}
{"email": "[email protected]", "name": null} |
Let's also consider this from a schema evolution perspective. We start with the following schema, not using Scout. type Query {
users(email: String @eq): [User!]!
} Clients query it like this: { users(email: "[email protected]") { id } } Now, we add an additional argument with type Query {
users(name: String @search, email: String @eq): [User!]!
} Suppose that we always use Scout if there is a search argument, even if it is null. |
Interesting, I understand what is happening now. I never considered it that way, and added unique fields for the search variants - I will see how to achieve what I expected to happen. I guess it is only the interaction of the empty strings to null middleware that ultimately "breaks" what I want to do, so it shouldn't be a massive issue. Thanks. |
Probably the better way to go. The current approach is somewhat mysterious to clients and can result in runtime exceptions, e.g. lighthouse/src/Scout/ScoutEnhancer.php Line 138 in 6b0fdde
Laravel's |
I think you technically already have that mechanism, it's Part of my misunderstanding was that passing |
Perhaps we can describe that behaviour in the |
I don't know how common this misunderstanding is, maybe I'm just thinking about this whole GraphQL thing wrong :) Those runtime interactions you detailed above seem to be worth noting as caveats. They feel quite unintuitive to me, and the behavior with empty/null string arguments would just naturally come up. |
While playing around with the type Query {
userSearch(search: String! @search) [User!]!
} The following query will work even with the middleware active, and behave differently depending on whether the argument is declared as query {
userSearch(search: "") {
id
}
} However, doing the same with query: query UserSearch($search: String!) {
userSearch(search: $search) {
id
}
} and variables {
"search": ""
} will produce the error |
Describe the bug
Empty values for
@search
arguments are a valid search use case. Search engines like Meilisearch will return a (more or less useful) set of results even for empty queries. Currently in lighthouse however, theScoutEnhancer
changes its behavior when the search string isnull
or''
. This is due to these code pieces interacting:lighthouse/src/Scout/ScoutEnhancer.php
Lines 98 to 100 in 889c7bc
lighthouse/src/Scout/ScoutEnhancer.php
Lines 51 to 54 in 889c7bc
lighthouse/src/Scout/ScoutEnhancer.php
Lines 62 to 65 in 889c7bc
First, the search argument is not added to the list of search arguments if the value is empty. Then, when the enhancer is probed, it claims there is nothing to be done with the
ScoutBuilder
.I don't quite understand the rest of the control flow enough, but the search itself will be executed correctly. The field will be resolved using a
ScoutBuilder
, and the empty query will be handled by the responsible search engine as expected. However, when otherScoutBuilderDirective
are placed on the argument, they will not be allowed to handle the builder while the search query value is empty. I thinkScoutBuilderDirective
should be able to add additional filters regardless of the search value.Expected behavior/Solution
Any
ScoutBuilderDirective
that wishes to enhance the scout builder should be executed even for empty@search
values.Removing the
is_string
check shown above seems to fix the behavior at first glance, but I don't know if this has deeper repercussions.Steps to reproduce
@search
to enable scoutScoutBuilderDirective
that, for example, places a simple$builder->where('foo', 'bar')
on the buildernull
or''
search strings.Lighthouse Version
v6.22.0
The text was updated successfully, but these errors were encountered: