Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

resolveValues will error out if query has a fatal error

Open
#49 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
48/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
graphql, php
Domain
api, backend, search

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from drupal-graphql/graphql-search-api

All issues in drupal-graphql/graphql-search-api

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.