Skip to content
Snippets Groups Projects
Commit 3ae886a2 authored by Eli Stone's avatar Eli Stone
Browse files

Issue #3392635 by Tuuuukka, 3li: Debug button not visible

parent 9d119bea
No related branches found
No related tags found
No related merge requests found
Pipeline #34843 canceled
(($, Drupal) => {
((Drupal, once) => {
'use strict';
Drupal.behaviors.graphqlTwigDebug = {
attach: (context) => {
$(once('graphql-debug', '.graphql-twig-debug-wrapper', context)).each(
() => {
const query = $(this).attr('data-graphql-query');
once('graphql-debug', '.graphql-twig-debug-wrapper', context).forEach((element) => {
const query = element.dataset.graphqlQuery;
const server = element.dataset.graphqlServer;
let variables = element.dataset.graphqlVariables;
const form = document.createElement('form');
form.action = Drupal.url(`admin/config/graphql/servers/manage/${server}/explorer`);
form.method = 'post';
form.target = '_blank';
const txt = document.createElement('textarea');
txt.innerHTML = variables;
variables = txt.value;
let variables = $(this).attr('data-graphql-variables');
const queryInput = document.createElement('input');
queryInput.type = 'hidden';
queryInput.name = 'query';
queryInput.value = query;
const $form = $('<form method="post" target="_blank"></form>')
.attr('action', Drupal.url('graphql/explorer'))
.appendTo(this);
const variablesInput = document.createElement('input');
variablesInput.type = 'hidden';
variablesInput.name = 'variables';
variablesInput.value = variables;
const txt = document.createElement('textarea');
const button = document.createElement('input');
button.type = 'submit';
button.classList.add('graphql-twig-debug-button');
button.value = 'Inspect GraphQL query';
txt.innerHTML = variables;
variables = txt.value;
$('<input type="hidden" name="query"/>').val(query).appendTo($form);
$('<input type="hidden" name="variables"/>')
.val(variables)
.appendTo($form);
$(
'<input type="submit" class="graphql-twig-debug-button" value="Inspect GraphQL query"/>',
).appendTo($form);
},
);
form.append(queryInput, variablesInput, button);
element.append(form);
});
},
};
})(jQuery, Drupal);
})(Drupal, once);
......@@ -6,6 +6,5 @@ debug:
js:
assets/debug.js: {}
dependencies:
- core/jquery
- core/once
- core/drupal
......@@ -108,10 +108,11 @@ trait GraphQLTemplateTrait {
if ($this->env->isDebug() && $debug_placement == 'wrapped') {
printf(
'<div class="%s" data-graphql-query="%s" data-graphql-variables="%s">',
'<div class="%s" data-graphql-query="%s" data-graphql-variables="%s" data-graphql-server="%s">',
'graphql-twig-debug-wrapper',
htmlspecialchars($query),
htmlspecialchars(json_encode($arguments))
htmlspecialchars(json_encode($arguments)),
$this->env->getGraphQlServer()?->id()
);
}
......@@ -132,10 +133,11 @@ trait GraphQLTemplateTrait {
if ($this->env->isDebug() && $debug_placement == 'inside') {
$context['graphql_debug'] = [
'#markup' => sprintf(
'<div class="graphql-twig-debug-child"><div class="%s" data-graphql-query="%s" data-graphql-variables="%s"></div></div>',
'<div class="graphql-twig-debug-child"><div class="%s" data-graphql-query="%s" data-graphql-variables="%s" data-graphql-server="%s"></div></div>',
'graphql-twig-debug-wrapper',
htmlspecialchars($query),
htmlspecialchars(json_encode($arguments))
htmlspecialchars(json_encode($arguments)),
$this->env->getGraphQlServer()?->id()
),
];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment