chore(refactor): switch to async/await approach (#317)

chore(refactor): switch to async/await approach
This commit is contained in:
Liyas Thomas
2019-11-20 19:43:22 +05:30
committed by GitHub

View File

@@ -140,7 +140,7 @@ export default {
}; };
}, },
methods: { methods: {
getSchema() { async getSchema() {
const startTime = Date.now(); const startTime = Date.now();
this.schemaString = "Loading..."; this.schemaString = "Loading...";
@@ -148,11 +148,11 @@ export default {
// The nuxt axios module will hide it when the request is made. // The nuxt axios module will hide it when the request is made.
this.$nuxt.$loading.start(); this.$nuxt.$loading.start();
axios try {
.post(this.url, { const res = await axios.post(this.url, {
query: gql.getIntrospectionQuery() query: gql.getIntrospectionQuery()
}) })
.then(res => {
const schema = gql.buildClientSchema(res.data.data); const schema = gql.buildClientSchema(res.data.data);
this.schemaString = gql.printSchema(schema, { this.schemaString = gql.printSchema(schema, {
commentDescriptions: true commentDescriptions: true
@@ -216,15 +216,14 @@ export default {
this.$toast.info(`Finished in ${duration}ms`, { this.$toast.info(`Finished in ${duration}ms`, {
icon: "done" icon: "done"
}); });
}) } catch(error) {
.catch(error => {
this.$nuxt.$loading.finish(); this.$nuxt.$loading.finish();
this.schemaString = error + ". Check console for details."; this.schemaString = error + ". Check console for details.";
this.$toast.error(error + " (F12 for details)", { this.$toast.error(error + " (F12 for details)", {
icon: "error" icon: "error"
}); });
console.log("Error", error); console.log("Error", error);
}); }
} }
} }
}; };