Added ability to query editor to validate based on schema

This commit is contained in:
Andrew Bastin
2020-01-19 14:21:31 -05:00
parent 8b970ed9a0
commit f0cfee56f2

View File

@@ -33,7 +33,8 @@ export default {
data() { data() {
return { return {
editor: null, editor: null,
cacheValue: "" cacheValue: "",
validationSchema: null
}; };
}, },
@@ -88,9 +89,28 @@ export default {
} }
}, },
setValidationSchema(schema) {
this.validationSchema = schema;
this.parseContents(this.cacheValue);
},
parseContents: debounce(function(content) { parseContents: debounce(function(content) {
try { 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) { } catch (e) {
this.editor.session.setAnnotations([ this.editor.session.setAnnotations([
{ {