From f0cfee56f2106d906f00968ce0ef0ac307690016 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 14:21:31 -0500 Subject: [PATCH 1/8] Added ability to query editor to validate based on schema --- components/graphql/queryeditor.vue | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/components/graphql/queryeditor.vue b/components/graphql/queryeditor.vue index c89d9807e..959781992 100644 --- a/components/graphql/queryeditor.vue +++ b/components/graphql/queryeditor.vue @@ -33,7 +33,8 @@ export default { data() { return { editor: null, - cacheValue: "" + cacheValue: "", + validationSchema: null }; }, @@ -87,10 +88,29 @@ export default { ); } }, + + setValidationSchema(schema) { + this.validationSchema = schema; + this.parseContents(this.cacheValue); + }, parseContents: debounce(function(content) { try { - gql.parse(content); + const doc = gql.parse(content); + + if (this.validationSchema) { + this.editor.session.setAnnotations( + gql.validate(this.validationSchema, doc) + .map((err) => { + return { + row: err.locations[0].line - 1, + column: err.locations[0].column - 1, + text: err.message, + type: "error" + } + }) + ) + } } catch (e) { this.editor.session.setAnnotations([ { From 77e51f330111312be0eda10a57732cd620daa2b6 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 14:22:56 -0500 Subject: [PATCH 2/8] GraphQL page now notifies the query editor about the schema for validation --- pages/graphql.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pages/graphql.vue b/pages/graphql.vue index f6ca59d6c..606796472 100644 --- a/pages/graphql.vue +++ b/pages/graphql.vue @@ -812,6 +812,8 @@ export default { } } this.gqlTypes = types; + + this.$refs.queryEditor.setValidationSchema(schema); this.$nuxt.$loading.finish(); const duration = Date.now() - startTime; From 744d6477044a2856c4d59d487c6fb406f7aa0f7c Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 14:38:46 -0500 Subject: [PATCH 3/8] GQL Query Editor doesn't give errors for empty queries --- components/graphql/queryeditor.vue | 50 ++++++++++++++++-------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/components/graphql/queryeditor.vue b/components/graphql/queryeditor.vue index 959781992..7f1084b85 100644 --- a/components/graphql/queryeditor.vue +++ b/components/graphql/queryeditor.vue @@ -95,31 +95,35 @@ export default { }, parseContents: debounce(function(content) { - try { - const doc = gql.parse(content); + if (content !== "") { + try { + const doc = gql.parse(content); - if (this.validationSchema) { - this.editor.session.setAnnotations( - gql.validate(this.validationSchema, doc) - .map((err) => { - return { - row: err.locations[0].line - 1, - column: err.locations[0].column - 1, - text: err.message, - type: "error" - } - }) - ) - } - } catch (e) { - this.editor.session.setAnnotations([ - { - row: e.locations[0].line - 1, - column: e.locations[0].column - 1, - text: e.message, - type: "error" + if (this.validationSchema) { + this.editor.session.setAnnotations( + gql.validate(this.validationSchema, doc) + .map((err) => { + return { + row: err.locations[0].line - 1, + column: err.locations[0].column - 1, + text: err.message, + type: "error" + } + }) + ) } - ]); + } catch (e) { + this.editor.session.setAnnotations([ + { + row: e.locations[0].line - 1, + column: e.locations[0].column - 1, + text: e.message, + type: "error" + } + ]); + } + } else { + this.editor.session.setAnnotations([]); } }, 2000) }, From 2853a4bbef8e3ded138d7dcb4be8d074a08a6907 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 21 Jan 2020 16:37:04 +0530 Subject: [PATCH 4/8] fix: validation for duplicate collections --- store/postwoman.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/store/postwoman.js b/store/postwoman.js index bf5881268..895464977 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -111,6 +111,10 @@ export const mutations = { }, addNewCollection({ collections }, collection) { + const duplicateCollection = collections.some(item => item.name === collection.name) + if (duplicateCollection) { + alert('Duplicate collection'); + } collections.push({ name: "", folders: [], From a34acfd0c53b79227ddc5f9edfdd003278ba7108 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 21 Jan 2020 16:38:09 +0530 Subject: [PATCH 5/8] fix: return for duplicate collection --- store/postwoman.js | 1 + 1 file changed, 1 insertion(+) diff --git a/store/postwoman.js b/store/postwoman.js index 895464977..dabaf781b 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -114,6 +114,7 @@ export const mutations = { const duplicateCollection = collections.some(item => item.name === collection.name) if (duplicateCollection) { alert('Duplicate collection'); + return; } collections.push({ name: "", From fcdf93c5e55683f8f02edd450c7e76a2fa9c88ec Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 21 Jan 2020 16:38:34 +0530 Subject: [PATCH 6/8] fix: prefer destructuring approach --- store/postwoman.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/store/postwoman.js b/store/postwoman.js index dabaf781b..df7399d31 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -111,7 +111,8 @@ export const mutations = { }, addNewCollection({ collections }, collection) { - const duplicateCollection = collections.some(item => item.name === collection.name) + const { name } = collection + const duplicateCollection = collections.some(item => item.name === name) if (duplicateCollection) { alert('Duplicate collection'); return; From e16019dcbf0c939305fecd79a32cb37f6ea80741 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 21 Jan 2020 19:45:52 +0530 Subject: [PATCH 7/8] chore: make use of toast --- store/postwoman.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/store/postwoman.js b/store/postwoman.js index df7399d31..d07d70957 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -114,8 +114,7 @@ export const mutations = { const { name } = collection const duplicateCollection = collections.some(item => item.name === name) if (duplicateCollection) { - alert('Duplicate collection'); - return; + this.$toast.info('Duplicate collection'); } collections.push({ name: "", From bb973ee449cf2f44bb95e558b2e2e69a23d042f2 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Tue, 21 Jan 2020 19:46:33 +0530 Subject: [PATCH 8/8] fix: prevent creation of duplicate collection --- store/postwoman.js | 1 + 1 file changed, 1 insertion(+) diff --git a/store/postwoman.js b/store/postwoman.js index d07d70957..61712fb65 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -115,6 +115,7 @@ export const mutations = { const duplicateCollection = collections.some(item => item.name === name) if (duplicateCollection) { this.$toast.info('Duplicate collection'); + return; } collections.push({ name: "",