|
13 | 13 | use Drupal\Core\Plugin\PluginFormInterface;
|
14 | 14 | use Drupal\Core\Routing\RequestContext;
|
15 | 15 | use Drupal\graphql\Plugin\SchemaPluginManager;
|
| 16 | +use GraphQL\Error\DebugFlag; |
16 | 17 | use Symfony\Component\DependencyInjection\ContainerInterface;
|
17 | 18 |
|
18 | 19 | /**
|
@@ -181,11 +182,23 @@ public function form(array $form, FormStateInterface $formState) {
|
181 | 182 | '#description' => $this->t('Whether caching of queries and partial results is enabled.'),
|
182 | 183 | ];
|
183 | 184 |
|
184 |
| - $form['debug'] = [ |
185 |
| - '#title' => $this->t('Enable debugging'), |
186 |
| - '#type' => 'checkbox', |
187 |
| - '#default_value' => !!$server->get('debug'), |
188 |
| - '#description' => $this->t('In debugging mode, error messages contain more verbose information in the query response.'), |
| 185 | + $debug_flags = $server->get('debug_flag') ?? 0; |
| 186 | + $form['debug_flag'] = [ |
| 187 | + '#title' => $this->t('Debug settings'), |
| 188 | + '#type' => 'checkboxes', |
| 189 | + '#options' => [ |
| 190 | + DebugFlag::INCLUDE_DEBUG_MESSAGE => $this->t("Add debugMessage key containing the exception message to errors."), |
| 191 | + DebugFlag::INCLUDE_TRACE => $this->t("Include the formatted original backtrace in errors."), |
| 192 | + DebugFlag::RETHROW_INTERNAL_EXCEPTIONS => $this->t("Rethrow the internal GraphQL exceptions"), |
| 193 | + DebugFlag::RETHROW_UNSAFE_EXCEPTIONS => $this->t("Rethrow unsafe GraphQL exceptions, these are exceptions that have not been marked as safe to expose to clients."), |
| 194 | + ], |
| 195 | + '#default_value' => array_keys(array_filter([ |
| 196 | + DebugFlag::INCLUDE_DEBUG_MESSAGE => (bool) ($debug_flags & DebugFlag::INCLUDE_DEBUG_MESSAGE), |
| 197 | + DebugFlag::INCLUDE_TRACE => (bool) ($debug_flags & DebugFlag::INCLUDE_TRACE), |
| 198 | + DebugFlag::RETHROW_INTERNAL_EXCEPTIONS => (bool) ($debug_flags & DebugFlag::RETHROW_INTERNAL_EXCEPTIONS), |
| 199 | + DebugFlag::RETHROW_UNSAFE_EXCEPTIONS => (bool) ($debug_flags & DebugFlag::RETHROW_UNSAFE_EXCEPTIONS), |
| 200 | + ])), |
| 201 | + '#description' => $this->t("It is recommended to disable all debugging in production. During development you can enable the information that you need above."), |
189 | 202 | ];
|
190 | 203 |
|
191 | 204 | $form['actions'] = [
|
@@ -231,6 +244,9 @@ public function validateForm(array &$form, FormStateInterface $formState) {
|
231 | 244 | * {@inheritdoc}
|
232 | 245 | */
|
233 | 246 | public function submitForm(array &$form, FormStateInterface $formState) {
|
| 247 | + // Translate the debug flag from individual checkboxes to the enum value |
| 248 | + // that the GraphQL library expects. |
| 249 | + $formState->setValue('debug_flag', array_sum($formState->getValue('debug_flag'))); |
234 | 250 | parent::submitForm($form, $formState);
|
235 | 251 |
|
236 | 252 | $schema = $formState->getValue('schema');
|
|
0 commit comments