diff --git a/components/graphql/queryeditor.vue b/components/graphql/queryeditor.vue index c89d9807e..7f1084b85 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,19 +88,42 @@ export default { ); } }, + + setValidationSchema(schema) { + this.validationSchema = schema; + this.parseContents(this.cacheValue); + }, parseContents: debounce(function(content) { - try { - gql.parse(content); - } catch (e) { - this.editor.session.setAnnotations([ - { - row: e.locations[0].line - 1, - column: e.locations[0].column - 1, - text: e.message, - type: "error" + 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" + } + ]); + } + } else { + this.editor.session.setAnnotations([]); } }, 2000) }, 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; diff --git a/store/postwoman.js b/store/postwoman.js index bf5881268..61712fb65 100644 --- a/store/postwoman.js +++ b/store/postwoman.js @@ -111,6 +111,12 @@ export const mutations = { }, addNewCollection({ collections }, collection) { + const { name } = collection + const duplicateCollection = collections.some(item => item.name === name) + if (duplicateCollection) { + this.$toast.info('Duplicate collection'); + return; + } collections.push({ name: "", folders: [],