"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var graphql_1 = require("graphql");
var document_1 = require("../ast/document");
function validate(schema, sources) {
    var invalidDocuments = [];
    // read documents
    var documents = sources.map(document_1.readDocument);
    // keep all named fragments
    var fragments = [];
    documents.forEach(function (doc) {
        doc.fragments.forEach(function (fragment) {
            fragments.push(fragment.node);
        });
    });
    documents.forEach(function (doc) {
        // doc.operations.forEach(op => {
        var errors = graphql_1.validate(schema, 
        // all fragments next to an operation? Stuuuupid
        // but should be enough for now
        graphql_1.parse("\n          " + doc.source.body + "\n\n          " + fragments.map(graphql_1.print).join('\n\n') + "\n        "));
        if (errors) {
            invalidDocuments.push({
                source: doc.source,
                errors: errors,
            });
        }
        // });
    });
    return invalidDocuments;
}
exports.validate = validate;
//# sourceMappingURL=index.js.map