From 744d6477044a2856c4d59d487c6fb406f7aa0f7c Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 14:38:46 -0500 Subject: [PATCH] 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) },