Skip to content

Conversation

@rthideaway
Copy link
Contributor

This would be a useful info to get as it is kind of context which could be used in data producers. I can illustrate it on one of our data producers.

We have data producer doing search api solr query:

// Search API jobs query.
$registry->addFieldResolver('Query', 'jobs', $builder->compose(
  $builder->context('search_id', $builder->fromValue('jobs_search')),
  $builder->produce('search_api_load', [
    'index_id' => $builder->fromValue('job_search'),
    'language' => $builder->fromArgument('language'),
    'range' => $builder->fromArgument('ranges'),
    'sort' => $builder->fromValue([]),
    'fulltext' => $builder->fromArgument('fulltext'),
  ])
));

After execuion of search api query we do some alters to solarium query to use some specific solr features which cannot be used within SearchApiQuery object. We do that in hook_search_api_solr_query_alter. Our data producer sets search id so it's easily target-able in that hook:

// Set search id context to the query so it's easily target-able.
if ($search_id = $context->getContextValue('search_id')) {
  $this->query->setSearchId($search_id);
}

This would be much easier if we could obtain fieldName property of resolve info within FieldContext because it's unique. So instead of creating some custom context we'd just use this:

    $query->setSearchId($fieldContext->getFieldName());

This PR should make it possible.

@codecov
Copy link

codecov bot commented Oct 28, 2019

Codecov Report

Merging #929 into 8.x-4.x will decrease coverage by 0.08%.
The diff coverage is 0%.

Impacted file tree graph

@@              Coverage Diff              @@
##             8.x-4.x     #929      +/-   ##
=============================================
- Coverage      61.63%   61.54%   -0.09%     
- Complexity       678      679       +1     
=============================================
  Files             95       95              
  Lines           1405     1407       +2     
=============================================
  Hits             866      866              
- Misses           539      541       +2
Impacted Files Coverage Δ Complexity Δ
src/GraphQL/Execution/FieldContext.php 22.22% <0%> (-2.78%) 7 <1> (+1)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9209b65...7078634. Read the comment docs.

@pmelab pmelab added the 4.x label Oct 30, 2019
@fubhy fubhy merged commit 261c80b into drupal-graphql:8.x-4.x Feb 22, 2020
@rthideaway rthideaway deleted the feature/allow-obtain-field-name branch February 24, 2020 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants