diff --git a/lang/de-DE.js b/lang/de-DE.js index 112c2f588..88c920511 100644 --- a/lang/de-DE.js +++ b/lang/de-DE.js @@ -66,6 +66,7 @@ export default { response: "Antwort", query: "Abfrage", queries: "Abfragen", + query_variables: "Variablen", mutations: "Mutationen", subscriptions: "Abonnements", types: "Typen", diff --git a/lang/en-US.js b/lang/en-US.js index 19f9fce0b..317b9718e 100644 --- a/lang/en-US.js +++ b/lang/en-US.js @@ -66,6 +66,7 @@ export default { response: "Response", query: "Query", queries: "Queries", + query_variables: "Variables", mutations: "Mutations", subscriptions: "Subscriptions", types: "Types", diff --git a/lang/es-ES.js b/lang/es-ES.js index 5bd7fbe60..5574fabba 100644 --- a/lang/es-ES.js +++ b/lang/es-ES.js @@ -66,6 +66,7 @@ export default { response: "Respuesta", query: "Consulta", queries: "Consultas", + query_variables: "Variables", mutations: "Mutaciones", subscriptions: "Subscripciones", types: "Tipos", diff --git a/lang/fa-IR.js b/lang/fa-IR.js index a998fae05..868147717 100644 --- a/lang/fa-IR.js +++ b/lang/fa-IR.js @@ -66,6 +66,7 @@ export default { response: "Response", query: "Query", queries: "Queries", + query_variables: "Variables", mutations: "Mutations", subscriptions: "Subscriptions", types: "Types", diff --git a/lang/fr-FR.js b/lang/fr-FR.js index dc6c2e48b..ef20770cf 100644 --- a/lang/fr-FR.js +++ b/lang/fr-FR.js @@ -66,6 +66,7 @@ export default { response: "Réponse", query: "Requête", queries: "Requêtes", + query_variables: "Variables", mutations: "Mutations", subscriptions: "Abonnements", types: "Types", diff --git a/lang/id-ID.js b/lang/id-ID.js index 17d60c678..1a99f00cf 100644 --- a/lang/id-ID.js +++ b/lang/id-ID.js @@ -66,6 +66,7 @@ export default { response: "Balasan", query: "Kueri", queries: "Kueri", + query_variables: "Variables", mutations: "Mutasi", subscriptions: "Langganan", types: "Jenis", diff --git a/lang/ja-JP.js b/lang/ja-JP.js index 086cb127a..8aa9f951d 100644 --- a/lang/ja-JP.js +++ b/lang/ja-JP.js @@ -66,6 +66,7 @@ export default { response: "レスポンス", query: "クエリ", queries: "クエリ", + query_variables: "変数 (へんすう)", mutations: "ミューテーション", subscriptions: "サブスクリプション", types: "タイプ", diff --git a/lang/pt-BR.js b/lang/pt-BR.js index 7b7d919d1..9b1e294f8 100644 --- a/lang/pt-BR.js +++ b/lang/pt-BR.js @@ -66,6 +66,7 @@ export default { response: "Response", query: "Query", queries: "Queries", + query_variables: "Variáveis", mutations: "Mutações", subscriptions: "Assinaturas", types: "Tipos", diff --git a/lang/tr-TR.js b/lang/tr-TR.js index ea159fbdc..054a4f16f 100644 --- a/lang/tr-TR.js +++ b/lang/tr-TR.js @@ -66,6 +66,7 @@ export default { response: "Cevap", query: "Sorgu", queries: "Sorgular", + query_variables: "Değişkenler", mutations: "Değişimler", subscriptions: "Aboneler", types: "Tipler", diff --git a/lang/zh-CN.js b/lang/zh-CN.js index a98245413..9e8db750b 100644 --- a/lang/zh-CN.js +++ b/lang/zh-CN.js @@ -66,6 +66,7 @@ export default { response: "响应", query: "查询", queries: "查询", + query_variables: "变数", mutations: "Mutations", subscriptions: "订阅", types: "种类", diff --git a/package-lock.json b/package-lock.json index 168d09cc3..bc3a1d363 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11286,8 +11286,7 @@ }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -11427,7 +11426,6 @@ "minipass": { "version": "2.9.0", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -11444,7 +11442,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -11536,7 +11533,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -11612,8 +11608,7 @@ }, "safe-buffer": { "version": "5.1.2", - "bundled": true, - "optional": true + "bundled": true }, "safer-buffer": { "version": "2.1.2", @@ -11643,7 +11638,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -11700,13 +11694,11 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true, - "optional": true + "bundled": true }, "yallist": { "version": "3.1.1", - "bundled": true, - "optional": true + "bundled": true } } }, diff --git a/pages/graphql.vue b/pages/graphql.vue index 4a8634f07..efc37e300 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -185,6 +185,66 @@ useWorker: false }" /> +
+ +
+ +
+
+ + @@ -294,8 +354,8 @@ class="info" > Send a request first -

+

+ @@ -481,6 +541,14 @@ 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; @@ -558,6 +626,24 @@ export default { headers[header.key] = header.value; }); + let variables = {}; + const gqlQueryString = this.gqlQueryString; + this.variables.forEach(variable => { + // todo: better variable type validation + const intRex = new RegExp(`\$${variable.key}\: Int`); + intRex.compile(); + const floatRex = new RegExp(`\$${variable.key}\: Float`); + floatRex.compile(); + + if (intRex.test(gqlQueryString)) { + variables[variable.key] = parseInt(variable.value); + } else if (floatRex.test(gqlQueryString)) { + variables[variable.key] = parseFloat(variable.value); + } else { + variables[variable.key] = variable.value; + } + }); + const reqOptions = { method: "post", url: this.url, @@ -565,7 +651,7 @@ export default { ...headers, "content-type": "application/json" }, - data: JSON.stringify({ query: this.gqlQueryString }) + data: JSON.stringify({ query: gqlQueryString, variables }) }; const reqConfig = this.$store.state.postwoman.settings.PROXY_ENABLED @@ -771,6 +857,30 @@ 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("Deleted", { + icon: "delete", + action: { + text: "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 901d18482..61bfd4757 100644 --- a/store/mutations.js +++ b/store/mutations.js @@ -23,6 +23,22 @@ 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 2fb0322de..3f8a25da1 100644 --- a/store/state.js +++ b/store/state.js @@ -20,6 +20,7 @@ export default () => ({ gql: { url: "https://rickandmortyapi.com/graphql", headers: [], + variables: [], query: "" } });