console: prettify variable json when clicking on the prettify button, close 9968

GITHUB_PR_NUMBER: 9969
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/9969

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/10454
Co-authored-by: Bert Verhelst <1710840+bertyhell@users.noreply.github.com>
GitOrigin-RevId: d3d14fe2ac326f143d50925a0827c8c16e68d420
This commit is contained in:
hasura-bot 2024-01-05 04:14:23 +05:30
parent b8d39386f6
commit 500cf56171

View File

@ -137,10 +137,23 @@ class GraphiQLWrapper extends Component {
const handleClickPrettifyButton = () => {
trackGraphiQlToolbarButtonClick('Prettify');
const editor = graphiqlContext.getQueryEditor();
const currentText = editor.getValue();
const prettyText = print(sdlParse(currentText));
editor.setValue(prettyText);
const queryEditor = graphiqlContext.getQueryEditor();
const currentQueryText = queryEditor.getValue();
const prettyQueryText = print(sdlParse(currentQueryText));
queryEditor.setValue(prettyQueryText);
try {
const variableEditor = graphiqlContext.getVariableEditor();
const currentVariableText = variableEditor.getValue();
const prettyVariableText = JSON.stringify(
JSON.parse(currentVariableText),
null,
2
);
variableEditor.setValue(prettyVariableText);
} catch (err) {
// Ignore json parse errors, since we can't format invalid json anyway
}
};
const handleToggleHistory = () => {