@graphql-tools/merge 6.2.9-alpha-3e5e5d87.0 → 6.2.11
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.cjs.js +225 -161
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.esm.js +227 -151
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +3 -3
- package/es5/typedefs-mergers/comments.d.ts +4 -5
- package/es5/typedefs-mergers/fields.d.ts +1 -1
- package/es5/typedefs-mergers/merge-nodes.d.ts +8 -3
- package/es5/typedefs-mergers/merge-typedefs.d.ts +2 -1
- package/es5/typedefs-mergers/schema-def.d.ts +8 -0
- package/es5/typedefs-mergers/utils.d.ts +8 -15
- package/index.cjs.js +185 -144
- package/index.cjs.js.map +1 -1
- package/index.esm.js +186 -133
- package/index.esm.js.map +1 -1
- package/package.json +3 -3
- package/typedefs-mergers/comments.d.ts +4 -5
- package/typedefs-mergers/fields.d.ts +1 -1
- package/typedefs-mergers/merge-nodes.d.ts +8 -3
- package/typedefs-mergers/merge-typedefs.d.ts +2 -1
- package/typedefs-mergers/schema-def.d.ts +8 -0
- package/typedefs-mergers/utils.d.ts +8 -15
package/es5/index.cjs.js
CHANGED
|
@@ -78,7 +78,7 @@ function mergeResolvers(resolversDefinitions, options) {
|
|
|
78
78
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
79
79
|
args[_i] = arguments[_i];
|
|
80
80
|
}
|
|
81
|
-
var resultsOfFactories = resolversFactories.map(function (factory) { return factory.apply(void 0, tslib.
|
|
81
|
+
var resultsOfFactories = resolversFactories.map(function (factory) { return factory.apply(void 0, tslib.__spreadArray([], tslib.__read(args))); });
|
|
82
82
|
return resolvers.concat(resultsOfFactories).reduce(utils.mergeDeep, {});
|
|
83
83
|
});
|
|
84
84
|
}
|
|
@@ -203,12 +203,12 @@ function addDescription(cb) {
|
|
|
203
203
|
}
|
|
204
204
|
return prev[key];
|
|
205
205
|
}, ancestors[0]);
|
|
206
|
-
var key = tslib.
|
|
206
|
+
var key = tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(keys)), [parent.name.value]).join('.');
|
|
207
207
|
var items = [];
|
|
208
208
|
if (commentsRegistry[key]) {
|
|
209
|
-
items.push.apply(items, tslib.
|
|
209
|
+
items.push.apply(items, tslib.__spreadArray([], tslib.__read(commentsRegistry[key])));
|
|
210
210
|
}
|
|
211
|
-
return join(tslib.
|
|
211
|
+
return join(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(items.map(printComment))), [node.description, cb(node)]), '\n');
|
|
212
212
|
};
|
|
213
213
|
}
|
|
214
214
|
function indent(maybeString) {
|
|
@@ -411,7 +411,7 @@ function nameAlreadyExists(name, namesArr) {
|
|
|
411
411
|
}
|
|
412
412
|
function mergeArguments$1(a1, a2) {
|
|
413
413
|
var e_1, _a;
|
|
414
|
-
var result = tslib.
|
|
414
|
+
var result = tslib.__spreadArray([], tslib.__read(a2));
|
|
415
415
|
var _loop_1 = function (argument) {
|
|
416
416
|
var existingIndex = result.findIndex(function (a) { return a.name.value === argument.name.value; });
|
|
417
417
|
if (existingIndex > -1) {
|
|
@@ -468,7 +468,7 @@ function mergeDirectives(d1, d2, config) {
|
|
|
468
468
|
var reverseOrder = config && config.reverseDirectives;
|
|
469
469
|
var asNext = reverseOrder ? d1 : d2;
|
|
470
470
|
var asFirst = reverseOrder ? d2 : d1;
|
|
471
|
-
var result = deduplicateDirectives(tslib.
|
|
471
|
+
var result = deduplicateDirectives(tslib.__spreadArray([], tslib.__read(asNext)));
|
|
472
472
|
var _loop_2 = function (directive) {
|
|
473
473
|
if (directiveAlreadyExists(result, directive)) {
|
|
474
474
|
var existingDirectiveIndex = result.findIndex(function (d) { return d.name.value === directive.name.value; });
|
|
@@ -507,7 +507,7 @@ function validateInputs(node, existingNode) {
|
|
|
507
507
|
function mergeDirective(node, existingNode) {
|
|
508
508
|
if (existingNode) {
|
|
509
509
|
validateInputs(node, existingNode);
|
|
510
|
-
return tslib.__assign(tslib.__assign({}, node), { locations: tslib.
|
|
510
|
+
return tslib.__assign(tslib.__assign({}, node), { locations: tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(existingNode.locations)), tslib.__read(node.locations.filter(function (name) { return !nameAlreadyExists(name, existingNode.locations); }))) });
|
|
511
511
|
}
|
|
512
512
|
return node;
|
|
513
513
|
}
|
|
@@ -557,7 +557,7 @@ function mergeEnumValues(first, second, config) {
|
|
|
557
557
|
}
|
|
558
558
|
finally { if (e_2) throw e_2.error; }
|
|
559
559
|
}
|
|
560
|
-
var result = tslib.
|
|
560
|
+
var result = tslib.__spreadArray([], tslib.__read(enumValueMap.values()));
|
|
561
561
|
if (config && config.sort) {
|
|
562
562
|
result.sort(utils.compareNodes);
|
|
563
563
|
}
|
|
@@ -587,55 +587,13 @@ function isStringTypes(types) {
|
|
|
587
587
|
function isSourceTypes(types) {
|
|
588
588
|
return types instanceof graphql.Source;
|
|
589
589
|
}
|
|
590
|
-
function isGraphQLType(definition) {
|
|
591
|
-
return definition.kind === 'ObjectTypeDefinition';
|
|
592
|
-
}
|
|
593
|
-
function isGraphQLTypeExtension(definition) {
|
|
594
|
-
return definition.kind === 'ObjectTypeExtension';
|
|
595
|
-
}
|
|
596
|
-
function isGraphQLEnum(definition) {
|
|
597
|
-
return definition.kind === 'EnumTypeDefinition';
|
|
598
|
-
}
|
|
599
|
-
function isGraphQLEnumExtension(definition) {
|
|
600
|
-
return definition.kind === 'EnumTypeExtension';
|
|
601
|
-
}
|
|
602
|
-
function isGraphQLUnion(definition) {
|
|
603
|
-
return definition.kind === 'UnionTypeDefinition';
|
|
604
|
-
}
|
|
605
|
-
function isGraphQLUnionExtension(definition) {
|
|
606
|
-
return definition.kind === 'UnionTypeExtension';
|
|
607
|
-
}
|
|
608
|
-
function isGraphQLScalar(definition) {
|
|
609
|
-
return definition.kind === 'ScalarTypeDefinition';
|
|
610
|
-
}
|
|
611
|
-
function isGraphQLScalarExtension(definition) {
|
|
612
|
-
return definition.kind === 'ScalarTypeExtension';
|
|
613
|
-
}
|
|
614
|
-
function isGraphQLInputType(definition) {
|
|
615
|
-
return definition.kind === 'InputObjectTypeDefinition';
|
|
616
|
-
}
|
|
617
|
-
function isGraphQLInputTypeExtension(definition) {
|
|
618
|
-
return definition.kind === 'InputObjectTypeExtension';
|
|
619
|
-
}
|
|
620
|
-
function isGraphQLInterface(definition) {
|
|
621
|
-
return definition.kind === 'InterfaceTypeDefinition';
|
|
622
|
-
}
|
|
623
|
-
function isGraphQLInterfaceExtension(definition) {
|
|
624
|
-
return definition.kind === 'InterfaceTypeExtension';
|
|
625
|
-
}
|
|
626
|
-
function isGraphQLDirective(definition) {
|
|
627
|
-
return definition.kind === 'DirectiveDefinition';
|
|
628
|
-
}
|
|
629
590
|
function extractType(type) {
|
|
630
591
|
var visitedType = type;
|
|
631
|
-
while (visitedType.kind ===
|
|
592
|
+
while (visitedType.kind === graphql.Kind.LIST_TYPE || visitedType.kind === 'NonNullType') {
|
|
632
593
|
visitedType = visitedType.type;
|
|
633
594
|
}
|
|
634
595
|
return visitedType;
|
|
635
596
|
}
|
|
636
|
-
function isSchemaDefinition(node) {
|
|
637
|
-
return node.kind === 'SchemaDefinition';
|
|
638
|
-
}
|
|
639
597
|
function isWrappingTypeNode(type) {
|
|
640
598
|
return type.kind !== graphql.Kind.NAMED_TYPE;
|
|
641
599
|
}
|
|
@@ -654,10 +612,22 @@ function printTypeNode(type) {
|
|
|
654
612
|
}
|
|
655
613
|
return type.name.value;
|
|
656
614
|
}
|
|
615
|
+
(function (CompareVal) {
|
|
616
|
+
CompareVal[CompareVal["A_SMALLER_THAN_B"] = -1] = "A_SMALLER_THAN_B";
|
|
617
|
+
CompareVal[CompareVal["A_EQUALS_B"] = 0] = "A_EQUALS_B";
|
|
618
|
+
CompareVal[CompareVal["A_GREATER_THAN_B"] = 1] = "A_GREATER_THAN_B";
|
|
619
|
+
})(exports.CompareVal || (exports.CompareVal = {}));
|
|
620
|
+
function defaultStringComparator(a, b) {
|
|
621
|
+
if (a < b)
|
|
622
|
+
return exports.CompareVal.A_SMALLER_THAN_B;
|
|
623
|
+
if (a > b)
|
|
624
|
+
return exports.CompareVal.A_GREATER_THAN_B;
|
|
625
|
+
return exports.CompareVal.A_EQUALS_B;
|
|
626
|
+
}
|
|
657
627
|
|
|
658
|
-
function fieldAlreadyExists(fieldsArr, otherField) {
|
|
628
|
+
function fieldAlreadyExists(fieldsArr, otherField, config) {
|
|
659
629
|
var result = fieldsArr.find(function (field) { return field.name.value === otherField.name.value; });
|
|
660
|
-
if (result) {
|
|
630
|
+
if (result && !(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
661
631
|
var t1 = extractType(result.type);
|
|
662
632
|
var t2 = extractType(otherField.type);
|
|
663
633
|
if (t1.name.value !== t2.name.value) {
|
|
@@ -668,18 +638,20 @@ function fieldAlreadyExists(fieldsArr, otherField) {
|
|
|
668
638
|
}
|
|
669
639
|
function mergeFields(type, f1, f2, config) {
|
|
670
640
|
var e_1, _a;
|
|
671
|
-
var result = tslib.
|
|
641
|
+
var result = tslib.__spreadArray([], tslib.__read(f2));
|
|
672
642
|
var _loop_1 = function (field) {
|
|
673
|
-
if (fieldAlreadyExists(result, field)) {
|
|
643
|
+
if (fieldAlreadyExists(result, field, config)) {
|
|
674
644
|
var existing = result.find(function (f) { return f.name.value === field.name.value; });
|
|
675
|
-
if (config
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
645
|
+
if (!(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
646
|
+
if (config === null || config === void 0 ? void 0 : config.throwOnConflict) {
|
|
647
|
+
preventConflicts(type, existing, field);
|
|
648
|
+
}
|
|
649
|
+
else {
|
|
650
|
+
preventConflicts(type, existing, field);
|
|
651
|
+
}
|
|
652
|
+
if (isNonNullTypeNode(field.type) && !isNonNullTypeNode(existing.type)) {
|
|
653
|
+
existing.type = field.type;
|
|
654
|
+
}
|
|
683
655
|
}
|
|
684
656
|
existing.arguments = mergeArguments(field['arguments'] || [], existing.arguments || [], config);
|
|
685
657
|
existing.directives = mergeDirectives(field.directives, existing.directives, config);
|
|
@@ -793,7 +765,7 @@ function alreadyExists(arr, other) {
|
|
|
793
765
|
return !!arr.find(function (i) { return i.name.value === other.name.value; });
|
|
794
766
|
}
|
|
795
767
|
function mergeNamedTypeArray(first, second, config) {
|
|
796
|
-
var result = tslib.
|
|
768
|
+
var result = tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(second)), tslib.__read(first.filter(function (d) { return !alreadyExists(second, d); })));
|
|
797
769
|
if (config && config.sort) {
|
|
798
770
|
result.sort(utils.compareNodes);
|
|
799
771
|
}
|
|
@@ -862,43 +834,107 @@ function mergeUnion(first, second, config) {
|
|
|
862
834
|
? tslib.__assign(tslib.__assign({}, first), { kind: 'UnionTypeDefinition' }) : first;
|
|
863
835
|
}
|
|
864
836
|
|
|
837
|
+
var operationTypeDefinitionNodeTypeRootTypeMap = {
|
|
838
|
+
query: 'Query',
|
|
839
|
+
mutation: 'Mutation',
|
|
840
|
+
subscription: 'Subscription',
|
|
841
|
+
};
|
|
842
|
+
function mergeOperationTypes(opNodeList, existingOpNodeList) {
|
|
843
|
+
if (opNodeList === void 0) { opNodeList = []; }
|
|
844
|
+
if (existingOpNodeList === void 0) { existingOpNodeList = []; }
|
|
845
|
+
var finalOpNodeList = [];
|
|
846
|
+
var _loop_1 = function (opNodeType) {
|
|
847
|
+
var opNode = opNodeList.find(function (n) { return n.operation === opNodeType; }) || existingOpNodeList.find(function (n) { return n.operation === opNodeType; });
|
|
848
|
+
if (opNode) {
|
|
849
|
+
finalOpNodeList.push(opNode);
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
for (var opNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
853
|
+
_loop_1(opNodeType);
|
|
854
|
+
}
|
|
855
|
+
return finalOpNodeList;
|
|
856
|
+
}
|
|
857
|
+
function mergeSchemaDefs(node, existingNode, config) {
|
|
858
|
+
if (existingNode) {
|
|
859
|
+
return {
|
|
860
|
+
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
|
|
861
|
+
node.kind === graphql.Kind.SCHEMA_DEFINITION ||
|
|
862
|
+
existingNode.kind === graphql.Kind.SCHEMA_DEFINITION
|
|
863
|
+
? graphql.Kind.SCHEMA_DEFINITION
|
|
864
|
+
: graphql.Kind.SCHEMA_EXTENSION,
|
|
865
|
+
description: node['description'] || existingNode['description'],
|
|
866
|
+
directives: mergeDirectives(node.directives, existingNode.directives, config),
|
|
867
|
+
operationTypes: mergeOperationTypes(node.operationTypes, existingNode.operationTypes),
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
return ((config === null || config === void 0 ? void 0 : config.convertExtensions)
|
|
871
|
+
? tslib.__assign(tslib.__assign({}, node), { kind: graphql.Kind.SCHEMA_EXTENSION }) : node);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function isNamedDefinitionNode(definitionNode) {
|
|
875
|
+
return 'name' in definitionNode;
|
|
876
|
+
}
|
|
877
|
+
var schemaDefSymbol = Symbol('schemaDefSymbol');
|
|
865
878
|
function mergeGraphQLNodes(nodes, config) {
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
config.
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
879
|
+
var e_1, _a;
|
|
880
|
+
var _b, _c;
|
|
881
|
+
var mergedResultMap = {};
|
|
882
|
+
try {
|
|
883
|
+
for (var nodes_1 = tslib.__values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
|
|
884
|
+
var nodeDefinition = nodes_1_1.value;
|
|
885
|
+
if (isNamedDefinitionNode(nodeDefinition)) {
|
|
886
|
+
var name_1 = nodeDefinition.name.value;
|
|
887
|
+
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
|
|
888
|
+
collectComment(nodeDefinition);
|
|
889
|
+
}
|
|
890
|
+
if (((_b = config === null || config === void 0 ? void 0 : config.exclusions) === null || _b === void 0 ? void 0 : _b.includes(name_1 + '.*')) || ((_c = config === null || config === void 0 ? void 0 : config.exclusions) === null || _c === void 0 ? void 0 : _c.includes(name_1))) {
|
|
891
|
+
delete mergedResultMap[name_1];
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
switch (nodeDefinition.kind) {
|
|
895
|
+
case graphql.Kind.OBJECT_TYPE_DEFINITION:
|
|
896
|
+
case graphql.Kind.OBJECT_TYPE_EXTENSION:
|
|
897
|
+
mergedResultMap[name_1] = mergeType(nodeDefinition, mergedResultMap[name_1], config);
|
|
898
|
+
break;
|
|
899
|
+
case graphql.Kind.ENUM_TYPE_DEFINITION:
|
|
900
|
+
case graphql.Kind.ENUM_TYPE_EXTENSION:
|
|
901
|
+
mergedResultMap[name_1] = mergeEnum(nodeDefinition, mergedResultMap[name_1], config);
|
|
902
|
+
break;
|
|
903
|
+
case graphql.Kind.UNION_TYPE_DEFINITION:
|
|
904
|
+
case graphql.Kind.UNION_TYPE_EXTENSION:
|
|
905
|
+
mergedResultMap[name_1] = mergeUnion(nodeDefinition, mergedResultMap[name_1], config);
|
|
906
|
+
break;
|
|
907
|
+
case graphql.Kind.SCALAR_TYPE_DEFINITION:
|
|
908
|
+
case graphql.Kind.SCALAR_TYPE_EXTENSION:
|
|
909
|
+
mergedResultMap[name_1] = mergeScalar(nodeDefinition, mergedResultMap[name_1], config);
|
|
910
|
+
break;
|
|
911
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
912
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION:
|
|
913
|
+
mergedResultMap[name_1] = mergeInputType(nodeDefinition, mergedResultMap[name_1], config);
|
|
914
|
+
break;
|
|
915
|
+
case graphql.Kind.INTERFACE_TYPE_DEFINITION:
|
|
916
|
+
case graphql.Kind.INTERFACE_TYPE_EXTENSION:
|
|
917
|
+
mergedResultMap[name_1] = mergeInterface(nodeDefinition, mergedResultMap[name_1], config);
|
|
918
|
+
break;
|
|
919
|
+
case graphql.Kind.DIRECTIVE_DEFINITION:
|
|
920
|
+
mergedResultMap[name_1] = mergeDirective(nodeDefinition, mergedResultMap[name_1]);
|
|
921
|
+
break;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
895
924
|
}
|
|
896
|
-
else if (
|
|
897
|
-
|
|
925
|
+
else if (nodeDefinition.kind === graphql.Kind.SCHEMA_DEFINITION || nodeDefinition.kind === graphql.Kind.SCHEMA_EXTENSION) {
|
|
926
|
+
mergedResultMap[schemaDefSymbol] = mergeSchemaDefs(nodeDefinition, mergedResultMap[schemaDefSymbol], config);
|
|
898
927
|
}
|
|
899
928
|
}
|
|
900
|
-
|
|
901
|
-
|
|
929
|
+
}
|
|
930
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
931
|
+
finally {
|
|
932
|
+
try {
|
|
933
|
+
if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) _a.call(nodes_1);
|
|
934
|
+
}
|
|
935
|
+
finally { if (e_1) throw e_1.error; }
|
|
936
|
+
}
|
|
937
|
+
return mergedResultMap;
|
|
902
938
|
}
|
|
903
939
|
|
|
904
940
|
function mergeTypeDefs(types, config) {
|
|
@@ -917,61 +953,100 @@ function mergeTypeDefs(types, config) {
|
|
|
917
953
|
resetComments();
|
|
918
954
|
return result;
|
|
919
955
|
}
|
|
920
|
-
function
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
.
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
956
|
+
function visitTypeSources(types, allNodes) {
|
|
957
|
+
var e_1, _a;
|
|
958
|
+
try {
|
|
959
|
+
for (var types_1 = tslib.__values(types), types_1_1 = types_1.next(); !types_1_1.done; types_1_1 = types_1.next()) {
|
|
960
|
+
var type = types_1_1.value;
|
|
961
|
+
if (type) {
|
|
962
|
+
if (Array.isArray(type)) {
|
|
963
|
+
visitTypeSources(types, allNodes);
|
|
964
|
+
}
|
|
965
|
+
else if (graphql.isSchema(type)) {
|
|
966
|
+
var documentNode = utils.getDocumentNodeFromSchema(type);
|
|
967
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
968
|
+
}
|
|
969
|
+
else if (isStringTypes(type) || isSourceTypes(type)) {
|
|
970
|
+
var documentNode = graphql.parse(type);
|
|
971
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
972
|
+
}
|
|
973
|
+
else if (graphql.isDefinitionNode(type)) {
|
|
974
|
+
allNodes.push(type);
|
|
975
|
+
}
|
|
976
|
+
else {
|
|
977
|
+
visitTypeSources(type.definitions, allNodes);
|
|
978
|
+
}
|
|
979
|
+
}
|
|
929
980
|
}
|
|
930
|
-
|
|
931
|
-
|
|
981
|
+
}
|
|
982
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
983
|
+
finally {
|
|
984
|
+
try {
|
|
985
|
+
if (types_1_1 && !types_1_1.done && (_a = types_1.return)) _a.call(types_1);
|
|
932
986
|
}
|
|
933
|
-
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
var schemaDef = allNodes.filter(isSchemaDefinition).reduce(function (def, node) {
|
|
942
|
-
node.operationTypes
|
|
943
|
-
.filter(function (op) { return op.type.name.value; })
|
|
944
|
-
.forEach(function (op) {
|
|
945
|
-
def[op.operation] = op.type.name.value;
|
|
946
|
-
});
|
|
947
|
-
return def;
|
|
948
|
-
}, {
|
|
949
|
-
query: null,
|
|
950
|
-
mutation: null,
|
|
951
|
-
subscription: null,
|
|
952
|
-
});
|
|
987
|
+
finally { if (e_1) throw e_1.error; }
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
function mergeGraphQLTypes(types, config) {
|
|
991
|
+
var _a, _b;
|
|
992
|
+
resetComments();
|
|
993
|
+
var allNodes = [];
|
|
994
|
+
visitTypeSources(types, allNodes);
|
|
953
995
|
var mergedNodes = mergeGraphQLNodes(allNodes, config);
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
996
|
+
// XXX: right now we don't handle multiple schema definitions
|
|
997
|
+
var schemaDef = mergedNodes[schemaDefSymbol] || {
|
|
998
|
+
kind: graphql.Kind.SCHEMA_DEFINITION,
|
|
999
|
+
operationTypes: [],
|
|
1000
|
+
};
|
|
1001
|
+
if (config === null || config === void 0 ? void 0 : config.useSchemaDefinition) {
|
|
1002
|
+
var operationTypes = schemaDef.operationTypes;
|
|
1003
|
+
var _loop_1 = function (opTypeDefNodeType) {
|
|
1004
|
+
var opTypeDefNode = operationTypes.find(function (operationType) { return operationType.operation === opTypeDefNodeType; });
|
|
1005
|
+
if (!opTypeDefNode) {
|
|
1006
|
+
var existingPossibleRootType = mergedNodes[operationTypeDefinitionNodeTypeRootTypeMap[opTypeDefNodeType]];
|
|
1007
|
+
if (existingPossibleRootType) {
|
|
1008
|
+
operationTypes.push({
|
|
1009
|
+
kind: graphql.Kind.OPERATION_TYPE_DEFINITION,
|
|
1010
|
+
type: {
|
|
1011
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
1012
|
+
name: existingPossibleRootType.name,
|
|
1013
|
+
},
|
|
1014
|
+
operation: opTypeDefNodeType,
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
};
|
|
1019
|
+
for (var opTypeDefNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
1020
|
+
_loop_1(opTypeDefNodeType);
|
|
1021
|
+
}
|
|
957
1022
|
}
|
|
958
|
-
if (config
|
|
959
|
-
var queryType = schemaDef.query ? schemaDef.query : allTypes.find(function (t) { return t === 'Query'; });
|
|
960
|
-
var mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find(function (t) { return t === 'Mutation'; });
|
|
961
|
-
var subscriptionType = schemaDef.subscription ? schemaDef.subscription : allTypes.find(function (t) { return t === 'Subscription'; });
|
|
1023
|
+
if ((config === null || config === void 0 ? void 0 : config.forceSchemaDefinition) && !((_a = schemaDef === null || schemaDef === void 0 ? void 0 : schemaDef.operationTypes) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
962
1024
|
schemaDef = {
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1025
|
+
kind: graphql.Kind.SCHEMA_DEFINITION,
|
|
1026
|
+
operationTypes: [
|
|
1027
|
+
{
|
|
1028
|
+
kind: graphql.Kind.OPERATION_TYPE_DEFINITION,
|
|
1029
|
+
operation: 'query',
|
|
1030
|
+
type: {
|
|
1031
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
1032
|
+
name: {
|
|
1033
|
+
kind: graphql.Kind.NAME,
|
|
1034
|
+
value: 'Query',
|
|
1035
|
+
},
|
|
1036
|
+
},
|
|
1037
|
+
},
|
|
1038
|
+
],
|
|
966
1039
|
};
|
|
967
1040
|
}
|
|
968
|
-
var
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
1041
|
+
var mergedNodeDefinitions = Object.values(mergedNodes);
|
|
1042
|
+
if ((_b = schemaDef.operationTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
1043
|
+
mergedNodeDefinitions.push(schemaDef);
|
|
1044
|
+
}
|
|
1045
|
+
if (config === null || config === void 0 ? void 0 : config.sort) {
|
|
1046
|
+
var sortFn_1 = typeof config.sort === 'function' ? config.sort : defaultStringComparator;
|
|
1047
|
+
mergedNodeDefinitions.sort(function (a, b) { var _a, _b; return sortFn_1((_a = a.name) === null || _a === void 0 ? void 0 : _a.value, (_b = b.name) === null || _b === void 0 ? void 0 : _b.value); });
|
|
973
1048
|
}
|
|
974
|
-
return
|
|
1049
|
+
return mergedNodeDefinitions;
|
|
975
1050
|
}
|
|
976
1051
|
|
|
977
1052
|
function travelSchemaPossibleExtensions(schema, hooks) {
|
|
@@ -1267,7 +1342,7 @@ function mergeSchemas(config) {
|
|
|
1267
1342
|
}
|
|
1268
1343
|
finally { if (e_1) throw e_1.error; }
|
|
1269
1344
|
}
|
|
1270
|
-
extractedResolvers.push.apply(extractedResolvers, tslib.
|
|
1345
|
+
extractedResolvers.push.apply(extractedResolvers, tslib.__spreadArray([], tslib.__read(ensureResolvers(config))));
|
|
1271
1346
|
var resolvers = mergeResolvers(extractedResolvers, config);
|
|
1272
1347
|
var extensions = mergeExtensions(extractedExtensions);
|
|
1273
1348
|
return makeSchema({ resolvers: resolvers, typeDefs: typeDefs, extensions: extensions }, config);
|
|
@@ -1287,7 +1362,7 @@ function mergeSchemasAsync(config) {
|
|
|
1287
1362
|
Promise.all(config.schemas.map(function (schema) { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
|
|
1288
1363
|
return [2 /*return*/, utils.getResolversFromSchema(schema)];
|
|
1289
1364
|
}); }); })).then(function (extractedResolvers) {
|
|
1290
|
-
return mergeResolvers(tslib.
|
|
1365
|
+
return mergeResolvers(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(extractedResolvers)), tslib.__read(ensureResolvers(config))), config);
|
|
1291
1366
|
}),
|
|
1292
1367
|
Promise.all(config.schemas.map(function (schema) { return tslib.__awaiter(_this, void 0, void 0, function () { return tslib.__generator(this, function (_a) {
|
|
1293
1368
|
return [2 /*return*/, extractExtensionsFromSchema(schema)];
|
|
@@ -1304,7 +1379,7 @@ function mergeSchemasAsync(config) {
|
|
|
1304
1379
|
}
|
|
1305
1380
|
function mergeTypes(_a) {
|
|
1306
1381
|
var schemas = _a.schemas, typeDefs = _a.typeDefs, config = tslib.__rest(_a, ["schemas", "typeDefs"]);
|
|
1307
|
-
return mergeTypeDefs(tslib.
|
|
1382
|
+
return mergeTypeDefs(tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(schemas)), tslib.__read((typeDefs ? utils.asArray(typeDefs) : []))), config);
|
|
1308
1383
|
}
|
|
1309
1384
|
function ensureResolvers(config) {
|
|
1310
1385
|
return config.resolvers ? utils.asArray(config.resolvers) : [];
|
|
@@ -1335,24 +1410,12 @@ function makeSchema(_a, config) {
|
|
|
1335
1410
|
|
|
1336
1411
|
exports.applyExtensions = applyExtensions;
|
|
1337
1412
|
exports.collectComment = collectComment;
|
|
1413
|
+
exports.defaultStringComparator = defaultStringComparator;
|
|
1338
1414
|
exports.extractExtensionsFromSchema = extractExtensionsFromSchema;
|
|
1339
1415
|
exports.extractType = extractType;
|
|
1340
|
-
exports.isGraphQLDirective = isGraphQLDirective;
|
|
1341
|
-
exports.isGraphQLEnum = isGraphQLEnum;
|
|
1342
|
-
exports.isGraphQLEnumExtension = isGraphQLEnumExtension;
|
|
1343
|
-
exports.isGraphQLInputType = isGraphQLInputType;
|
|
1344
|
-
exports.isGraphQLInputTypeExtension = isGraphQLInputTypeExtension;
|
|
1345
|
-
exports.isGraphQLInterface = isGraphQLInterface;
|
|
1346
|
-
exports.isGraphQLInterfaceExtension = isGraphQLInterfaceExtension;
|
|
1347
|
-
exports.isGraphQLScalar = isGraphQLScalar;
|
|
1348
|
-
exports.isGraphQLScalarExtension = isGraphQLScalarExtension;
|
|
1349
|
-
exports.isGraphQLType = isGraphQLType;
|
|
1350
|
-
exports.isGraphQLTypeExtension = isGraphQLTypeExtension;
|
|
1351
|
-
exports.isGraphQLUnion = isGraphQLUnion;
|
|
1352
|
-
exports.isGraphQLUnionExtension = isGraphQLUnionExtension;
|
|
1353
1416
|
exports.isListTypeNode = isListTypeNode;
|
|
1417
|
+
exports.isNamedDefinitionNode = isNamedDefinitionNode;
|
|
1354
1418
|
exports.isNonNullTypeNode = isNonNullTypeNode;
|
|
1355
|
-
exports.isSchemaDefinition = isSchemaDefinition;
|
|
1356
1419
|
exports.isSourceTypes = isSourceTypes;
|
|
1357
1420
|
exports.isStringTypes = isStringTypes;
|
|
1358
1421
|
exports.isWrappingTypeNode = isWrappingTypeNode;
|
|
@@ -1380,5 +1443,6 @@ exports.printTypeNode = printTypeNode;
|
|
|
1380
1443
|
exports.printWithComments = printWithComments;
|
|
1381
1444
|
exports.pushComment = pushComment;
|
|
1382
1445
|
exports.resetComments = resetComments;
|
|
1446
|
+
exports.schemaDefSymbol = schemaDefSymbol;
|
|
1383
1447
|
exports.travelSchemaPossibleExtensions = travelSchemaPossibleExtensions;
|
|
1384
1448
|
//# sourceMappingURL=index.cjs.js.map
|