|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Drupal\graphql_core\Plugin\GraphQL\Fields\Routing\ExternalUrl; |
|
4
|
|
|
|
|
5
|
|
|
use Drupal\Core\DependencyInjection\DependencySerializationTrait; |
|
|
|
|
|
|
6
|
|
|
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
|
|
|
|
|
7
|
|
|
use Drupal\Core\Url; |
|
|
|
|
|
|
8
|
|
|
use Drupal\graphql\GraphQL\Execution\ResolveContext; |
|
9
|
|
|
use Drupal\graphql\Plugin\GraphQL\Fields\FieldPluginBase; |
|
10
|
|
|
use GuzzleHttp\ClientInterface; |
|
|
|
|
|
|
11
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
|
|
|
|
12
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Issue an external request and retrieve the response object. |
|
16
|
|
|
* |
|
17
|
|
|
* @GraphQLField( |
|
18
|
|
|
* id = "external_url_request", |
|
19
|
|
|
* name = "request", |
|
20
|
|
|
* type = "ExternalResponse", |
|
21
|
|
|
* parents = {"ExternalUrl"} |
|
22
|
|
|
* ) |
|
23
|
|
|
*/ |
|
24
|
|
|
class ExternalRequest extends FieldPluginBase implements ContainerFactoryPluginInterface { |
|
25
|
|
|
use DependencySerializationTrait; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var \GuzzleHttp\ClientInterface |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $httpClient; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public static function create( |
|
36
|
|
|
ContainerInterface $container, |
|
37
|
|
|
array $configuration, |
|
38
|
|
|
$plugin_id, |
|
39
|
|
|
$plugin_definition |
|
40
|
|
|
) { |
|
41
|
|
|
return new static( |
|
42
|
|
|
$configuration, |
|
43
|
|
|
$plugin_id, |
|
44
|
|
|
$plugin_definition, |
|
45
|
|
|
$container->get('http_client') |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* ExternalRequest constructor. |
|
51
|
|
|
* |
|
52
|
|
|
* @param array $configuration |
|
53
|
|
|
* The plugin configuration array. |
|
54
|
|
|
* @param string $pluginId |
|
55
|
|
|
* The plugin id. |
|
56
|
|
|
* @param mixed $pluginDefinition |
|
57
|
|
|
* The plugin definition array. |
|
58
|
|
|
* @param \GuzzleHttp\ClientInterface $httpClient |
|
59
|
|
|
* The http client service. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function __construct( |
|
62
|
|
|
array $configuration, |
|
63
|
|
|
$pluginId, |
|
64
|
|
|
$pluginDefinition, |
|
65
|
|
|
ClientInterface $httpClient |
|
66
|
|
|
) { |
|
67
|
|
|
parent::__construct($configuration, $pluginId, $pluginDefinition); |
|
68
|
|
|
$this->httpClient = $httpClient; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* {@inheritdoc} |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function resolveValues($value, array $args, ResolveContext $context, ResolveInfo $info) { |
|
76
|
|
|
if ($value instanceof Url) { |
|
77
|
|
|
yield $this->httpClient->request('GET', $value->toString()); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths