From d35d3061e52550a8ec9917396f0b4e9b2bee439e Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Mon, 27 Jan 2020 18:42:38 -0500 Subject: [PATCH 1/4] Added variable editor and removed the old variable system --- pages/graphql.vue | 90 ++++++++++------------------------------------- 1 file changed, 18 insertions(+), 72 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 606796472..360bc0183 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -187,67 +187,21 @@ useWorker: false }" /> -
- -
- -
-
- - + + + + @@ -410,6 +364,7 @@ export default { data() { return { schemaString: "", + variableString: "{}", commonHeaders: [ "WWW-Authenticate", "Authorization", @@ -666,19 +621,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", From cf9fe0c02c9d05c8b0e8b6b9ded1fc314f09f996 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 29 Jan 2020 20:05:59 -0500 Subject: [PATCH 2/4] Removed old variable store mechanisms --- pages/graphql.vue | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 360bc0183..ab04eb41b 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -519,14 +519,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; @@ -827,30 +819,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" From 5d2ba22988208926b9b11d7f7a71ac8c1ddbf07e Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 29 Jan 2020 20:21:23 -0500 Subject: [PATCH 3/4] Removed mutations for GraphQL variables --- store/mutations.js | 16 ---------------- 1 file changed, 16 deletions(-) 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); }, From 94c24408329c949b07e6a3bcd734246d59a8ae84 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Wed, 29 Jan 2020 20:35:54 -0500 Subject: [PATCH 4/4] Hooked the new variable editor to the persistent store --- pages/graphql.vue | 9 ++++++++- store/state.js | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index ab04eb41b..0dfdae88e 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -364,7 +364,6 @@ export default { data() { return { schemaString: "", - variableString: "{}", commonHeaders: [ "WWW-Authenticate", "Authorization", @@ -527,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) 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: {