class WSConnectorGraphQL 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
HTTP Connector.
Plugin annotation
@WSConnector(
id = "WSConnectorGraphQL",
label = @Translation("GraphQL Connector", context = "WSConnector"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorSimpleHTTP
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorGraphQL
- class \Drupal\wsdata\Plugin\WSConnector\WSConnectorSimpleHTTP
- class \Drupal\wsdata\Plugin\WSConnectorBase implements WSConnectorInterface uses StringTranslationTrait
Expanded class hierarchy of WSConnectorGraphQL
File
- src/
Plugin/ WSConnector/ WSConnectorGraphQL.php, line 19
Namespace
Drupal\wsdata\Plugin\WSConnectorView source
class WSConnectorGraphQL extends WSConnectorSimpleHTTP {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Client $http_client, Token $token, LanguageManagerInterface $language_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $http_client, $token, $language_manager);
$this->http_client = $http_client;
$this->token = $token;
$this->language_manager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('http_client'), $container
->get('token'), $container
->get('language_manager'));
}
/**
* {@inheritdoc}
*/
public function getMethods() {
return [
'post',
];
}
/**
* {@inheritdoc}
*/
public function getOptions() {
return [
'path' => '',
'method' => [],
'headers' => [],
'query' => '',
'operationName' => '',
'variables' => [],
];
}
/**
* {@inheritdoc}
*/
public function getReplacements(array $options) {
$replacements = array_unique($this
->findTokens($this->endpoint . '/' . $options['path']) + $this
->findTokens($options['query']) + $this
->findTokens(json_encode($options['variables'])));
unset($replacements[array_search('LANGUAGE', $replacements)]);
return $replacements;
}
/**
* {@inheritdoc}
*/
public function getOptionsForm($options = []) {
$form = parent::getOptionsForm($options);
$form['query'] = [
'#type' => 'textarea',
'#title' => $this
->t('GraphQL Query'),
'#required' => TRUE,
];
$form['operationName'] = [
'#type' => 'textfield',
'#title' => $this
->t('Operation Name (optional)'),
];
$form['variables'] = [
'#type' => 'textarea',
'#title' => $this
->t('GraphQL Variables (optional)'),
];
return $form;
}
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
public function getCache() {
return $this->language_manager
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | property | ||
WSConnectorBase:: |
protected | function | Internal function for applying replacements. | |
WSConnectorBase:: |
protected | function | Clear current error. | |
WSConnectorBase:: |
public | function | Figure out the overrides for cache times. | |
WSConnectorBase:: |
public | function | Get the expired time for caching. | |
WSConnectorBase:: |
protected | function | Internal function for finding tokens. | |
WSConnectorBase:: |
public | function | Getter for the endpoint. | |
WSConnectorBase:: |
public | function | Return the last error the connector received. | |
WSConnectorBase:: |
public | function | Return the status of the last call. | |
WSConnectorBase:: |
public | function | Return the list of supported language handling plugins. | |
WSConnectorBase:: |
public | function | Whether the connector is in a dead state and shouldn't be called. | |
WSConnectorBase:: |
public | function | Setter for the endpoint. | |
WSConnectorBase:: |
protected | function | Setter for the connector errors. | |
WSConnectorGraphQL:: |
public | function |
Make the connector call. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public static | function |
Creates an instance of the plugin. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public | function |
Return cache cid for cases cache rules change. Overrides WSConnectorBase:: |
|
WSConnectorGraphQL:: |
public | function |
Return available methods supported by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public | function |
Return available options supported by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public | function |
Return the settings form provided by the connector. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public | function |
Return an array of replacements. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorGraphQL:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides WSConnectorSimpleHTTP:: |
|
WSConnectorSimpleHTTP:: |
public | function |
Saves the options form. Overrides WSConnectorBase:: |
|
WSConnectorSimpleHTTP:: |
public | function | Sets the expires times based on the response. | |
WSConnectorSimpleHTTP:: |
public | function |
Whether returned data can be cached. Overrides WSConnectorBase:: |
|
WSConnectorSimpleHTTP:: |
public static | function | Ajax callback function. | 1 |