introspectron 0.2.4 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +12 -0
- package/esm/gql.js +297 -0
- package/esm/index.js +6 -0
- package/esm/introspect.js +85 -0
- package/{module → esm}/introspectGql.js +2 -2
- package/esm/process.js +278 -0
- package/{module → esm}/query.js +16 -12
- package/esm/utils.js +42 -0
- package/gql.d.ts +4 -0
- package/gql.js +301 -0
- package/{module/index.js → index.d.ts} +1 -1
- package/index.js +22 -0
- package/introspect.d.ts +16 -0
- package/introspect.js +89 -0
- package/introspectGql.d.ts +1 -0
- package/introspectGql.js +105 -0
- package/package.json +19 -51
- package/process.d.ts +1 -0
- package/process.js +282 -0
- package/query.d.ts +1 -0
- package/query.js +425 -0
- package/utils.d.ts +2 -0
- package/utils.js +47 -0
- package/CHANGELOG.md +0 -99
- package/main/gql.js +0 -376
- package/main/index.js +0 -70
- package/main/introspect.js +0 -194
- package/main/introspectGql.js +0 -25
- package/main/process.js +0 -410
- package/main/query.js +0 -26
- package/main/utils.js +0 -64
- package/module/gql.js +0 -330
- package/module/introspect.js +0 -75
- package/module/process.js +0 -321
- package/module/utils.js +0 -46
package/main/gql.js
DELETED
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.parseGraphQuery = void 0;
|
|
9
|
-
|
|
10
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
-
|
|
14
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
15
|
-
|
|
16
|
-
var parseGraphQuery = function parseGraphQuery(introQuery) {
|
|
17
|
-
var types = introQuery.__schema.types;
|
|
18
|
-
var HASH = types.reduce(function (m, v) {
|
|
19
|
-
m[v.name] = v;
|
|
20
|
-
return m;
|
|
21
|
-
}, {});
|
|
22
|
-
var queriesRoot = types.find(function (t) {
|
|
23
|
-
return t.name === 'Query';
|
|
24
|
-
});
|
|
25
|
-
var mutationsRoot = types.find(function (t) {
|
|
26
|
-
return t.name === 'Mutation';
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
var getInputForQueries = function getInputForQueries(input) {
|
|
30
|
-
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
31
|
-
|
|
32
|
-
if (input.kind === 'NON_NULL') {
|
|
33
|
-
context.isNotNull = true;
|
|
34
|
-
return getInputForQueries(input.ofType, context);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (input.kind === 'LIST') {
|
|
38
|
-
context.isArray = true;
|
|
39
|
-
|
|
40
|
-
if (context.isNotNull) {
|
|
41
|
-
context.isArrayNotNull = true;
|
|
42
|
-
delete context.isNotNull;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return getInputForQueries(input.ofType, context);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (input.kind === 'INPUT_OBJECT') {
|
|
49
|
-
if (input.name && HASH.hasOwnProperty(input.name)) {
|
|
50
|
-
var schema = HASH[input.name];
|
|
51
|
-
context.properties = schema.inputFields.map(function (field) {
|
|
52
|
-
return {
|
|
53
|
-
name: field.name,
|
|
54
|
-
type: field.type
|
|
55
|
-
};
|
|
56
|
-
}).reduce(function (m3, v) {
|
|
57
|
-
m3[v.name] = v;
|
|
58
|
-
return m3;
|
|
59
|
-
}, {});
|
|
60
|
-
}
|
|
61
|
-
} else if (input.kind === 'OBJECT') {
|
|
62
|
-
if (input.name && HASH.hasOwnProperty(input.name)) {
|
|
63
|
-
var _schema = HASH[input.name];
|
|
64
|
-
context.properties = _schema.fields.map(function (field) {
|
|
65
|
-
return {
|
|
66
|
-
name: field.name,
|
|
67
|
-
type: field.type
|
|
68
|
-
};
|
|
69
|
-
}).reduce(function (m3, v) {
|
|
70
|
-
m3[v.name] = v;
|
|
71
|
-
return m3;
|
|
72
|
-
}, {});
|
|
73
|
-
}
|
|
74
|
-
} else {
|
|
75
|
-
context.type = input.name;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return context;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
var getInputForMutations = function getInputForMutations(input) {
|
|
82
|
-
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
83
|
-
|
|
84
|
-
if (input.kind === 'NON_NULL') {
|
|
85
|
-
context.isNotNull = true;
|
|
86
|
-
return getInputForMutations(input.ofType, context);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (input.kind === 'LIST') {
|
|
90
|
-
context.isArray = true;
|
|
91
|
-
|
|
92
|
-
if (context.isNotNull) {
|
|
93
|
-
context.isArrayNotNull = true;
|
|
94
|
-
delete context.isNotNull;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return getInputForMutations(input.ofType, context);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (input.kind === 'INPUT_OBJECT') {
|
|
101
|
-
if (input.name && HASH.hasOwnProperty(input.name)) {
|
|
102
|
-
var schema = HASH[input.name];
|
|
103
|
-
context.properties = schema.inputFields.map(function (field) {
|
|
104
|
-
return getInputForMutations(field.type, {
|
|
105
|
-
name: field.name
|
|
106
|
-
});
|
|
107
|
-
}).reduce(function (m3, v) {
|
|
108
|
-
m3[v.name] = v;
|
|
109
|
-
return m3;
|
|
110
|
-
}, {});
|
|
111
|
-
}
|
|
112
|
-
} else if (input.kind === 'OBJECT') {
|
|
113
|
-
if (input.name && HASH.hasOwnProperty(input.name)) {
|
|
114
|
-
var _schema2 = HASH[input.name];
|
|
115
|
-
context.properties = _schema2.fields.map(function (field) {
|
|
116
|
-
return {
|
|
117
|
-
name: field.name,
|
|
118
|
-
type: field.type
|
|
119
|
-
};
|
|
120
|
-
}).reduce(function (m3, v) {
|
|
121
|
-
m3[v.name] = v;
|
|
122
|
-
return m3;
|
|
123
|
-
}, {});
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
context.type = input.name;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return context;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
var mutations = mutationsRoot.fields.reduce(function (m, mutation) {
|
|
133
|
-
var mutationType = 'other';
|
|
134
|
-
|
|
135
|
-
if (/^Create/.test(mutation.type.name)) {
|
|
136
|
-
mutationType = 'create';
|
|
137
|
-
} else if (/^Update/.test(mutation.type.name)) {
|
|
138
|
-
mutationType = 'patch';
|
|
139
|
-
} else if (/^Delete/.test(mutation.type.name)) {
|
|
140
|
-
mutationType = 'delete';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
var props = mutation.args.reduce(function (m2, arg) {
|
|
144
|
-
var _arg$type, _arg$type$ofType, _arg$type2;
|
|
145
|
-
|
|
146
|
-
var type = (_arg$type = arg.type) === null || _arg$type === void 0 ? void 0 : (_arg$type$ofType = _arg$type.ofType) === null || _arg$type$ofType === void 0 ? void 0 : _arg$type$ofType.name;
|
|
147
|
-
var isNotNull = ((_arg$type2 = arg.type) === null || _arg$type2 === void 0 ? void 0 : _arg$type2.kind) === 'NON_NULL';
|
|
148
|
-
|
|
149
|
-
if (type && HASH.hasOwnProperty(type)) {
|
|
150
|
-
var schema = HASH[type];
|
|
151
|
-
var fields = schema.inputFields.filter(function (a) {
|
|
152
|
-
return a.name !== 'clientMutationId';
|
|
153
|
-
});
|
|
154
|
-
var properties = fields.map(function (a) {
|
|
155
|
-
return getInputForMutations(a.type, {
|
|
156
|
-
name: a.name
|
|
157
|
-
});
|
|
158
|
-
}).reduce(function (m3, v) {
|
|
159
|
-
m3[v.name] = v;
|
|
160
|
-
return m3;
|
|
161
|
-
}, {});
|
|
162
|
-
m2[arg.name] = {
|
|
163
|
-
isNotNull: isNotNull,
|
|
164
|
-
type: type,
|
|
165
|
-
properties: properties
|
|
166
|
-
};
|
|
167
|
-
} else {
|
|
168
|
-
console.warn('whats wrong with ' + arg);
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return m2;
|
|
172
|
-
}, {});
|
|
173
|
-
|
|
174
|
-
var getModelTypes = function getModelTypes(type) {
|
|
175
|
-
return type.fields.filter(function (t) {
|
|
176
|
-
return t.type.kind === 'OBJECT';
|
|
177
|
-
}).filter(function (t) {
|
|
178
|
-
return t.type.name !== 'Query';
|
|
179
|
-
}).map(function (f) {
|
|
180
|
-
return {
|
|
181
|
-
name: f.name,
|
|
182
|
-
type: f.type
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
var models = getModelTypes(HASH[mutation.type.name]);
|
|
188
|
-
|
|
189
|
-
if (models.length > 0) {
|
|
190
|
-
// TODO this is probably brittle
|
|
191
|
-
var model = models[0].type.name;
|
|
192
|
-
m[mutation.name] = {
|
|
193
|
-
qtype: 'mutation',
|
|
194
|
-
mutationType: mutationType,
|
|
195
|
-
model: model,
|
|
196
|
-
properties: props,
|
|
197
|
-
output: mutation.type
|
|
198
|
-
};
|
|
199
|
-
} else {
|
|
200
|
-
// no return args, probably void functions
|
|
201
|
-
var t;
|
|
202
|
-
var outputFields = [];
|
|
203
|
-
|
|
204
|
-
if (mutation.type.kind === 'OBJECT') {
|
|
205
|
-
t = HASH[mutation.type.name];
|
|
206
|
-
outputFields = t.fields.map(function (f) {
|
|
207
|
-
return {
|
|
208
|
-
name: f.name,
|
|
209
|
-
type: f.type
|
|
210
|
-
};
|
|
211
|
-
}).filter(function (f) {
|
|
212
|
-
return f.name !== 'clientMutationId';
|
|
213
|
-
}).filter(function (f) {
|
|
214
|
-
return f.type.name !== 'Query';
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
m[mutation.name] = {
|
|
219
|
-
qtype: 'mutation',
|
|
220
|
-
mutationType: mutationType,
|
|
221
|
-
properties: props,
|
|
222
|
-
output: mutation.type,
|
|
223
|
-
outputs: outputFields
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return m;
|
|
228
|
-
}, {}); // expect(mts).toMatchSnapshot();
|
|
229
|
-
|
|
230
|
-
var parseConnectionQuery = function parseConnectionQuery(query, nesting) {
|
|
231
|
-
var objectType = getObjectType(query.type);
|
|
232
|
-
var Connection = HASH[objectType];
|
|
233
|
-
var nodes = Connection.fields.find(function (f) {
|
|
234
|
-
return f.name === 'nodes';
|
|
235
|
-
});
|
|
236
|
-
var edges = Connection.fields.find(function (f) {
|
|
237
|
-
return f.name === 'edges';
|
|
238
|
-
});
|
|
239
|
-
var model = getObjectType(nodes.type);
|
|
240
|
-
var context = {
|
|
241
|
-
HASH: HASH,
|
|
242
|
-
parseConnectionQuery: parseConnectionQuery,
|
|
243
|
-
parseSingleQuery: parseSingleQuery
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
if (nesting === 0) {
|
|
247
|
-
return {
|
|
248
|
-
qtype: 'getMany',
|
|
249
|
-
model: model,
|
|
250
|
-
selection: parseSelectionScalar(context, model)
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return {
|
|
255
|
-
qtype: 'getMany',
|
|
256
|
-
model: model,
|
|
257
|
-
selection: parseSelectionObject(context, model, 1)
|
|
258
|
-
};
|
|
259
|
-
};
|
|
260
|
-
|
|
261
|
-
var parseSingleQuery = function parseSingleQuery(query, nesting) {
|
|
262
|
-
var model = getObjectType(query.type);
|
|
263
|
-
var context = {
|
|
264
|
-
HASH: HASH,
|
|
265
|
-
parseConnectionQuery: parseConnectionQuery,
|
|
266
|
-
parseSingleQuery: parseSingleQuery
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
if (nesting === 0) {
|
|
270
|
-
return {
|
|
271
|
-
qtype: 'getOne',
|
|
272
|
-
model: model,
|
|
273
|
-
properties: query.args.reduce(function (m2, v) {
|
|
274
|
-
m2[v.name] = getInputForQueries(v.type);
|
|
275
|
-
return m2;
|
|
276
|
-
}, {}),
|
|
277
|
-
selection: parseSelectionScalar(context, model)
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
return {
|
|
282
|
-
model: model,
|
|
283
|
-
qtype: 'getOne',
|
|
284
|
-
properties: query.args.reduce(function (m2, v) {
|
|
285
|
-
m2[v.name] = getInputForQueries(v.type);
|
|
286
|
-
return m2;
|
|
287
|
-
}, {}),
|
|
288
|
-
selection: parseSelectionObject(context, model, 1)
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
var queries = queriesRoot.fields.reduce(function (m, query) {
|
|
293
|
-
// m[query.name] = getInputForQueries(query.type);
|
|
294
|
-
if (query.type.kind === 'OBJECT') {
|
|
295
|
-
if (isConnectionQuery(query)) {
|
|
296
|
-
m[query.name] = parseConnectionQuery(query, 1);
|
|
297
|
-
} else {
|
|
298
|
-
m[query.name] = parseSingleQuery(query, 1);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
return m;
|
|
303
|
-
}, {});
|
|
304
|
-
return {
|
|
305
|
-
queries: queries,
|
|
306
|
-
mutations: mutations
|
|
307
|
-
};
|
|
308
|
-
}; // Parse selections for both scalar and object fields
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
exports.parseGraphQuery = parseGraphQuery;
|
|
312
|
-
|
|
313
|
-
function parseSelectionObject(context, model, nesting) {
|
|
314
|
-
var HASH = context.HASH,
|
|
315
|
-
parseConnectionQuery = context.parseConnectionQuery,
|
|
316
|
-
parseSingleQuery = context.parseSingleQuery;
|
|
317
|
-
throwIfInvalidContext(context);
|
|
318
|
-
var selectionFields = HASH[model].fields.filter(function (f) {
|
|
319
|
-
return f.type.kind !== 'OBJECT';
|
|
320
|
-
});
|
|
321
|
-
var selection = selectionFields.map(function (f) {
|
|
322
|
-
var _f$type$ofType;
|
|
323
|
-
|
|
324
|
-
if (((_f$type$ofType = f.type.ofType) === null || _f$type$ofType === void 0 ? void 0 : _f$type$ofType.kind) === 'OBJECT') {
|
|
325
|
-
if (isConnectionQuery(f)) {
|
|
326
|
-
return _objectSpread({
|
|
327
|
-
name: f.name
|
|
328
|
-
}, parseConnectionQuery(f, nesting - 1));
|
|
329
|
-
} else {
|
|
330
|
-
return _objectSpread({
|
|
331
|
-
name: f.name
|
|
332
|
-
}, parseSingleQuery(f, nesting - 1));
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return f.name;
|
|
337
|
-
});
|
|
338
|
-
return selection;
|
|
339
|
-
} // Parse selections for scalar types only, ignore all field selections
|
|
340
|
-
// that have more nesting selection level
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
function parseSelectionScalar(context, model) {
|
|
344
|
-
var HASH = context.HASH;
|
|
345
|
-
throwIfInvalidContext(context);
|
|
346
|
-
var selectionFields = HASH[model].fields.filter(function (f) {
|
|
347
|
-
return f.type.kind !== 'OBJECT' && !isConnectionQuery(f);
|
|
348
|
-
});
|
|
349
|
-
var selection = selectionFields.map(function (f) {
|
|
350
|
-
return f.name;
|
|
351
|
-
});
|
|
352
|
-
return selection;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
function isConnectionQuery(query) {
|
|
356
|
-
var objectType = getObjectType(query.type);
|
|
357
|
-
var fields = query.args.map(function (a) {
|
|
358
|
-
return a.name;
|
|
359
|
-
});
|
|
360
|
-
return /Connection$/.test(objectType) && fields.includes('condition') && fields.includes('filter');
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
function getObjectType(type) {
|
|
364
|
-
if (type.kind === 'OBJECT') return type.name;
|
|
365
|
-
if (type.ofType) return getObjectType(type.ofType);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
function throwIfInvalidContext(context) {
|
|
369
|
-
var HASH = context.HASH,
|
|
370
|
-
parseConnectionQuery = context.parseConnectionQuery,
|
|
371
|
-
parseSingleQuery = context.parseSingleQuery;
|
|
372
|
-
|
|
373
|
-
if (!HASH || !parseConnectionQuery || !parseSingleQuery) {
|
|
374
|
-
throw new Error('parseSelection: context missing');
|
|
375
|
-
}
|
|
376
|
-
}
|
package/main/index.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _introspect = require("./introspect");
|
|
8
|
-
|
|
9
|
-
Object.keys(_introspect).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _introspect[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function get() {
|
|
15
|
-
return _introspect[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _process = require("./process");
|
|
21
|
-
|
|
22
|
-
Object.keys(_process).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] === _process[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function get() {
|
|
28
|
-
return _process[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
var _query = require("./query");
|
|
34
|
-
|
|
35
|
-
Object.keys(_query).forEach(function (key) {
|
|
36
|
-
if (key === "default" || key === "__esModule") return;
|
|
37
|
-
if (key in exports && exports[key] === _query[key]) return;
|
|
38
|
-
Object.defineProperty(exports, key, {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function get() {
|
|
41
|
-
return _query[key];
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
var _gql = require("./gql");
|
|
47
|
-
|
|
48
|
-
Object.keys(_gql).forEach(function (key) {
|
|
49
|
-
if (key === "default" || key === "__esModule") return;
|
|
50
|
-
if (key in exports && exports[key] === _gql[key]) return;
|
|
51
|
-
Object.defineProperty(exports, key, {
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function get() {
|
|
54
|
-
return _gql[key];
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
var _introspectGql = require("./introspectGql");
|
|
60
|
-
|
|
61
|
-
Object.keys(_introspectGql).forEach(function (key) {
|
|
62
|
-
if (key === "default" || key === "__esModule") return;
|
|
63
|
-
if (key in exports && exports[key] === _introspectGql[key]) return;
|
|
64
|
-
Object.defineProperty(exports, key, {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function get() {
|
|
67
|
-
return _introspectGql[key];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
package/main/introspect.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.introspect = void 0;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
|
-
var _query = require("./query");
|
|
15
|
-
|
|
16
|
-
var _utils = require("./utils");
|
|
17
|
-
|
|
18
|
-
var _flatMap = _interopRequireDefault(require("lodash/flatMap"));
|
|
19
|
-
|
|
20
|
-
var introspect =
|
|
21
|
-
/*#__PURE__*/
|
|
22
|
-
function () {
|
|
23
|
-
var _ref = (0, _asyncToGenerator2["default"])(
|
|
24
|
-
/*#__PURE__*/
|
|
25
|
-
_regenerator["default"].mark(function _callee(pgClient) {
|
|
26
|
-
var _ref2,
|
|
27
|
-
schemas,
|
|
28
|
-
_ref2$includeExtensio,
|
|
29
|
-
includeExtensions,
|
|
30
|
-
_ref2$pgEnableTags,
|
|
31
|
-
pgEnableTags,
|
|
32
|
-
_ref2$pgThrowOnMissin,
|
|
33
|
-
pgThrowOnMissingSchema,
|
|
34
|
-
versionResult,
|
|
35
|
-
serverVersionNum,
|
|
36
|
-
introspectionQuery,
|
|
37
|
-
_ref3,
|
|
38
|
-
rows,
|
|
39
|
-
result,
|
|
40
|
-
_iteratorNormalCompletion,
|
|
41
|
-
_didIteratorError,
|
|
42
|
-
_iteratorError,
|
|
43
|
-
_iterator,
|
|
44
|
-
_step,
|
|
45
|
-
object,
|
|
46
|
-
extensionConfigurationClassIds,
|
|
47
|
-
knownSchemas,
|
|
48
|
-
missingSchemas,
|
|
49
|
-
errorMessage,
|
|
50
|
-
_args = arguments;
|
|
51
|
-
|
|
52
|
-
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
53
|
-
while (1) {
|
|
54
|
-
switch (_context.prev = _context.next) {
|
|
55
|
-
case 0:
|
|
56
|
-
_ref2 = _args.length > 1 && _args[1] !== undefined ? _args[1] : {}, schemas = _ref2.schemas, _ref2$includeExtensio = _ref2.includeExtensions, includeExtensions = _ref2$includeExtensio === void 0 ? false : _ref2$includeExtensio, _ref2$pgEnableTags = _ref2.pgEnableTags, pgEnableTags = _ref2$pgEnableTags === void 0 ? true : _ref2$pgEnableTags, _ref2$pgThrowOnMissin = _ref2.pgThrowOnMissingSchema, pgThrowOnMissingSchema = _ref2$pgThrowOnMissin === void 0 ? true : _ref2$pgThrowOnMissin;
|
|
57
|
-
_context.next = 3;
|
|
58
|
-
return pgClient.query('show server_version_num;');
|
|
59
|
-
|
|
60
|
-
case 3:
|
|
61
|
-
versionResult = _context.sent;
|
|
62
|
-
serverVersionNum = parseInt(versionResult.rows[0].server_version_num, 10);
|
|
63
|
-
introspectionQuery = (0, _query.makeIntrospectionQuery)(serverVersionNum, {
|
|
64
|
-
pgLegacyFunctionsOnly: false,
|
|
65
|
-
pgIgnoreRBAC: true
|
|
66
|
-
});
|
|
67
|
-
_context.next = 8;
|
|
68
|
-
return pgClient.query(introspectionQuery, [schemas, includeExtensions]);
|
|
69
|
-
|
|
70
|
-
case 8:
|
|
71
|
-
_ref3 = _context.sent;
|
|
72
|
-
rows = _ref3.rows;
|
|
73
|
-
result = {
|
|
74
|
-
__pgVersion: serverVersionNum,
|
|
75
|
-
namespace: [],
|
|
76
|
-
"class": [],
|
|
77
|
-
attribute: [],
|
|
78
|
-
type: [],
|
|
79
|
-
constraint: [],
|
|
80
|
-
procedure: [],
|
|
81
|
-
extension: [],
|
|
82
|
-
index: []
|
|
83
|
-
};
|
|
84
|
-
_iteratorNormalCompletion = true;
|
|
85
|
-
_didIteratorError = false;
|
|
86
|
-
_iteratorError = undefined;
|
|
87
|
-
_context.prev = 14;
|
|
88
|
-
|
|
89
|
-
for (_iterator = rows[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
90
|
-
object = _step.value.object;
|
|
91
|
-
result[object.kind].push(object);
|
|
92
|
-
} // Parse tags from comments
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_context.next = 22;
|
|
96
|
-
break;
|
|
97
|
-
|
|
98
|
-
case 18:
|
|
99
|
-
_context.prev = 18;
|
|
100
|
-
_context.t0 = _context["catch"](14);
|
|
101
|
-
_didIteratorError = true;
|
|
102
|
-
_iteratorError = _context.t0;
|
|
103
|
-
|
|
104
|
-
case 22:
|
|
105
|
-
_context.prev = 22;
|
|
106
|
-
_context.prev = 23;
|
|
107
|
-
|
|
108
|
-
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
|
109
|
-
_iterator["return"]();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
case 25:
|
|
113
|
-
_context.prev = 25;
|
|
114
|
-
|
|
115
|
-
if (!_didIteratorError) {
|
|
116
|
-
_context.next = 28;
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
throw _iteratorError;
|
|
121
|
-
|
|
122
|
-
case 28:
|
|
123
|
-
return _context.finish(25);
|
|
124
|
-
|
|
125
|
-
case 29:
|
|
126
|
-
return _context.finish(22);
|
|
127
|
-
|
|
128
|
-
case 30:
|
|
129
|
-
['namespace', 'class', 'attribute', 'type', 'constraint', 'procedure', 'extension', 'index'].forEach(function (kind) {
|
|
130
|
-
result[kind].forEach(function (object) {
|
|
131
|
-
// Keep a copy of the raw comment
|
|
132
|
-
object.comment = object.description;
|
|
133
|
-
|
|
134
|
-
if (pgEnableTags && object.description) {
|
|
135
|
-
var parsed = (0, _utils.parseTags)(object.description);
|
|
136
|
-
object.tags = parsed.tags;
|
|
137
|
-
object.description = parsed.text;
|
|
138
|
-
} else {
|
|
139
|
-
object.tags = {};
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
extensionConfigurationClassIds = (0, _flatMap["default"])(result.extension, function (e) {
|
|
144
|
-
return e.configurationClassIds;
|
|
145
|
-
});
|
|
146
|
-
result["class"].forEach(function (klass) {
|
|
147
|
-
klass.isExtensionConfigurationTable = extensionConfigurationClassIds.indexOf(klass.id) >= 0;
|
|
148
|
-
});
|
|
149
|
-
['namespace', 'class', 'attribute', 'type', 'constraint', 'procedure', 'extension', 'index'].forEach(function (k) {
|
|
150
|
-
result[k].forEach(Object.freeze);
|
|
151
|
-
});
|
|
152
|
-
knownSchemas = result.namespace.map(function (n) {
|
|
153
|
-
return n.name;
|
|
154
|
-
});
|
|
155
|
-
missingSchemas = schemas.filter(function (s) {
|
|
156
|
-
return knownSchemas.indexOf(s) < 0;
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
if (!missingSchemas.length) {
|
|
160
|
-
_context.next = 43;
|
|
161
|
-
break;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
errorMessage = "You requested to use schema '".concat(schemas.join("', '"), "'; however we couldn't find some of those! Missing schemas are: '").concat(missingSchemas.join("', '"), "'");
|
|
165
|
-
|
|
166
|
-
if (!pgThrowOnMissingSchema) {
|
|
167
|
-
_context.next = 42;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
throw new Error(errorMessage);
|
|
172
|
-
|
|
173
|
-
case 42:
|
|
174
|
-
console.warn('⚠️ WARNING⚠️ ' + errorMessage); // eslint-disable-line no-console
|
|
175
|
-
|
|
176
|
-
case 43:
|
|
177
|
-
return _context.abrupt("return", Object.freeze(result));
|
|
178
|
-
|
|
179
|
-
case 44:
|
|
180
|
-
case "end":
|
|
181
|
-
return _context.stop();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
}, _callee, null, [[14, 18, 22, 30], [23,, 25, 29]]);
|
|
185
|
-
}));
|
|
186
|
-
|
|
187
|
-
return function introspect(_x) {
|
|
188
|
-
return _ref.apply(this, arguments);
|
|
189
|
-
};
|
|
190
|
-
}(); // export const processIntrospection = async (pgClient, introspectionResultsByKind) => {
|
|
191
|
-
// }
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
exports.introspect = introspect;
|
package/main/introspectGql.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.IntrospectionQuery = void 0;
|
|
9
|
-
|
|
10
|
-
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
|
-
|
|
12
|
-
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
|
|
13
|
-
|
|
14
|
-
function _templateObject() {
|
|
15
|
-
var data = (0, _taggedTemplateLiteral2["default"])(["\n query IntrospectionQuery {\n __schema {\n queryType {\n name\n }\n mutationType {\n name\n }\n subscriptionType {\n name\n }\n types {\n ...FullType\n }\n directives {\n name\n description\n locations\n args {\n ...InputValue\n }\n }\n }\n }\n fragment FullType on __Type {\n kind\n name\n description\n fields(includeDeprecated: true) {\n name\n description\n args {\n ...InputValue\n }\n type {\n ...TypeRef\n }\n isDeprecated\n deprecationReason\n }\n inputFields {\n ...InputValue\n }\n interfaces {\n ...TypeRef\n }\n enumValues(includeDeprecated: true) {\n name\n description\n isDeprecated\n deprecationReason\n }\n possibleTypes {\n ...TypeRef\n }\n }\n fragment InputValue on __InputValue {\n name\n description\n type {\n ...TypeRef\n }\n defaultValue\n }\n fragment TypeRef on __Type {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n ofType {\n kind\n name\n }\n }\n }\n }\n }\n }\n }\n }\n"]);
|
|
16
|
-
|
|
17
|
-
_templateObject = function _templateObject() {
|
|
18
|
-
return data;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
return data;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
var IntrospectionQuery = (0, _graphqlTag["default"])(_templateObject());
|
|
25
|
-
exports.IntrospectionQuery = IntrospectionQuery;
|