Merge pull request #650 from AndrewBastin/feat/gql-query-prettify
Added the ability to prettify GraphQL queries
This commit is contained in:
@@ -147,6 +147,15 @@ export default {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
editor.commands.addCommand({
|
||||||
|
name: "prettifyGQLQuery",
|
||||||
|
exec: () => this.prettifyQuery(),
|
||||||
|
bindKey: {
|
||||||
|
mac: "cmd-p",
|
||||||
|
win: "ctrl-p",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
editor.on("change", () => {
|
editor.on("change", () => {
|
||||||
const content = editor.getValue()
|
const content = editor.getValue()
|
||||||
this.$emit("input", content)
|
this.$emit("input", content)
|
||||||
@@ -158,6 +167,16 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
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() {
|
defineTheme() {
|
||||||
if (this.theme) {
|
if (this.theme) {
|
||||||
return this.theme
|
return this.theme
|
||||||
|
|||||||
@@ -182,6 +182,9 @@ export default {
|
|||||||
waiting_send_req: "(waiting to send request)",
|
waiting_send_req: "(waiting to send request)",
|
||||||
waiting_receive_response: "(waiting to receive response)",
|
waiting_receive_response: "(waiting to receive response)",
|
||||||
waiting_receive_schema: "(waiting to receive schema)",
|
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",
|
cancel: "Cancel",
|
||||||
save: "Save",
|
save: "Save",
|
||||||
dismiss: "Dismiss",
|
dismiss: "Dismiss",
|
||||||
|
|||||||
@@ -178,6 +178,13 @@
|
|||||||
>
|
>
|
||||||
<i class="material-icons">file_copy</i>
|
<i class="material-icons">file_copy</i>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
class="icon"
|
||||||
|
@click="doPrettifyQuery"
|
||||||
|
v-tooltip="`${$t('prettify_query')} (${getSpecialKey()}-P)`"
|
||||||
|
>
|
||||||
|
<i class="material-icons">photo_filter</i>
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<QueryEditor
|
<QueryEditor
|
||||||
@@ -452,6 +459,9 @@ export default {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getSpecialKey: getPlatformSpecialKey,
|
getSpecialKey: getPlatformSpecialKey,
|
||||||
|
doPrettifyQuery() {
|
||||||
|
this.$refs.queryEditor.prettifyQuery()
|
||||||
|
},
|
||||||
handleJumpToType(type) {
|
handleJumpToType(type) {
|
||||||
const typesTab = document.getElementById("gqltypes-tab")
|
const typesTab = document.getElementById("gqltypes-tab")
|
||||||
typesTab.checked = true
|
typesTab.checked = true
|
||||||
|
|||||||
Reference in New Issue
Block a user