graphql.install in GraphQL 8.4
Same filename and directory in other branches
Install, update and uninstall functions for the GraphQL module.
File
graphql.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the GraphQL module.
*/
use Drupal\graphql\Entity\Server;
use GraphQL\Error\DebugFlag;
/**
* Implements hook_requirements().
*/
function graphql_requirements(string $phase) : array {
// This is the first reference into the library performed by the module.
$libraryAvailable = class_exists('\\GraphQL\\GraphQL');
$libraryArg = [
'@library' => 'webonyx/graphql-php',
];
return [
'graphql' => [
'title' => 'GraphQL',
'description' => !empty($libraryAvailable) ? t('@library component available', $libraryArg) : t('@library component not found', $libraryArg),
'severity' => !empty($libraryAvailable) ? REQUIREMENT_OK : REQUIREMENT_ERROR,
],
];
}
/**
* Implements hook_uninstall().
*/
function graphql_uninstall() : void {
// Remove the config keys set in GraphQLConfigOverrides::loadOverrides().
/** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
$configFactory = \Drupal::getContainer()
->get('config.factory');
$languageTypes = $configFactory
->getEditable('language.types');
$negotiation = $languageTypes
->get('negotiation');
foreach (array_keys($negotiation) as $type) {
unset($negotiation[$type]['enabled']['language-graphql']);
}
$languageTypes
->set('negotiation', $negotiation)
->save();
}
/**
* Update GraphQL Server debug configuration value.
*/
function graphql_update_8001() : void {
// The `debug` config item has changed to `debug_flag`. It is no longer a
// boolean toggle but instead a set of flags providing more control. In this
// case we default to debug messages and a backtrace in case debugging was
// enabled and just unselect all flags otherwise.
$servers = Server::loadMultiple();
foreach ($servers as $server) {
// There is no need to unset `debug` as its property no longer exists so it
// will not get persisted.
$debugEnabled = (bool) $server
->get('debug');
$server
->set('debug_flag', $debugEnabled ? DebugFlag::INCLUDE_DEBUG_MESSAGE | DebugFlag::INCLUDE_TRACE : DebugFlag::NONE);
$server
->save();
}
}
/**
* Empty update that was removed again.
*/
function graphql_update_8400() : void {
}
Functions
Name | Description |
---|---|
graphql_requirements | Implements hook_requirements(). |
graphql_uninstall | Implements hook_uninstall(). |
graphql_update_8001 | Update GraphQL Server debug configuration value. |
graphql_update_8400 | Empty update that was removed again. |