From f0cfee56f2106d906f00968ce0ef0ac307690016 Mon Sep 17 00:00:00 2001 From: Andrew Bastin Date: Sun, 19 Jan 2020 14:21:31 -0500 Subject: [PATCH] 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([ {