@graphql-tools/merge 6.2.17 → 8.0.1
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/es5/index.d.ts +0 -1
- package/es5/index.js +7 -525
- package/es5/index.mjs +6 -517
- package/es5/package.json +2 -3
- package/es5/typedefs-mergers/index.d.ts +0 -1
- package/es5/typedefs-mergers/merge-nodes.d.ts +2 -4
- package/index.d.ts +0 -1
- package/index.js +13 -355
- package/index.mjs +11 -346
- package/package.json +2 -3
- package/typedefs-mergers/index.d.ts +0 -1
- package/typedefs-mergers/merge-nodes.d.ts +2 -4
- package/es5/merge-schemas.d.ts +0 -34
- package/es5/typedefs-mergers/comments.d.ts +0 -11
- package/merge-schemas.d.ts +0 -34
- package/typedefs-mergers/comments.d.ts +0 -11
package/es5/index.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { __values, __read, __spreadArray, __assign
|
|
2
|
-
import { mergeDeep, isSome, compareNodes, isNotEqual,
|
|
3
|
-
import {
|
|
4
|
-
import { addResolversToSchema } from '@graphql-tools/schema/es5';
|
|
1
|
+
import { __values, __read, __spreadArray, __assign } from 'tslib';
|
|
2
|
+
import { mergeDeep, isSome, compareNodes, isNotEqual, collectComment, resetComments, printWithComments, getDocumentNodeFromSchema, isDocumentNode } from '@graphql-tools/utils/es5';
|
|
3
|
+
import { print, Source, Kind, isSchema, parse, isDefinitionNode, isScalarType, isSpecifiedScalarType, isIntrospectionType, isObjectType, isInterfaceType, isInputObjectType, isUnionType, isEnumType } from 'graphql';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Deep merges multiple resolver definition objects into a single definition.
|
|
@@ -104,432 +103,6 @@ function deduplicateArguments(args) {
|
|
|
104
103
|
}, []);
|
|
105
104
|
}
|
|
106
105
|
|
|
107
|
-
var MAX_LINE_LENGTH = 80;
|
|
108
|
-
var commentsRegistry = {};
|
|
109
|
-
function resetComments() {
|
|
110
|
-
commentsRegistry = {};
|
|
111
|
-
}
|
|
112
|
-
function collectComment(node) {
|
|
113
|
-
var e_1, _a, e_2, _b, e_3, _c;
|
|
114
|
-
var _d;
|
|
115
|
-
var entityName = (_d = node.name) === null || _d === void 0 ? void 0 : _d.value;
|
|
116
|
-
if (entityName == null) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
pushComment(node, entityName);
|
|
120
|
-
switch (node.kind) {
|
|
121
|
-
case 'EnumTypeDefinition':
|
|
122
|
-
if (node.values) {
|
|
123
|
-
try {
|
|
124
|
-
for (var _e = __values(node.values), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
125
|
-
var value = _f.value;
|
|
126
|
-
pushComment(value, entityName, value.name.value);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
130
|
-
finally {
|
|
131
|
-
try {
|
|
132
|
-
if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
|
|
133
|
-
}
|
|
134
|
-
finally { if (e_1) throw e_1.error; }
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
break;
|
|
138
|
-
case 'ObjectTypeDefinition':
|
|
139
|
-
case 'InputObjectTypeDefinition':
|
|
140
|
-
case 'InterfaceTypeDefinition':
|
|
141
|
-
if (node.fields) {
|
|
142
|
-
try {
|
|
143
|
-
for (var _g = __values(node.fields), _h = _g.next(); !_h.done; _h = _g.next()) {
|
|
144
|
-
var field = _h.value;
|
|
145
|
-
pushComment(field, entityName, field.name.value);
|
|
146
|
-
if (isFieldDefinitionNode(field) && field.arguments) {
|
|
147
|
-
try {
|
|
148
|
-
for (var _j = (e_3 = void 0, __values(field.arguments)), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
149
|
-
var arg = _k.value;
|
|
150
|
-
pushComment(arg, entityName, field.name.value, arg.name.value);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
154
|
-
finally {
|
|
155
|
-
try {
|
|
156
|
-
if (_k && !_k.done && (_c = _j.return)) _c.call(_j);
|
|
157
|
-
}
|
|
158
|
-
finally { if (e_3) throw e_3.error; }
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
164
|
-
finally {
|
|
165
|
-
try {
|
|
166
|
-
if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
|
|
167
|
-
}
|
|
168
|
-
finally { if (e_2) throw e_2.error; }
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
function pushComment(node, entity, field, argument) {
|
|
175
|
-
var comment = getDescription(node, { commentDescriptions: true });
|
|
176
|
-
if (typeof comment !== 'string' || comment.length === 0) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
var keys = [entity];
|
|
180
|
-
if (field) {
|
|
181
|
-
keys.push(field);
|
|
182
|
-
if (argument) {
|
|
183
|
-
keys.push(argument);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
var path = keys.join('.');
|
|
187
|
-
if (!commentsRegistry[path]) {
|
|
188
|
-
commentsRegistry[path] = [];
|
|
189
|
-
}
|
|
190
|
-
commentsRegistry[path].push(comment);
|
|
191
|
-
}
|
|
192
|
-
function printComment(comment) {
|
|
193
|
-
return '\n# ' + comment.replace(/\n/g, '\n# ');
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Copyright (c) 2015-present, Facebook, Inc.
|
|
197
|
-
*
|
|
198
|
-
* This source code is licensed under the MIT license found in the
|
|
199
|
-
* LICENSE file in the root directory of this source tree.
|
|
200
|
-
*/
|
|
201
|
-
/**
|
|
202
|
-
* NOTE: ==> This file has been modified just to add comments to the printed AST
|
|
203
|
-
* This is a temp measure, we will move to using the original non modified printer.js ASAP.
|
|
204
|
-
*/
|
|
205
|
-
// import { visit, VisitFn } from 'graphql';
|
|
206
|
-
/**
|
|
207
|
-
* Given maybeArray, print an empty string if it is null or empty, otherwise
|
|
208
|
-
* print all items together separated by separator if provided
|
|
209
|
-
*/
|
|
210
|
-
function join(maybeArray, separator) {
|
|
211
|
-
return maybeArray ? maybeArray.filter(function (x) { return x; }).join(separator || '') : '';
|
|
212
|
-
}
|
|
213
|
-
function hasMultilineItems(maybeArray) {
|
|
214
|
-
var _a;
|
|
215
|
-
return (_a = maybeArray === null || maybeArray === void 0 ? void 0 : maybeArray.some(function (str) { return str.includes('\n'); })) !== null && _a !== void 0 ? _a : false;
|
|
216
|
-
}
|
|
217
|
-
function addDescription(cb) {
|
|
218
|
-
return function (node, _key, _parent, path, ancestors) {
|
|
219
|
-
var _a;
|
|
220
|
-
var keys = [];
|
|
221
|
-
var parent = path.reduce(function (prev, key) {
|
|
222
|
-
if (['fields', 'arguments', 'values'].includes(key) && prev.name) {
|
|
223
|
-
keys.push(prev.name.value);
|
|
224
|
-
}
|
|
225
|
-
return prev[key];
|
|
226
|
-
}, ancestors[0]);
|
|
227
|
-
var key = __spreadArray(__spreadArray([], __read(keys)), [(_a = parent === null || parent === void 0 ? void 0 : parent.name) === null || _a === void 0 ? void 0 : _a.value]).filter(Boolean).join('.');
|
|
228
|
-
var items = [];
|
|
229
|
-
if (node.kind.includes('Definition') && commentsRegistry[key]) {
|
|
230
|
-
items.push.apply(items, __spreadArray([], __read(commentsRegistry[key])));
|
|
231
|
-
}
|
|
232
|
-
return join(__spreadArray(__spreadArray([], __read(items.map(printComment))), [node.description, cb(node)]), '\n');
|
|
233
|
-
};
|
|
234
|
-
}
|
|
235
|
-
function indent(maybeString) {
|
|
236
|
-
return maybeString && " " + maybeString.replace(/\n/g, '\n ');
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Given array, print each item on its own line, wrapped in an
|
|
240
|
-
* indented "{ }" block.
|
|
241
|
-
*/
|
|
242
|
-
function block(array) {
|
|
243
|
-
return array && array.length !== 0 ? "{\n" + indent(join(array, '\n')) + "\n}" : '';
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* If maybeString is not null or empty, then wrap with start and end, otherwise
|
|
247
|
-
* print an empty string.
|
|
248
|
-
*/
|
|
249
|
-
function wrap(start, maybeString, end) {
|
|
250
|
-
return maybeString ? start + maybeString + (end || '') : '';
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Print a block string in the indented block form by adding a leading and
|
|
254
|
-
* trailing blank line. However, if a block string starts with whitespace and is
|
|
255
|
-
* a single-line, adding a leading blank line would strip that whitespace.
|
|
256
|
-
*/
|
|
257
|
-
function printBlockString(value, isDescription) {
|
|
258
|
-
if (isDescription === void 0) { isDescription = false; }
|
|
259
|
-
var escaped = value.replace(/"""/g, '\\"""');
|
|
260
|
-
return (value[0] === ' ' || value[0] === '\t') && value.indexOf('\n') === -1
|
|
261
|
-
? "\"\"\"" + escaped.replace(/"$/, '"\n') + "\"\"\""
|
|
262
|
-
: "\"\"\"\n" + (isDescription ? escaped : indent(escaped)) + "\n\"\"\"";
|
|
263
|
-
}
|
|
264
|
-
var printDocASTReducer = {
|
|
265
|
-
Name: { leave: function (node) { return node.value; } },
|
|
266
|
-
Variable: { leave: function (node) { return '$' + node.name; } },
|
|
267
|
-
// Document
|
|
268
|
-
Document: {
|
|
269
|
-
leave: function (node) { return join(node.definitions, '\n\n'); },
|
|
270
|
-
},
|
|
271
|
-
OperationDefinition: {
|
|
272
|
-
leave: function (node) {
|
|
273
|
-
var varDefs = wrap('(', join(node.variableDefinitions, ', '), ')');
|
|
274
|
-
var prefix = join([node.operation, join([node.name, varDefs]), join(node.directives, ' ')], ' ');
|
|
275
|
-
// the query short form.
|
|
276
|
-
return prefix + ' ' + node.selectionSet;
|
|
277
|
-
},
|
|
278
|
-
},
|
|
279
|
-
VariableDefinition: {
|
|
280
|
-
leave: function (_a) {
|
|
281
|
-
var variable = _a.variable, type = _a.type, defaultValue = _a.defaultValue, directives = _a.directives;
|
|
282
|
-
return variable + ': ' + type + wrap(' = ', defaultValue) + wrap(' ', join(directives, ' '));
|
|
283
|
-
},
|
|
284
|
-
},
|
|
285
|
-
SelectionSet: { leave: function (_a) {
|
|
286
|
-
var selections = _a.selections;
|
|
287
|
-
return block(selections);
|
|
288
|
-
} },
|
|
289
|
-
Field: {
|
|
290
|
-
leave: function (_a) {
|
|
291
|
-
var alias = _a.alias, name = _a.name, args = _a.arguments, directives = _a.directives, selectionSet = _a.selectionSet;
|
|
292
|
-
var prefix = wrap('', alias, ': ') + name;
|
|
293
|
-
var argsLine = prefix + wrap('(', join(args, ', '), ')');
|
|
294
|
-
if (argsLine.length > MAX_LINE_LENGTH) {
|
|
295
|
-
argsLine = prefix + wrap('(\n', indent(join(args, '\n')), '\n)');
|
|
296
|
-
}
|
|
297
|
-
return join([argsLine, join(directives, ' '), selectionSet], ' ');
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
Argument: { leave: function (_a) {
|
|
301
|
-
var name = _a.name, value = _a.value;
|
|
302
|
-
return name + ': ' + value;
|
|
303
|
-
} },
|
|
304
|
-
// Fragments
|
|
305
|
-
FragmentSpread: {
|
|
306
|
-
leave: function (_a) {
|
|
307
|
-
var name = _a.name, directives = _a.directives;
|
|
308
|
-
return '...' + name + wrap(' ', join(directives, ' '));
|
|
309
|
-
},
|
|
310
|
-
},
|
|
311
|
-
InlineFragment: {
|
|
312
|
-
leave: function (_a) {
|
|
313
|
-
var typeCondition = _a.typeCondition, directives = _a.directives, selectionSet = _a.selectionSet;
|
|
314
|
-
return join(['...', wrap('on ', typeCondition), join(directives, ' '), selectionSet], ' ');
|
|
315
|
-
},
|
|
316
|
-
},
|
|
317
|
-
FragmentDefinition: {
|
|
318
|
-
leave: function (_a) {
|
|
319
|
-
var name = _a.name, typeCondition = _a.typeCondition, variableDefinitions = _a.variableDefinitions, directives = _a.directives, selectionSet = _a.selectionSet;
|
|
320
|
-
// Note: fragment variable definitions are experimental and may be changed
|
|
321
|
-
// or removed in the future.
|
|
322
|
-
return "fragment " + name + wrap('(', join(variableDefinitions, ', '), ')') + " " +
|
|
323
|
-
("on " + typeCondition + " " + wrap('', join(directives, ' '), ' ')) +
|
|
324
|
-
selectionSet;
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
// Value
|
|
328
|
-
IntValue: { leave: function (_a) {
|
|
329
|
-
var value = _a.value;
|
|
330
|
-
return value;
|
|
331
|
-
} },
|
|
332
|
-
FloatValue: { leave: function (_a) {
|
|
333
|
-
var value = _a.value;
|
|
334
|
-
return value;
|
|
335
|
-
} },
|
|
336
|
-
StringValue: {
|
|
337
|
-
leave: function (_a) {
|
|
338
|
-
var value = _a.value, isBlockString = _a.block;
|
|
339
|
-
return (isBlockString ? printBlockString(value) : JSON.stringify(value));
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
BooleanValue: { leave: function (_a) {
|
|
343
|
-
var value = _a.value;
|
|
344
|
-
return (value ? 'true' : 'false');
|
|
345
|
-
} },
|
|
346
|
-
NullValue: { leave: function () { return 'null'; } },
|
|
347
|
-
EnumValue: { leave: function (_a) {
|
|
348
|
-
var value = _a.value;
|
|
349
|
-
return value;
|
|
350
|
-
} },
|
|
351
|
-
ListValue: { leave: function (_a) {
|
|
352
|
-
var values = _a.values;
|
|
353
|
-
return '[' + join(values, ', ') + ']';
|
|
354
|
-
} },
|
|
355
|
-
ObjectValue: { leave: function (_a) {
|
|
356
|
-
var fields = _a.fields;
|
|
357
|
-
return '{' + join(fields, ', ') + '}';
|
|
358
|
-
} },
|
|
359
|
-
ObjectField: { leave: function (_a) {
|
|
360
|
-
var name = _a.name, value = _a.value;
|
|
361
|
-
return name + ': ' + value;
|
|
362
|
-
} },
|
|
363
|
-
// Directive
|
|
364
|
-
Directive: {
|
|
365
|
-
leave: function (_a) {
|
|
366
|
-
var name = _a.name, args = _a.arguments;
|
|
367
|
-
return '@' + name + wrap('(', join(args, ', '), ')');
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
// Type
|
|
371
|
-
NamedType: { leave: function (_a) {
|
|
372
|
-
var name = _a.name;
|
|
373
|
-
return name;
|
|
374
|
-
} },
|
|
375
|
-
ListType: { leave: function (_a) {
|
|
376
|
-
var type = _a.type;
|
|
377
|
-
return '[' + type + ']';
|
|
378
|
-
} },
|
|
379
|
-
NonNullType: { leave: function (_a) {
|
|
380
|
-
var type = _a.type;
|
|
381
|
-
return type + '!';
|
|
382
|
-
} },
|
|
383
|
-
// Type System Definitions
|
|
384
|
-
SchemaDefinition: {
|
|
385
|
-
leave: function (_a) {
|
|
386
|
-
var description = _a.description, directives = _a.directives, operationTypes = _a.operationTypes;
|
|
387
|
-
return wrap('', description, '\n') + join(['schema', join(directives, ' '), block(operationTypes)], ' ');
|
|
388
|
-
},
|
|
389
|
-
},
|
|
390
|
-
OperationTypeDefinition: {
|
|
391
|
-
leave: function (_a) {
|
|
392
|
-
var operation = _a.operation, type = _a.type;
|
|
393
|
-
return operation + ': ' + type;
|
|
394
|
-
},
|
|
395
|
-
},
|
|
396
|
-
ScalarTypeDefinition: {
|
|
397
|
-
leave: function (_a) {
|
|
398
|
-
var description = _a.description, name = _a.name, directives = _a.directives;
|
|
399
|
-
return wrap('', description, '\n') + join(['scalar', name, join(directives, ' ')], ' ');
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
ObjectTypeDefinition: {
|
|
403
|
-
leave: function (_a) {
|
|
404
|
-
var description = _a.description, name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
|
|
405
|
-
return wrap('', description, '\n') +
|
|
406
|
-
join(['type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
|
407
|
-
},
|
|
408
|
-
},
|
|
409
|
-
FieldDefinition: {
|
|
410
|
-
leave: function (_a) {
|
|
411
|
-
var description = _a.description, name = _a.name, args = _a.arguments, type = _a.type, directives = _a.directives;
|
|
412
|
-
return wrap('', description, '\n') +
|
|
413
|
-
name +
|
|
414
|
-
(hasMultilineItems(args)
|
|
415
|
-
? wrap('(\n', indent(join(args, '\n')), '\n)')
|
|
416
|
-
: wrap('(', join(args, ', '), ')')) +
|
|
417
|
-
': ' +
|
|
418
|
-
type +
|
|
419
|
-
wrap(' ', join(directives, ' '));
|
|
420
|
-
},
|
|
421
|
-
},
|
|
422
|
-
InputValueDefinition: {
|
|
423
|
-
leave: function (_a) {
|
|
424
|
-
var description = _a.description, name = _a.name, type = _a.type, defaultValue = _a.defaultValue, directives = _a.directives;
|
|
425
|
-
return wrap('', description, '\n') + join([name + ': ' + type, wrap('= ', defaultValue), join(directives, ' ')], ' ');
|
|
426
|
-
},
|
|
427
|
-
},
|
|
428
|
-
InterfaceTypeDefinition: {
|
|
429
|
-
leave: function (_a) {
|
|
430
|
-
var description = _a.description, name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
|
|
431
|
-
return wrap('', description, '\n') +
|
|
432
|
-
join(['interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
|
433
|
-
},
|
|
434
|
-
},
|
|
435
|
-
UnionTypeDefinition: {
|
|
436
|
-
leave: function (_a) {
|
|
437
|
-
var description = _a.description, name = _a.name, directives = _a.directives, types = _a.types;
|
|
438
|
-
return wrap('', description, '\n') + join(['union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' ');
|
|
439
|
-
},
|
|
440
|
-
},
|
|
441
|
-
EnumTypeDefinition: {
|
|
442
|
-
leave: function (_a) {
|
|
443
|
-
var description = _a.description, name = _a.name, directives = _a.directives, values = _a.values;
|
|
444
|
-
return wrap('', description, '\n') + join(['enum', name, join(directives, ' '), block(values)], ' ');
|
|
445
|
-
},
|
|
446
|
-
},
|
|
447
|
-
EnumValueDefinition: {
|
|
448
|
-
leave: function (_a) {
|
|
449
|
-
var description = _a.description, name = _a.name, directives = _a.directives;
|
|
450
|
-
return wrap('', description, '\n') + join([name, join(directives, ' ')], ' ');
|
|
451
|
-
},
|
|
452
|
-
},
|
|
453
|
-
InputObjectTypeDefinition: {
|
|
454
|
-
leave: function (_a) {
|
|
455
|
-
var description = _a.description, name = _a.name, directives = _a.directives, fields = _a.fields;
|
|
456
|
-
return wrap('', description, '\n') + join(['input', name, join(directives, ' '), block(fields)], ' ');
|
|
457
|
-
},
|
|
458
|
-
},
|
|
459
|
-
DirectiveDefinition: {
|
|
460
|
-
leave: function (_a) {
|
|
461
|
-
var description = _a.description, name = _a.name, args = _a.arguments, repeatable = _a.repeatable, locations = _a.locations;
|
|
462
|
-
return wrap('', description, '\n') +
|
|
463
|
-
'directive @' +
|
|
464
|
-
name +
|
|
465
|
-
(hasMultilineItems(args)
|
|
466
|
-
? wrap('(\n', indent(join(args, '\n')), '\n)')
|
|
467
|
-
: wrap('(', join(args, ', '), ')')) +
|
|
468
|
-
(repeatable ? ' repeatable' : '') +
|
|
469
|
-
' on ' +
|
|
470
|
-
join(locations, ' | ');
|
|
471
|
-
},
|
|
472
|
-
},
|
|
473
|
-
SchemaExtension: {
|
|
474
|
-
leave: function (_a) {
|
|
475
|
-
var directives = _a.directives, operationTypes = _a.operationTypes;
|
|
476
|
-
return join(['extend schema', join(directives, ' '), block(operationTypes)], ' ');
|
|
477
|
-
},
|
|
478
|
-
},
|
|
479
|
-
ScalarTypeExtension: {
|
|
480
|
-
leave: function (_a) {
|
|
481
|
-
var name = _a.name, directives = _a.directives;
|
|
482
|
-
return join(['extend scalar', name, join(directives, ' ')], ' ');
|
|
483
|
-
},
|
|
484
|
-
},
|
|
485
|
-
ObjectTypeExtension: {
|
|
486
|
-
leave: function (_a) {
|
|
487
|
-
var name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
|
|
488
|
-
return join(['extend type', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
|
489
|
-
},
|
|
490
|
-
},
|
|
491
|
-
InterfaceTypeExtension: {
|
|
492
|
-
leave: function (_a) {
|
|
493
|
-
var name = _a.name, interfaces = _a.interfaces, directives = _a.directives, fields = _a.fields;
|
|
494
|
-
return join(['extend interface', name, wrap('implements ', join(interfaces, ' & ')), join(directives, ' '), block(fields)], ' ');
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
UnionTypeExtension: {
|
|
498
|
-
leave: function (_a) {
|
|
499
|
-
var name = _a.name, directives = _a.directives, types = _a.types;
|
|
500
|
-
return join(['extend union', name, join(directives, ' '), wrap('= ', join(types, ' | '))], ' ');
|
|
501
|
-
},
|
|
502
|
-
},
|
|
503
|
-
EnumTypeExtension: {
|
|
504
|
-
leave: function (_a) {
|
|
505
|
-
var name = _a.name, directives = _a.directives, values = _a.values;
|
|
506
|
-
return join(['extend enum', name, join(directives, ' '), block(values)], ' ');
|
|
507
|
-
},
|
|
508
|
-
},
|
|
509
|
-
InputObjectTypeExtension: {
|
|
510
|
-
leave: function (_a) {
|
|
511
|
-
var name = _a.name, directives = _a.directives, fields = _a.fields;
|
|
512
|
-
return join(['extend input', name, join(directives, ' '), block(fields)], ' ');
|
|
513
|
-
},
|
|
514
|
-
},
|
|
515
|
-
};
|
|
516
|
-
var printDocASTReducerWithComments = Object.keys(printDocASTReducer).reduce(function (prev, key) {
|
|
517
|
-
var _a;
|
|
518
|
-
return (__assign(__assign({}, prev), (_a = {}, _a[key] = {
|
|
519
|
-
leave: addDescription(printDocASTReducer[key].leave),
|
|
520
|
-
}, _a)));
|
|
521
|
-
}, {});
|
|
522
|
-
/**
|
|
523
|
-
* Converts an AST into a string, using one set of reasonable
|
|
524
|
-
* formatting rules.
|
|
525
|
-
*/
|
|
526
|
-
function printWithComments(ast) {
|
|
527
|
-
return visit(ast, printDocASTReducerWithComments);
|
|
528
|
-
}
|
|
529
|
-
function isFieldDefinitionNode(node) {
|
|
530
|
-
return node.kind === 'FieldDefinition';
|
|
531
|
-
}
|
|
532
|
-
|
|
533
106
|
function directiveAlreadyExists(directivesArr, otherDirective) {
|
|
534
107
|
return !!directivesArr.find(function (directive) { return directive.name.value === otherDirective.name.value; });
|
|
535
108
|
}
|
|
@@ -625,8 +198,8 @@ function mergeDirectives(d1, d2, config) {
|
|
|
625
198
|
return result;
|
|
626
199
|
}
|
|
627
200
|
function validateInputs(node, existingNode) {
|
|
628
|
-
var printedNode = print(node);
|
|
629
|
-
var printedExistingNode = print(existingNode);
|
|
201
|
+
var printedNode = print(__assign(__assign({}, node), { description: undefined }));
|
|
202
|
+
var printedExistingNode = print(__assign(__assign({}, existingNode), { description: undefined }));
|
|
630
203
|
// eslint-disable-next-line
|
|
631
204
|
var leaveInputs = new RegExp('(directive @w*d*)|( on .*$)', 'g');
|
|
632
205
|
var sameArguments = printedNode.replace(leaveInputs, '') === printedExistingNode.replace(leaveInputs, '');
|
|
@@ -1480,88 +1053,4 @@ function extractExtensionsFromSchema(schema) {
|
|
|
1480
1053
|
return result;
|
|
1481
1054
|
}
|
|
1482
1055
|
|
|
1483
|
-
|
|
1484
|
-
requireResolversForArgs: 'ignore',
|
|
1485
|
-
requireResolversForNonScalar: 'ignore',
|
|
1486
|
-
requireResolversForAllFields: 'ignore',
|
|
1487
|
-
requireResolversForResolveType: 'ignore',
|
|
1488
|
-
requireResolversToMatchSchema: 'ignore',
|
|
1489
|
-
};
|
|
1490
|
-
/**
|
|
1491
|
-
* Synchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema.
|
|
1492
|
-
* @param config Configuration object
|
|
1493
|
-
*/
|
|
1494
|
-
function mergeSchemas(config) {
|
|
1495
|
-
var e_1, _a;
|
|
1496
|
-
var typeDefs = mergeTypeDefs([config.schemas, config.typeDefs || []], config);
|
|
1497
|
-
var extractedResolvers = [];
|
|
1498
|
-
var extractedExtensions = [];
|
|
1499
|
-
try {
|
|
1500
|
-
for (var _b = __values(config.schemas), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
1501
|
-
var schema = _c.value;
|
|
1502
|
-
extractedResolvers.push(getResolversFromSchema(schema));
|
|
1503
|
-
extractedExtensions.push(extractExtensionsFromSchema(schema));
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1507
|
-
finally {
|
|
1508
|
-
try {
|
|
1509
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
1510
|
-
}
|
|
1511
|
-
finally { if (e_1) throw e_1.error; }
|
|
1512
|
-
}
|
|
1513
|
-
extractedResolvers.push.apply(extractedResolvers, __spreadArray([], __read(ensureResolvers(config))));
|
|
1514
|
-
var resolvers = mergeResolvers(extractedResolvers, config);
|
|
1515
|
-
var extensions = mergeExtensions(extractedExtensions);
|
|
1516
|
-
return makeSchema({ resolvers: resolvers, typeDefs: typeDefs, extensions: extensions }, config);
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Asynchronously merges multiple schemas, typeDefinitions and/or resolvers into a single schema.
|
|
1520
|
-
* @param config Configuration object
|
|
1521
|
-
*/
|
|
1522
|
-
function mergeSchemasAsync(config) {
|
|
1523
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1524
|
-
var _a, typeDefs, resolvers, extensions;
|
|
1525
|
-
var _this = this;
|
|
1526
|
-
return __generator(this, function (_b) {
|
|
1527
|
-
switch (_b.label) {
|
|
1528
|
-
case 0: return [4 /*yield*/, Promise.all([
|
|
1529
|
-
mergeTypeDefs([config.schemas, config.typeDefs || []], config),
|
|
1530
|
-
Promise.all(config.schemas.map(function (schema) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1531
|
-
return [2 /*return*/, getResolversFromSchema(schema)];
|
|
1532
|
-
}); }); })).then(function (extractedResolvers) {
|
|
1533
|
-
return mergeResolvers(__spreadArray(__spreadArray([], __read(extractedResolvers)), __read(ensureResolvers(config))), config);
|
|
1534
|
-
}),
|
|
1535
|
-
Promise.all(config.schemas.map(function (schema) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1536
|
-
return [2 /*return*/, extractExtensionsFromSchema(schema)];
|
|
1537
|
-
}); }); })).then(function (extractedExtensions) {
|
|
1538
|
-
return mergeExtensions(extractedExtensions);
|
|
1539
|
-
}),
|
|
1540
|
-
])];
|
|
1541
|
-
case 1:
|
|
1542
|
-
_a = __read.apply(void 0, [_b.sent(), 3]), typeDefs = _a[0], resolvers = _a[1], extensions = _a[2];
|
|
1543
|
-
return [2 /*return*/, makeSchema({ resolvers: resolvers, typeDefs: typeDefs, extensions: extensions }, config)];
|
|
1544
|
-
}
|
|
1545
|
-
});
|
|
1546
|
-
});
|
|
1547
|
-
}
|
|
1548
|
-
function ensureResolvers(config) {
|
|
1549
|
-
return config.resolvers ? asArray(config.resolvers) : [];
|
|
1550
|
-
}
|
|
1551
|
-
function makeSchema(_a, config) {
|
|
1552
|
-
var resolvers = _a.resolvers, typeDefs = _a.typeDefs, extensions = _a.extensions;
|
|
1553
|
-
var schema = typeof typeDefs === 'string' ? buildSchema(typeDefs, config) : buildASTSchema(typeDefs, config);
|
|
1554
|
-
// add resolvers
|
|
1555
|
-
if (resolvers) {
|
|
1556
|
-
schema = addResolversToSchema({
|
|
1557
|
-
schema: schema,
|
|
1558
|
-
resolvers: resolvers,
|
|
1559
|
-
resolverValidationOptions: __assign(__assign({}, defaultResolverValidationOptions), (config.resolverValidationOptions || {})),
|
|
1560
|
-
});
|
|
1561
|
-
}
|
|
1562
|
-
// extensions
|
|
1563
|
-
applyExtensions(schema, extensions);
|
|
1564
|
-
return schema;
|
|
1565
|
-
}
|
|
1566
|
-
|
|
1567
|
-
export { CompareVal, applyExtensions, collectComment, defaultStringComparator, extractExtensionsFromSchema, extractType, isListTypeNode, isNamedDefinitionNode, isNonNullTypeNode, isSourceTypes, isStringTypes, isWrappingTypeNode, mergeArguments, mergeDirective, mergeDirectives, mergeEnum, mergeEnumValues, mergeExtensions, mergeFields, mergeGraphQLNodes, mergeGraphQLTypes, mergeInputType, mergeInterface, mergeNamedTypeArray, mergeResolvers, mergeScalar, mergeSchemas, mergeSchemasAsync, mergeType, mergeTypeDefs, mergeUnion, printComment, printTypeNode, printWithComments, pushComment, resetComments, schemaDefSymbol, travelSchemaPossibleExtensions };
|
|
1056
|
+
export { CompareVal, applyExtensions, defaultStringComparator, extractExtensionsFromSchema, extractType, isListTypeNode, isNamedDefinitionNode, isNonNullTypeNode, isSourceTypes, isStringTypes, isWrappingTypeNode, mergeArguments, mergeDirective, mergeDirectives, mergeEnum, mergeEnumValues, mergeExtensions, mergeFields, mergeGraphQLNodes, mergeGraphQLTypes, mergeInputType, mergeInterface, mergeNamedTypeArray, mergeResolvers, mergeScalar, mergeType, mergeTypeDefs, mergeUnion, printTypeNode, schemaDefSymbol, travelSchemaPossibleExtensions };
|
package/es5/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/merge/es5",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "A set of utils for faster development of GraphQL tools",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-tools/
|
|
11
|
-
"@graphql-tools/utils": "8.0.2",
|
|
10
|
+
"@graphql-tools/utils": "8.1.1",
|
|
12
11
|
"tslib": "~2.3.0"
|
|
13
12
|
},
|
|
14
13
|
"repository": {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Config } from './merge-typedefs';
|
|
2
|
-
import { DefinitionNode,
|
|
2
|
+
import { DefinitionNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
|
|
3
|
+
import { NamedDefinitionNode } from '@graphql-tools/utils';
|
|
3
4
|
export declare const schemaDefSymbol = "SCHEMA_DEF_SYMBOL";
|
|
4
5
|
export declare type MergedResultMap = Record<string, NamedDefinitionNode> & {
|
|
5
6
|
[schemaDefSymbol]: SchemaDefinitionNode | SchemaExtensionNode;
|
|
6
7
|
};
|
|
7
|
-
export declare type NamedDefinitionNode = DefinitionNode & {
|
|
8
|
-
name?: NameNode;
|
|
9
|
-
};
|
|
10
8
|
export declare function isNamedDefinitionNode(definitionNode: DefinitionNode): definitionNode is NamedDefinitionNode;
|
|
11
9
|
export declare function mergeGraphQLNodes(nodes: ReadonlyArray<DefinitionNode>, config?: Config): MergedResultMap;
|
package/index.d.ts
CHANGED