You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
This way at least the client doesn't break down and "empty results" message configured with Search will work.
The text was updated successfully, but these errors were encountered:
kevinquillen
changed the title
resolveValues will error out if query returns no results
resolveValues will error out if query has a fatal error
Sep 21, 2021
If $results errors or is NULL:
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:
This way at least the client doesn't break down and "empty results" message configured with Search will work.
The text was updated successfully, but these errors were encountered: