Merge pull request #650 from AndrewBastin/feat/gql-query-prettify

Added the ability to prettify GraphQL queries
This commit is contained in:
Andrew Bastin
2020-03-05 20:22:46 -05:00
committed by GitHub
3 changed files with 32 additions and 0 deletions

View File

@@ -147,6 +147,15 @@ export default {
},
})
editor.commands.addCommand({
name: "prettifyGQLQuery",
exec: () => this.prettifyQuery(),
bindKey: {
mac: "cmd-p",
win: "ctrl-p",
},
})
editor.on("change", () => {
const content = editor.getValue()
this.$emit("input", content)
@@ -158,6 +167,16 @@ export default {
},
methods: {
prettifyQuery() {
try {
this.value = gql.print(gql.parse(this.editor.getValue()))
} catch (e) {
this.$toast.error(`${this.$t("gql_prettify_invalid_query")}`, {
icon: "error",
})
}
},
defineTheme() {
if (this.theme) {
return this.theme

View File

@@ -182,6 +182,9 @@ export default {
waiting_send_req: "(waiting to send request)",
waiting_receive_response: "(waiting to receive response)",
waiting_receive_schema: "(waiting to receive schema)",
gql_prettify_invalid_query:
"Couldn't prettify an invalid query, solve query syntax errors and try again",
prettify_query: "Prettify Query",
cancel: "Cancel",
save: "Save",
dismiss: "Dismiss",

View File

@@ -178,6 +178,13 @@
>
<i class="material-icons">file_copy</i>
</button>
<button
class="icon"
@click="doPrettifyQuery"
v-tooltip="`${$t('prettify_query')} (${getSpecialKey()}-P)`"
>
<i class="material-icons">photo_filter</i>
</button>
</div>
</div>
<QueryEditor
@@ -452,6 +459,9 @@ export default {
},
methods: {
getSpecialKey: getPlatformSpecialKey,
doPrettifyQuery() {
this.$refs.queryEditor.prettifyQuery()
},
handleJumpToType(type) {
const typesTab = document.getElementById("gqltypes-tab")
typesTab.checked = true