From f8c3d1e6db07710740ddc79081728563bf8110b3 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:00:17 +0530 Subject: [PATCH 1/7] refactor: use async await approach --- pages/graphql.vue | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 25c8a7f47..c49b48ded 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -148,11 +148,10 @@ export default { // The nuxt axios module will hide it when the request is made. this.$nuxt.$loading.start(); - axios - .post(this.url, { - query: gql.getIntrospectionQuery() + try { + const res = await axios.post(this.url, { + query: gql.getIntrospectionQuery() }) - .then(res => { const schema = gql.buildClientSchema(res.data.data); this.schemaString = gql.printSchema(schema, { commentDescriptions: true @@ -216,8 +215,7 @@ export default { this.$toast.info(`Finished in ${duration}ms`, { icon: "done" }); - }) - .catch(error => { + } catch(err) { this.$nuxt.$loading.finish(); this.schemaString = error + ". Check console for details."; this.$toast.error(error + " (F12 for details)", { From f61eeebc8ff7808c540a5e6bafef2b2daf6126a2 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:05:46 +0530 Subject: [PATCH 2/7] fix: lint --- pages/graphql.vue | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index c49b48ded..eda127b25 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -152,37 +152,38 @@ export default { const res = await axios.post(this.url, { query: gql.getIntrospectionQuery() }) - const schema = gql.buildClientSchema(res.data.data); + + const schema = gql.buildClientSchema(res.data.data); this.schemaString = gql.printSchema(schema, { commentDescriptions: true - }); + }); - if (schema.getQueryType()) { - const fields = schema.getQueryType().getFields(); - const qFields = []; - for (const field in fields) { - qFields.push(fields[field]); - } - this.queryFields = qFields; + if (schema.getQueryType()) { + const fields = schema.getQueryType().getFields(); + const qFields = []; + for (const field in fields) { + qFields.push(fields[field]); } + this.queryFields = qFields; + } - if (schema.getMutationType()) { - const fields = schema.getMutationType().getFields(); - const mFields = []; - for (const field in fields) { - mFields.push(fields[field]); - } - this.mutationFields = mFields; + if (schema.getMutationType()) { + const fields = schema.getMutationType().getFields(); + const mFields = []; + for (const field in fields) { + mFields.push(fields[field]); } + this.mutationFields = mFields; + } - if (schema.getSubscriptionType()) { - const fields = schema.getSubscriptionType().getFields(); - const sFields = []; - for (const field in fields) { - sFields.push(fields[field]); - } - this.subscriptionFields = sFields; + if (schema.getSubscriptionType()) { + const fields = schema.getSubscriptionType().getFields(); + const sFields = []; + for (const field in fields) { + sFields.push(fields[field]); } + this.subscriptionFields = sFields; + } const typeMap = schema.getTypeMap(); const types = []; From 929d9552379ceafc3689109217368944bf4615d1 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:06:19 +0530 Subject: [PATCH 3/7] fix: minor tweak --- pages/graphql.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index eda127b25..35673aa14 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -154,8 +154,8 @@ export default { }) const schema = gql.buildClientSchema(res.data.data); - this.schemaString = gql.printSchema(schema, { - commentDescriptions: true + this.schemaString = gql.printSchema(schema, { + commentDescriptions: true }); if (schema.getQueryType()) { From a0dd02ec076f1471fdc7a45afe26cf2314d06357 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:07:33 +0530 Subject: [PATCH 4/7] fix: lint --- pages/graphql.vue | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 35673aa14..f6bdcebe2 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -185,30 +185,30 @@ export default { this.subscriptionFields = sFields; } - const typeMap = schema.getTypeMap(); - const types = []; + const typeMap = schema.getTypeMap(); + const types = []; - const queryTypeName = schema.getQueryType() - ? schema.getQueryType().name - : ""; - const mutationTypeName = schema.getMutationType() - ? schema.getMutationType().name - : ""; - const subscriptionTypeName = schema.getSubscriptionType() - ? schema.getSubscriptionType().name - : ""; + const queryTypeName = schema.getQueryType() + ? schema.getQueryType().name + : ""; + const mutationTypeName = schema.getMutationType() + ? schema.getMutationType().name + : ""; + const subscriptionTypeName = schema.getSubscriptionType() + ? schema.getSubscriptionType().name + : ""; - for (const type in typeMap) { - if ( - !typeMap[type].name.startsWith("__") && - ![queryTypeName, mutationTypeName, subscriptionTypeName].includes( - typeMap[type].name - ) && - typeMap[type] instanceof gql.GraphQLObjectType - ) { - types.push(typeMap[type]); - } + for (const type in typeMap) { + if ( + !typeMap[type].name.startsWith("__") && + ![queryTypeName, mutationTypeName, subscriptionTypeName].includes( + typeMap[type].name + ) && + typeMap[type] instanceof gql.GraphQLObjectType + ) { + types.push(typeMap[type]); } + } this.gqlTypes = types; this.$nuxt.$loading.finish(); From a7d483ea1b54099ce39f74160c59d5a944d0c867 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:07:52 +0530 Subject: [PATCH 5/7] fix: lint --- pages/graphql.vue | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index f6bdcebe2..c8da4e158 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -209,13 +209,13 @@ export default { types.push(typeMap[type]); } } - this.gqlTypes = types; + this.gqlTypes = types; - this.$nuxt.$loading.finish(); - const duration = Date.now() - startTime; - this.$toast.info(`Finished in ${duration}ms`, { - icon: "done" - }); + this.$nuxt.$loading.finish(); + const duration = Date.now() - startTime; + this.$toast.info(`Finished in ${duration}ms`, { + icon: "done" + }); } catch(err) { this.$nuxt.$loading.finish(); this.schemaString = error + ". Check console for details."; From 2083e026989cc18693c399ab59ca7e0ab49b912b Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:08:22 +0530 Subject: [PATCH 6/7] fix: typo --- pages/graphql.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index c8da4e158..8663ca1fe 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -216,7 +216,7 @@ export default { this.$toast.info(`Finished in ${duration}ms`, { icon: "done" }); - } catch(err) { + } catch(error) { this.$nuxt.$loading.finish(); this.schemaString = error + ". Check console for details."; this.$toast.error(error + " (F12 for details)", { From 3639ed8f70e74ed167083a9f0c0e9514314cbba4 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Wed, 20 Nov 2019 18:11:07 +0530 Subject: [PATCH 7/7] fix: add async nature --- pages/graphql.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/graphql.vue b/pages/graphql.vue index 8663ca1fe..bd1f6ce0a 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -140,7 +140,7 @@ export default { }; }, methods: { - getSchema() { + async getSchema() { const startTime = Date.now(); this.schemaString = "Loading..."; @@ -223,7 +223,7 @@ export default { icon: "error" }); console.log("Error", error); - }); + } } } };