|
9 | 9 | use Drupal\graphql\GraphQL\Cache\CacheableValue;
|
10 | 10 | use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase;
|
11 | 11 | use Drupal\graphql\GraphQL\Execution\ResolveContext;
|
| 12 | +use Drupal\search_api\SearchApiException; |
12 | 13 | use GraphQL\Type\Definition\ResolveInfo;
|
13 | 14 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
14 | 15 |
|
|
32 | 33 | * "sort" = "[SortInput]",
|
33 | 34 | * "facets" = "[FacetInput]",
|
34 | 35 | * "more_like_this" = "MLTInput",
|
| 36 | + * "options" = "[SearchApiQueryOptions]", |
35 | 37 | * "solr_params" = "[SolrParameterInput]",
|
36 | 38 | * },
|
37 | 39 | * )
|
@@ -319,6 +321,19 @@ private function prepareSearchQuery($args) {
|
319 | 321 | if ($args['facets']) {
|
320 | 322 | $this->setFacets($args['facets']);
|
321 | 323 | }
|
| 324 | + // Adding options to the query. |
| 325 | + if ($args['options']) { |
| 326 | + foreach ($args['options'] as $option) { |
| 327 | + if($option['json']) { |
| 328 | + $value = json_decode($option['json'], true); |
| 329 | + } elseif($option['value']) { |
| 330 | + $value = $option['value']; |
| 331 | + } else { |
| 332 | + throw new SearchApiException("Option '{$option['key']}' must have value in 'value' or 'json' argument."); |
| 333 | + } |
| 334 | + $this->query->setOption($option['key'], $value); |
| 335 | + } |
| 336 | + } |
322 | 337 | // Adding more like this parameters to the query.
|
323 | 338 | if ($args['more_like_this']) {
|
324 | 339 | $this->setMLT($args['more_like_this']);
|
|
0 commit comments