@graphql-inspector/core
Advanced tools
Comparing version 0.7.2 to 0.7.3
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var graphql_1 = require("graphql"); | ||
var dependency_graph_1 = require("dependency-graph"); | ||
var document_1 = require("../ast/document"); | ||
@@ -12,15 +13,42 @@ var graphql_2 = require("../utils/graphql"); | ||
var fragments = []; | ||
var graph = new dependency_graph_1.DepGraph({ circular: true }); | ||
documents.forEach(function (doc) { | ||
doc.fragments.forEach(function (fragment) { | ||
fragments.push(fragment.node); | ||
fragments.push(fragment); | ||
graph.addNode(fragment.node.name.value, fragment.node); | ||
}); | ||
}); | ||
documents.forEach(function (doc) { | ||
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 | ||
.filter(function (f) { return doc.source.body.indexOf("fragment " + f.name.value + " on"); }) | ||
fragments.forEach(function (fragment) { | ||
var depends = extractFragments(graphql_1.print(fragment.node)); | ||
if (depends) { | ||
depends.forEach(function (name) { | ||
graph.addDependency(fragment.node.name.value, name); | ||
}); | ||
} | ||
}); | ||
documents | ||
// since we include fragments, validate only operations | ||
.filter(function (doc) { return doc.hasOperations; }) | ||
.forEach(function (doc) { | ||
var merged = "\n " + doc.source.body + "\n\n " + (extractFragments(doc.source.body) || []) | ||
// resolve all nested fragments | ||
.map(function (fragmentName) { | ||
return resolveFragment(graph.getNodeData(fragmentName), graph); | ||
}) | ||
// flatten arrays | ||
.reduce(function (list, current) { return list.concat(current); }, []) | ||
// remove duplicates | ||
.filter(function (def, i, all) { | ||
return all.findIndex(function (item) { return item.name.value === def.name.value; }) === i; | ||
}) | ||
// does not include fragment definition | ||
.filter(function (fragment) { | ||
return doc.source.body.indexOf("fragment " + fragment.name.value + " on") === | ||
-1; | ||
}) | ||
.map(graphql_1.print) | ||
.join('\n\n') + "\n ")); | ||
// merge | ||
.join('\n\n') + "\n "; | ||
var errors = graphql_1.validate(schema, graphql_1.parse(merged)); | ||
var deprecated = graphql_2.findDeprecatedUsages(schema, graphql_1.parse(doc.source.body)); | ||
@@ -38,2 +66,16 @@ if (errors || deprecated) { | ||
exports.validate = validate; | ||
// | ||
// PostInfo -> AuthorInfo | ||
// AuthorInfo -> None | ||
// | ||
function resolveFragment(fragment, graph) { | ||
return graph | ||
.dependenciesOf(fragment.name.value) | ||
.reduce(function (list, current) { return list.concat(resolveFragment(graph.getNodeData(current), graph)); }, [fragment]); | ||
} | ||
function extractFragments(document) { | ||
return (document.match(/[\.]{3}[a-z0-9\_]+\b/gi) || []).map(function (name) { | ||
return name.replace('...', ''); | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@graphql-inspector/core", | ||
"version": "0.7.2", | ||
"version": "0.7.3", | ||
"description": "Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.", | ||
@@ -39,3 +39,6 @@ "keywords": [ | ||
"typescript": "3.2.2" | ||
}, | ||
"dependencies": { | ||
"dependency-graph": "0.8.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
786669
85
1671
2
+ Addeddependency-graph@0.8.0
+ Addeddependency-graph@0.8.0(transitive)