resolveValues will error out if query has a fatal error
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Start in modules/contrib/graphql_search_api/src/Plugin/GraphQL/Fields/SearchAPISearch.php and inspect resolveValues(), especially the query execution and exception path. Reproduce a failed or null search result if possible, then verify that the GraphQL response remains valid and reports zero results instead of triggering an undefined-variable notice or a client-side 500 error.
Written by the indexing model from the issue text.
Description
If $results errors or is NULL:
public function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) {
// Load up the index passed in argument.
$this->index = $this->entityTypeManager->getStorage('search_api_index')->load($args['index_id']);
// Prepare the query with our arguments.
$this->prepareSearchQuery($args);
// Execute search.
try {
$results = $this->query->execute();
}
// Handle error, check exception type -> SearchApiException ?
catch (\Exception $exception) {
$this->logger->get('graphql_search_api')->error($exception->getMessage());
}
// Get search response from results.
$search_response = $this->getSearchResponse($results);
// Add the result count to the response.
$search_response['result_count'] = $results->getResultCount();
// Set response type.
$search_response['type'] = 'SearchAPIResult';
yield $search_response;
}
I get a PHP notice:
"Notice: Undefined variable: results in Drupal\graphql_search_api\Plugin\GraphQL\Fields\SearchAPISearch->resolveValues() (line 97 of modules/contrib/graphql_search_api/src/Plugin/GraphQL/Fields/SearchAPISearch.php)."
In the browser I get a JS 500 error about an unexpected token.
This turns out to be (a rather common case) if you are running Solr and the Solr results are stale and return items that aren't in Drupal (like say, syncing a prod database to dev) and Drupal cannot load the item to display in a result. This is a little hard to track down if you aren't familiar with Search API and Solr.
I think the 3 lines pertaining to $search_response should be moved into the try block, and the catch block should have:
$search_response = [];
$search_response['result_count'] = 0;
$search_response['type'] = 'SearchAPIResult';
This way at least the client doesn't break down and "empty results" message configured with Search will work.
- Dominant language
- PHP
- Stars
- 10
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from drupal-graphql/graphql-search-api
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Graphql v4Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
drupal-graphql/graphql-search-api#55 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
drupal-graphql/graphql-search-api#54 · 1 comment ·
-
Mulitvalued custom field results are incompletePossibly taken @carolpettirossi claimed this 2044 days ago. Openbug needs review/QA
drupal-graphql/graphql-search-api#40 · 1 comment · 1 assignee ·
-
Facets with LanguageOpenenhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
drupal-graphql/graphql-search-api#35 · 2 comments ·
All issues in drupal-graphql/graphql-search-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
PHP-CS-Fixer/PHP-CS-Fixer#9899 ·
Maintainers usually reply within 1 day
-
needs-triage Platform(Default)
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 2 days
-
sync-en
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
[Sync EN] Document Error thrown by shm_* functions on a detached segment (#5975)Possibly taken A pull request linked to this issue is open or already merged. Opensync-en
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 3 days
-
Перевод устарел
Difficulty 2/5 1-3 hours Newbie friendliness 72/100