public function WSConnectorGraphQL::call in Web Service Data 8
Same name and namespace in other branches
- 2.0.x src/Plugin/WSConnector/WSConnectorGraphQL.php \Drupal\wsdata\Plugin\WSConnector\WSConnectorGraphQL::call()
Make the connector call.
Overrides WSConnectorSimpleHTTP::call
File
- src/
Plugin/ WSConnector/ WSConnectorGraphQL.php, line 110
Class
- WSConnectorGraphQL
- HTTP Connector.
Namespace
Drupal\wsdata\Plugin\WSConnectorCode
public function call($options, $method, $replacements = [], $data = NULL, array $tokens = []) {
$langcode = $options['langcode'] ?? $this->language_manager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
$replacements['LANGUAGE'] = strtoupper($langcode);
$contenttype = FALSE;
if (!isset($options['headers'])) {
$options['headers'] = [];
}
foreach ($options['headers'] as $key => $header) {
if (isset($header['key_' . $key]) and strtolower($header['key_' . $key]) == strtolower('Content-Type')) {
$contenttype = TRUE;
}
}
if (!$contenttype) {
$i = count($options['headers']);
$options['headers'][$i] = [
'key_' . $i => 'Content-Type',
'value_' . $i => 'application/json',
];
}
$graphql = [
'query' => $this
->applyReplacements($options['query'], $replacements, $tokens),
'operationName' => !empty($options['operationName']) ? $options['operationName'] : NULL,
'variables' => json_decode($options['variables']),
];
unset($options['query']);
unset($options['operationName']);
unset($options['variables']);
$data = json_encode($graphql);
return parent::call($options, $method, $replacements, $data, $tokens);
}