UNPKG

5.41 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
8
9var getIntrospection = function () {
10 var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(client, typeName) {
11 var _introspection;
12
13 return regeneratorRuntime.wrap(function _callee$(_context) {
14 while (1) {
15 switch (_context.prev = _context.next) {
16 case 0:
17 _introspection = void 0;
18 _context.prev = 1;
19 _context.next = 4;
20 return introspection.type(client, typeName);
21
22 case 4:
23 _introspection = _context.sent;
24 _context.next = 9;
25 break;
26
27 case 7:
28 _context.prev = 7;
29 _context.t0 = _context['catch'](1);
30
31 case 9:
32 return _context.abrupt('return', _introspection);
33
34 case 10:
35 case 'end':
36 return _context.stop();
37 }
38 }
39 }, _callee, this, [[1, 7]]);
40 }));
41
42 return function getIntrospection(_x, _x2) {
43 return _ref.apply(this, arguments);
44 };
45}();
46
47var _introspection2 = require('./introspection');
48
49var introspection = _interopRequireWildcard(_introspection2);
50
51function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
52
53function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
54
55function fragmentToQL(fragment) {
56 var iterate = function iterate(i) {
57 return Object.keys(i).map(function (key) {
58 var result;
59 var value = i[key];
60 if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object') {
61 result = key + ' { ' + iterate(value) + ' }';
62 } else {
63 result = key;
64 }
65 return result;
66 }).join(',');
67 };
68 return iterate(fragment);
69}
70
71function getAvaliableFragments(a, b) {
72 var fragment = {};
73 Object.keys(b).forEach(function (field) {
74 var _field = a.find(function (f) {
75 return f.name === field;
76 });
77 if (_field) {
78 if (_typeof(b[field]) === 'object' && _field.type.ofType.kind === 'OBJECT') {
79 fragment[field] = b[field];
80 } else {
81 fragment[field] = 1;
82 }
83 }
84 });
85 return fragment;
86}
87
88var protectionFields = {
89 _id: 1,
90 state: 1,
91 bail: 1,
92 growthWarning: 1,
93 errorMessage: 1,
94 size: 1,
95 transformedSize: 1
96};
97
98var deprecationFields = {
99 type: 1,
100 entity: 1
101};
102
103var sourceFields = {
104 filename: 1
105};
106
107var errorMessageFields = {
108 message: 1,
109 line: 1,
110 column: 1,
111 fatal: 1
112};
113
114exports.default = function () {
115 var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(client) {
116 var appProtection, deprecation, source, errorMessage, fragments;
117 return regeneratorRuntime.wrap(function _callee2$(_context2) {
118 while (1) {
119 switch (_context2.prev = _context2.next) {
120 case 0:
121 _context2.next = 2;
122 return getIntrospection(client, 'ApplicationProtection');
123
124 case 2:
125 appProtection = _context2.sent;
126 _context2.next = 5;
127 return getIntrospection(client, 'Deprecation');
128
129 case 5:
130 deprecation = _context2.sent;
131 _context2.next = 8;
132 return getIntrospection(client, 'ApplicationSource');
133
134 case 8:
135 source = _context2.sent;
136 _context2.next = 11;
137 return getIntrospection(client, 'ErrorMessages');
138
139 case 11:
140 errorMessage = _context2.sent;
141 fragments = {
142 application: {
143 name: 1
144 },
145 applicationProtection: {}
146 };
147
148 fragments.applicationProtection = appProtection && getAvaliableFragments(appProtection.fields, protectionFields);
149
150 fragments.applicationProtection.deprecations = deprecation && getAvaliableFragments(deprecation.fields, deprecationFields);
151
152 fragments.applicationProtection.sources = source && getAvaliableFragments(source.fields, sourceFields);
153
154 fragments.applicationProtection.sources.errorMessages = errorMessage && getAvaliableFragments(errorMessage.fields, errorMessageFields);
155
156 return _context2.abrupt('return', {
157 application: fragmentToQL(fragments.application),
158 applicationProtection: fragmentToQL(fragments.applicationProtection)
159 });
160
161 case 18:
162 case 'end':
163 return _context2.stop();
164 }
165 }
166 }, _callee2, this);
167 }));
168
169 return function (_x3) {
170 return _ref2.apply(this, arguments);
171 };
172}();
\No newline at end of file