Merge branch 'master' into i18n
This commit is contained in:
@@ -150,6 +150,61 @@
|
|||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
</pw-section>
|
</pw-section>
|
||||||
|
<pw-section class="cyan" label="Query" ref="query">
|
||||||
|
<div class="flex-wrap">
|
||||||
|
<label for="gqlQuery">Query</label>
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
class="icon"
|
||||||
|
@click="runQuery()"
|
||||||
|
v-tooltip.bottom="'Run Query'"
|
||||||
|
>
|
||||||
|
<i class="material-icons">play_arrow</i>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="icon"
|
||||||
|
@click="copyQuery"
|
||||||
|
ref="copyQueryButton"
|
||||||
|
v-tooltip="'Copy Query'"
|
||||||
|
>
|
||||||
|
<i class="material-icons">file_copy</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
id="gqlQuery"
|
||||||
|
rows="8"
|
||||||
|
v-model="gqlQueryString">
|
||||||
|
></textarea>
|
||||||
|
</pw-section>
|
||||||
|
<pw-section class="purple" label="Response" ref="response">
|
||||||
|
<div class="flex-wrap">
|
||||||
|
<label for="responseField">Response</label>
|
||||||
|
<div>
|
||||||
|
<button
|
||||||
|
class="icon"
|
||||||
|
@click="copyResponse"
|
||||||
|
ref="copyResponseButton"
|
||||||
|
v-tooltip="'Copy Response'"
|
||||||
|
>
|
||||||
|
<i class="material-icons">file_copy</i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Editor
|
||||||
|
:value="responseString"
|
||||||
|
:lang="'json'"
|
||||||
|
:options="{
|
||||||
|
maxLines: responseBodyMaxLines,
|
||||||
|
minLines: '16',
|
||||||
|
fontSize: '16px',
|
||||||
|
autoScrollEditorIntoView: true,
|
||||||
|
readOnly: true,
|
||||||
|
showPrintMargin: false,
|
||||||
|
useWorker: false
|
||||||
|
}"
|
||||||
|
/>
|
||||||
|
</pw-section>
|
||||||
</div>
|
</div>
|
||||||
<aside class="sticky-inner inner-right">
|
<aside class="sticky-inner inner-right">
|
||||||
<pw-section class="purple" label="Docs" ref="docs">
|
<pw-section class="purple" label="Docs" ref="docs">
|
||||||
@@ -252,6 +307,7 @@ export default {
|
|||||||
mutationFields: [],
|
mutationFields: [],
|
||||||
subscriptionFields: [],
|
subscriptionFields: [],
|
||||||
gqlTypes: [],
|
gqlTypes: [],
|
||||||
|
responseString: "",
|
||||||
copyButton: '<i class="material-icons">file_copy</i>',
|
copyButton: '<i class="material-icons">file_copy</i>',
|
||||||
downloadButton: '<i class="material-icons">get_app</i>',
|
downloadButton: '<i class="material-icons">get_app</i>',
|
||||||
doneButton: '<i class="material-icons">done</i>',
|
doneButton: '<i class="material-icons">done</i>',
|
||||||
@@ -276,6 +332,14 @@ export default {
|
|||||||
this.$store.commit("setGQLState", { value, attribute: "headers" });
|
this.$store.commit("setGQLState", { value, attribute: "headers" });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
gqlQueryString: {
|
||||||
|
get() {
|
||||||
|
return this.$store.state.gql.query;
|
||||||
|
},
|
||||||
|
set(value) {
|
||||||
|
this.$store.commit("setGQLState", { value, attribute: "query" });
|
||||||
|
}
|
||||||
|
},
|
||||||
headerString() {
|
headerString() {
|
||||||
const result = this.headers
|
const result = this.headers
|
||||||
.filter(({ key }) => !!key)
|
.filter(({ key }) => !!key)
|
||||||
@@ -301,6 +365,92 @@ export default {
|
|||||||
1000
|
1000
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
copyQuery() {
|
||||||
|
this.$refs.copyQueryButton.innerHTML = this.doneButton;
|
||||||
|
const aux = document.createElement("textarea");
|
||||||
|
aux.innerText = this.gqlQueryString;
|
||||||
|
document.body.appendChild(aux);
|
||||||
|
aux.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(aux);
|
||||||
|
this.$toast.success("Copied to clipboard", {
|
||||||
|
icon: "done"
|
||||||
|
});
|
||||||
|
setTimeout(
|
||||||
|
() => (this.$refs.copyQueryButton.innerHTML = this.copyButton),
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
},
|
||||||
|
copyResponse() {
|
||||||
|
this.$refs.copyResponseButton.innerHTML = this.doneButton;
|
||||||
|
const aux = document.createElement("textarea");
|
||||||
|
aux.innerText = this.responseString;
|
||||||
|
document.body.appendChild(aux);
|
||||||
|
aux.select();
|
||||||
|
document.execCommand("copy");
|
||||||
|
document.body.removeChild(aux);
|
||||||
|
this.$toast.success("Copied to clipboard", {
|
||||||
|
icon: "done"
|
||||||
|
});
|
||||||
|
setTimeout(
|
||||||
|
() => (this.$refs.copyResponseButton.innerHTML = this.copyButton),
|
||||||
|
1000
|
||||||
|
);
|
||||||
|
},
|
||||||
|
async runQuery() {
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
this.$nuxt.$loading.start();
|
||||||
|
|
||||||
|
try {
|
||||||
|
let headers = {};
|
||||||
|
this.headers.forEach(header => {
|
||||||
|
headers[header.key] = header.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const reqOptions = {
|
||||||
|
method: "post",
|
||||||
|
url: this.url,
|
||||||
|
headers: {
|
||||||
|
...headers,
|
||||||
|
"content-type": "application/json"
|
||||||
|
},
|
||||||
|
data: JSON.stringify({ query: this.gqlQueryString })
|
||||||
|
};
|
||||||
|
|
||||||
|
const reqConfig = this.$store.state.postwoman.settings.PROXY_ENABLED
|
||||||
|
? {
|
||||||
|
method: "post",
|
||||||
|
url:
|
||||||
|
this.$store.state.postwoman.settings.PROXY_URL ||
|
||||||
|
`https://postwoman.apollotv.xyz/`,
|
||||||
|
data: reqOptions
|
||||||
|
}
|
||||||
|
: reqOptions;
|
||||||
|
|
||||||
|
const res = await axios(reqConfig);
|
||||||
|
|
||||||
|
const data = this.$store.state.postwoman.settings.PROXY_ENABLED
|
||||||
|
? res.data
|
||||||
|
: res;
|
||||||
|
|
||||||
|
this.responseString = JSON.stringify(data.data, null, 2);
|
||||||
|
|
||||||
|
this.$nuxt.$loading.finish();
|
||||||
|
const duration = Date.now() - startTime;
|
||||||
|
this.$toast.info(`Finished in ${duration}ms`, {
|
||||||
|
icon: "done"
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.$nuxt.$loading.finish();
|
||||||
|
|
||||||
|
this.$toast.error(error + " (F12 for details)", {
|
||||||
|
icon: "error"
|
||||||
|
});
|
||||||
|
console.log("Error", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
async getSchema() {
|
async getSchema() {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
this.schemaString = "Loading...";
|
this.schemaString = "Loading...";
|
||||||
@@ -454,10 +604,22 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
removeRequestHeader(index) {
|
removeRequestHeader(index) {
|
||||||
|
// .slice() is used so we get a separate array, rather than just a reference
|
||||||
|
const oldHeaders = this.headers.slice();
|
||||||
|
|
||||||
this.$store.commit("removeGQLHeader", index);
|
this.$store.commit("removeGQLHeader", index);
|
||||||
this.$toast.error("Deleted", {
|
this.$toast.error("Deleted", {
|
||||||
icon: "delete"
|
icon: "delete",
|
||||||
|
action: {
|
||||||
|
text: "Undo",
|
||||||
|
duration: 4000,
|
||||||
|
onClick: (e, toastObject) => {
|
||||||
|
this.headers = oldHeaders;
|
||||||
|
toastObject.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
console.log(oldHeaders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1606,9 +1606,19 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
removeRequestHeader(index) {
|
removeRequestHeader(index) {
|
||||||
|
// .slice() gives us an entirely new array rather than giving us just the reference
|
||||||
|
const oldHeaders = this.headers.slice();
|
||||||
|
|
||||||
this.$store.commit("removeHeaders", index);
|
this.$store.commit("removeHeaders", index);
|
||||||
this.$toast.error("Deleted", {
|
this.$toast.error("Deleted", {
|
||||||
icon: "delete"
|
icon: "delete",
|
||||||
|
action: {
|
||||||
|
text: "Undo",
|
||||||
|
onClick: (e, toastObject) => {
|
||||||
|
this.headers = oldHeaders;
|
||||||
|
toastObject.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addRequestParam() {
|
addRequestParam() {
|
||||||
@@ -1616,9 +1626,19 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
removeRequestParam(index) {
|
removeRequestParam(index) {
|
||||||
|
// .slice() gives us an entirely new array rather than giving us just the reference
|
||||||
|
const oldParams = this.params.slice();
|
||||||
|
|
||||||
this.$store.commit("removeParams", index);
|
this.$store.commit("removeParams", index);
|
||||||
this.$toast.error("Deleted", {
|
this.$toast.error("Deleted", {
|
||||||
icon: "delete"
|
icon: "delete",
|
||||||
|
action: {
|
||||||
|
text: "Undo",
|
||||||
|
onClick: (e, toastObject) => {
|
||||||
|
this.params = oldParams;
|
||||||
|
toastObject.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
addRequestBodyParam() {
|
addRequestBodyParam() {
|
||||||
@@ -1626,9 +1646,19 @@ export default {
|
|||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
removeRequestBodyParam(index) {
|
removeRequestBodyParam(index) {
|
||||||
|
// .slice() gives us an entirely new array rather than giving us just the reference
|
||||||
|
const oldBodyParams = this.bodyParams.slice();
|
||||||
|
|
||||||
this.$store.commit("removeBodyParams", index);
|
this.$store.commit("removeBodyParams", index);
|
||||||
this.$toast.error("Deleted", {
|
this.$toast.error("Deleted", {
|
||||||
icon: "delete"
|
icon: "delete",
|
||||||
|
action: {
|
||||||
|
text: "Undo",
|
||||||
|
onClick: (e, toastObject) => {
|
||||||
|
this.bodyParams = oldBodyParams;
|
||||||
|
toastObject.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
formatRawParams(event) {
|
formatRawParams(event) {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export default () => ({
|
|||||||
},
|
},
|
||||||
gql: {
|
gql: {
|
||||||
url: 'https://rickandmortyapi.com/graphql',
|
url: 'https://rickandmortyapi.com/graphql',
|
||||||
headers: []
|
headers: [],
|
||||||
|
query: ""
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user