-
Notifications
You must be signed in to change notification settings - Fork 201
/
graphql.install
83 lines (74 loc) · 2.57 KB
/
graphql.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?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 {
}
/**
* Preserve dataproducer default value behavior for old installations.
*
* Set dataproducer_populate_default_values to TRUE after you verified that your
* dataproducers are still working with the new default value behavior.
*/
function graphql_update_10400() :void {
\Drupal::configFactory()->getEditable('graphql.settings')
->set('dataproducer_populate_default_values', FALSE)
->save();
}