UNPKG

6.1 kBJavaScriptView Raw
1"use strict";
2var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4 return cooked;
5};
6var __assign = (this && this.__assign) || function () {
7 __assign = Object.assign || function(t) {
8 for (var s, i = 1, n = arguments.length; i < n; i++) {
9 s = arguments[i];
10 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
11 t[p] = s[p];
12 }
13 return t;
14 };
15 return __assign.apply(this, arguments);
16};
17var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18 return new (P || (P = Promise))(function (resolve, reject) {
19 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
22 step((generator = generator.apply(thisArg, _arguments || [])).next());
23 });
24};
25var __generator = (this && this.__generator) || function (thisArg, body) {
26 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28 function verb(n) { return function (v) { return step([n, v]); }; }
29 function step(op) {
30 if (f) throw new TypeError("Generator is already executing.");
31 while (_) try {
32 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33 if (y = 0, t) op = [op[0] & 2, t.value];
34 switch (op[0]) {
35 case 0: case 1: t = op; break;
36 case 4: _.label++; return { value: op[1], done: false };
37 case 5: _.label++; y = op[1]; op = [0]; continue;
38 case 7: op = _.ops.pop(); _.trys.pop(); continue;
39 default:
40 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44 if (t[2]) _.ops.pop();
45 _.trys.pop(); continue;
46 }
47 op = body.call(thisArg, _);
48 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50 }
51};
52Object.defineProperty(exports, "__esModule", { value: true });
53var core_1 = require("@graphql-inspector/core");
54var load_1 = require("@graphql-inspector/load");
55var graphql_tag_1 = require("graphql-tag");
56exports.typeDefs = graphql_tag_1.default(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n type Location {\n start: Int!\n end: Int!\n }\n\n type DocumentLocation {\n name: String!\n locations: [Location!]\n }\n\n type TypeChildCoverage {\n name: String!\n hits: Int!\n locations: [DocumentLocation!]\n }\n\n type TypeCoverage {\n name: String!\n hits: Int!\n # type: GraphQLNamedType; TODO: define that\n children: [TypeChildCoverage!]\n }\n\n type SchemaCoverage {\n sources: [DocumentSource!]\n types: [TypeCoverage!]\n }\n\n extend type Query {\n coverage(schema: String!, documents: String!): SchemaCoverage!\n }\n"], ["\n type Location {\n start: Int!\n end: Int!\n }\n\n type DocumentLocation {\n name: String!\n locations: [Location!]\n }\n\n type TypeChildCoverage {\n name: String!\n hits: Int!\n locations: [DocumentLocation!]\n }\n\n type TypeCoverage {\n name: String!\n hits: Int!\n # type: GraphQLNamedType; TODO: define that\n children: [TypeChildCoverage!]\n }\n\n type SchemaCoverage {\n sources: [DocumentSource!]\n types: [TypeCoverage!]\n }\n\n extend type Query {\n coverage(schema: String!, documents: String!): SchemaCoverage!\n }\n"])));
57var Query = {
58 coverage: function (_, args) {
59 return __awaiter(this, void 0, void 0, function () {
60 var schema, documents;
61 return __generator(this, function (_a) {
62 switch (_a.label) {
63 case 0: return [4 /*yield*/, load_1.loadSchema(args.schema)];
64 case 1:
65 schema = _a.sent();
66 return [4 /*yield*/, load_1.loadDocuments(args.documents)];
67 case 2:
68 documents = _a.sent();
69 return [2 /*return*/, core_1.coverage(schema, documents)];
70 }
71 });
72 });
73 },
74};
75var SchemaCoverage = {
76 types: function (schemaCoverage) {
77 return Object.keys(schemaCoverage.types).map(function (name) { return (__assign({ name: name }, schemaCoverage.types[name])); });
78 },
79};
80var TypeCoverage = {
81 children: function (typeCoverage) {
82 return Object.keys(typeCoverage.children).map(function (name) { return (__assign({ name: name }, typeCoverage.children[name])); });
83 },
84};
85var TypeChildCoverage = {
86 locations: function (typeChildCoverage) {
87 return Object.keys(typeChildCoverage.locations).map(function (name) { return ({
88 name: name,
89 locations: typeChildCoverage.locations[name],
90 }); });
91 },
92};
93exports.resolvers = {
94 Query: Query,
95 SchemaCoverage: SchemaCoverage,
96 TypeCoverage: TypeCoverage,
97 TypeChildCoverage: TypeChildCoverage,
98};
99var templateObject_1;
100//# sourceMappingURL=coverage.js.map
\No newline at end of file