-
-
Save maktouch/e1a2955dfcca42541a41665a361be28b to your computer and use it in GitHub Desktop.
query-validator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const schema = require('./schemas').default; | |
const gql = require('graphql-tag'); | |
const { validate, graphql } = require('graphql'); | |
const { removeConnectionDirectiveFromDocument } = require('apollo-utilities'); | |
const { diffString } = require('json-diff'); | |
const raw = fs.readFileSync('gql-queries.json'); | |
const { queries, fragments } = JSON.parse(raw.toString()); | |
const checkQueries = async () => { | |
const output = []; | |
Object.keys(queries).forEach(path => { | |
const { query } = queries[path]; | |
const parsedQuery = removeConnectionDirectiveFromDocument(gql(query)); | |
const errors = validate(schema, parsedQuery); | |
if (errors.length === 0) { | |
return; | |
} | |
const parsedErrors = errors.map(e => e.message); | |
output.push({ | |
path, | |
errors: parsedErrors, | |
}); | |
}); | |
return output; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment