diff --git a/pages/graphql.vue b/pages/graphql.vue index d4129796c..127f74428 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -187,67 +187,21 @@ useWorker: false }" /> -
- -
- -
-
- - + + + + @@ -564,14 +518,6 @@ export default { this.$store.commit("setGQLState", { value, attribute: "headers" }); } }, - variables: { - get() { - return this.$store.state.gql.variables; - }, - set(value) { - this.$store.commit("setGQLState", { value, attribute: "variables" }); - } - }, gqlQueryString: { get() { return this.$store.state.gql.query; @@ -580,6 +526,14 @@ export default { this.$store.commit("setGQLState", { value, attribute: "query" }); } }, + variableString: { + get() { + return this.$store.state.gql.variablesJSONString; + }, + set(value) { + this.$store.commit("setGQLState", { value, attribute: "variablesJSONString" }); + } + }, headerString() { const result = this.headers .filter(({ key }) => !!key) @@ -666,19 +620,10 @@ export default { this.headers.forEach(header => { headers[header.key] = header.value; }); + + let variables = JSON.parse(this.variableString); - let variables = {}; const gqlQueryString = this.gqlQueryString; - this.variables.forEach(variable => { - // todo: better variable type validation - if (gqlQueryString.indexOf(`\$${variable.key}: Int`) > -1) { - variables[variable.key] = parseInt(variable.value); - } else if (gqlQueryString.indexOf(`\$${variable.key}: Float`) > -1) { - variables[variable.key] = parseFloat(variable.value); - } else { - variables[variable.key] = variable.value; - } - }); const reqOptions = { method: "post", @@ -879,30 +824,6 @@ export default { }); // console.log(oldHeaders); }, - addQueryVariable(index) { - this.$store.commit("addGQLVariable", { - key: "", - value: "" - }); - return false; - }, - removeQueryVariable(index) { - const oldVariables = this.variables.slice(); - - this.$store.commit("removeGQLVariable", index); - this.$toast.error(this.$t("deleted"), { - icon: "delete", - action: { - text: this.$t("undo"), - duration: 4000, - onClick: (e, toastObject) => { - this.variables = oldVariables; - toastObject.remove(); - } - } - }); - // console.log(oldVariables); - }, scrollInto(view) { this.$refs[view].$el.scrollIntoView({ behavior: "smooth" diff --git a/store/mutations.js b/store/mutations.js index 64d178f57..acc84471a 100644 --- a/store/mutations.js +++ b/store/mutations.js @@ -23,22 +23,6 @@ export default { gql.headers[index].value = value; }, - addGQLVariable({ gql }, object) { - gql.variables.push(object); - }, - - removeGQLVariable({ gql }, index) { - gql.variables.splice(index, 1); - }, - - setGQLVariableKey({ gql }, { index, value }) { - gql.variables[index].key = value; - }, - - setGQLVariableValue({ gql }, { index, value }) { - gql.variables[index].value = value; - }, - addHeaders({ request }, value) { request.headers.push(value); }, diff --git a/store/state.js b/store/state.js index e6ab3b51d..7667b1d0a 100644 --- a/store/state.js +++ b/store/state.js @@ -20,7 +20,7 @@ export default () => ({ gql: { url: "https://rickandmortyapi.com/graphql", headers: [], - variables: [], + variablesJSONString: "", query: "" }, oauth2: {