@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.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { __values, __read,
|
|
2
|
-
import { mergeDeep, compareNodes, isNotEqual, getDocumentNodeFromSchema,
|
|
3
|
-
import { getDescription, visit, print, Source, Kind, isSchema, parse, isScalarType, isSpecifiedScalarType, isIntrospectionType, isObjectType, isInterfaceType, isInputObjectType, isUnionType, isEnumType, buildSchema, buildASTSchema } from 'graphql';
|
|
1
|
+
import { __values, __read, __spreadArray, __assign, __awaiter, __generator, __rest } from 'tslib';
|
|
2
|
+
import { mergeDeep, compareNodes, isNotEqual, getDocumentNodeFromSchema, asArray, getResolversFromSchema, SchemaDirectiveVisitor } from '@graphql-tools/utils/es5';
|
|
3
|
+
import { getDescription, visit, print, Source, Kind, isSchema, parse, isDefinitionNode, isScalarType, isSpecifiedScalarType, isIntrospectionType, isObjectType, isInterfaceType, isInputObjectType, isUnionType, isEnumType, buildSchema, buildASTSchema } from 'graphql';
|
|
4
4
|
import { addResolversToSchema, addErrorLoggingToSchema } from '@graphql-tools/schema/es5';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -74,7 +74,7 @@ function mergeResolvers(resolversDefinitions, options) {
|
|
|
74
74
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
75
75
|
args[_i] = arguments[_i];
|
|
76
76
|
}
|
|
77
|
-
var resultsOfFactories = resolversFactories.map(function (factory) { return factory.apply(void 0,
|
|
77
|
+
var resultsOfFactories = resolversFactories.map(function (factory) { return factory.apply(void 0, __spreadArray([], __read(args))); });
|
|
78
78
|
return resolvers.concat(resultsOfFactories).reduce(mergeDeep, {});
|
|
79
79
|
});
|
|
80
80
|
}
|
|
@@ -199,12 +199,12 @@ function addDescription(cb) {
|
|
|
199
199
|
}
|
|
200
200
|
return prev[key];
|
|
201
201
|
}, ancestors[0]);
|
|
202
|
-
var key =
|
|
202
|
+
var key = __spreadArray(__spreadArray([], __read(keys)), [parent.name.value]).join('.');
|
|
203
203
|
var items = [];
|
|
204
204
|
if (commentsRegistry[key]) {
|
|
205
|
-
items.push.apply(items,
|
|
205
|
+
items.push.apply(items, __spreadArray([], __read(commentsRegistry[key])));
|
|
206
206
|
}
|
|
207
|
-
return join(
|
|
207
|
+
return join(__spreadArray(__spreadArray([], __read(items.map(printComment))), [node.description, cb(node)]), '\n');
|
|
208
208
|
};
|
|
209
209
|
}
|
|
210
210
|
function indent(maybeString) {
|
|
@@ -407,7 +407,7 @@ function nameAlreadyExists(name, namesArr) {
|
|
|
407
407
|
}
|
|
408
408
|
function mergeArguments$1(a1, a2) {
|
|
409
409
|
var e_1, _a;
|
|
410
|
-
var result =
|
|
410
|
+
var result = __spreadArray([], __read(a2));
|
|
411
411
|
var _loop_1 = function (argument) {
|
|
412
412
|
var existingIndex = result.findIndex(function (a) { return a.name.value === argument.name.value; });
|
|
413
413
|
if (existingIndex > -1) {
|
|
@@ -464,7 +464,7 @@ function mergeDirectives(d1, d2, config) {
|
|
|
464
464
|
var reverseOrder = config && config.reverseDirectives;
|
|
465
465
|
var asNext = reverseOrder ? d1 : d2;
|
|
466
466
|
var asFirst = reverseOrder ? d2 : d1;
|
|
467
|
-
var result = deduplicateDirectives(
|
|
467
|
+
var result = deduplicateDirectives(__spreadArray([], __read(asNext)));
|
|
468
468
|
var _loop_2 = function (directive) {
|
|
469
469
|
if (directiveAlreadyExists(result, directive)) {
|
|
470
470
|
var existingDirectiveIndex = result.findIndex(function (d) { return d.name.value === directive.name.value; });
|
|
@@ -503,7 +503,7 @@ function validateInputs(node, existingNode) {
|
|
|
503
503
|
function mergeDirective(node, existingNode) {
|
|
504
504
|
if (existingNode) {
|
|
505
505
|
validateInputs(node, existingNode);
|
|
506
|
-
return __assign(__assign({}, node), { locations:
|
|
506
|
+
return __assign(__assign({}, node), { locations: __spreadArray(__spreadArray([], __read(existingNode.locations)), __read(node.locations.filter(function (name) { return !nameAlreadyExists(name, existingNode.locations); }))) });
|
|
507
507
|
}
|
|
508
508
|
return node;
|
|
509
509
|
}
|
|
@@ -553,7 +553,7 @@ function mergeEnumValues(first, second, config) {
|
|
|
553
553
|
}
|
|
554
554
|
finally { if (e_2) throw e_2.error; }
|
|
555
555
|
}
|
|
556
|
-
var result =
|
|
556
|
+
var result = __spreadArray([], __read(enumValueMap.values()));
|
|
557
557
|
if (config && config.sort) {
|
|
558
558
|
result.sort(compareNodes);
|
|
559
559
|
}
|
|
@@ -583,55 +583,13 @@ function isStringTypes(types) {
|
|
|
583
583
|
function isSourceTypes(types) {
|
|
584
584
|
return types instanceof Source;
|
|
585
585
|
}
|
|
586
|
-
function isGraphQLType(definition) {
|
|
587
|
-
return definition.kind === 'ObjectTypeDefinition';
|
|
588
|
-
}
|
|
589
|
-
function isGraphQLTypeExtension(definition) {
|
|
590
|
-
return definition.kind === 'ObjectTypeExtension';
|
|
591
|
-
}
|
|
592
|
-
function isGraphQLEnum(definition) {
|
|
593
|
-
return definition.kind === 'EnumTypeDefinition';
|
|
594
|
-
}
|
|
595
|
-
function isGraphQLEnumExtension(definition) {
|
|
596
|
-
return definition.kind === 'EnumTypeExtension';
|
|
597
|
-
}
|
|
598
|
-
function isGraphQLUnion(definition) {
|
|
599
|
-
return definition.kind === 'UnionTypeDefinition';
|
|
600
|
-
}
|
|
601
|
-
function isGraphQLUnionExtension(definition) {
|
|
602
|
-
return definition.kind === 'UnionTypeExtension';
|
|
603
|
-
}
|
|
604
|
-
function isGraphQLScalar(definition) {
|
|
605
|
-
return definition.kind === 'ScalarTypeDefinition';
|
|
606
|
-
}
|
|
607
|
-
function isGraphQLScalarExtension(definition) {
|
|
608
|
-
return definition.kind === 'ScalarTypeExtension';
|
|
609
|
-
}
|
|
610
|
-
function isGraphQLInputType(definition) {
|
|
611
|
-
return definition.kind === 'InputObjectTypeDefinition';
|
|
612
|
-
}
|
|
613
|
-
function isGraphQLInputTypeExtension(definition) {
|
|
614
|
-
return definition.kind === 'InputObjectTypeExtension';
|
|
615
|
-
}
|
|
616
|
-
function isGraphQLInterface(definition) {
|
|
617
|
-
return definition.kind === 'InterfaceTypeDefinition';
|
|
618
|
-
}
|
|
619
|
-
function isGraphQLInterfaceExtension(definition) {
|
|
620
|
-
return definition.kind === 'InterfaceTypeExtension';
|
|
621
|
-
}
|
|
622
|
-
function isGraphQLDirective(definition) {
|
|
623
|
-
return definition.kind === 'DirectiveDefinition';
|
|
624
|
-
}
|
|
625
586
|
function extractType(type) {
|
|
626
587
|
var visitedType = type;
|
|
627
|
-
while (visitedType.kind ===
|
|
588
|
+
while (visitedType.kind === Kind.LIST_TYPE || visitedType.kind === 'NonNullType') {
|
|
628
589
|
visitedType = visitedType.type;
|
|
629
590
|
}
|
|
630
591
|
return visitedType;
|
|
631
592
|
}
|
|
632
|
-
function isSchemaDefinition(node) {
|
|
633
|
-
return node.kind === 'SchemaDefinition';
|
|
634
|
-
}
|
|
635
593
|
function isWrappingTypeNode(type) {
|
|
636
594
|
return type.kind !== Kind.NAMED_TYPE;
|
|
637
595
|
}
|
|
@@ -650,10 +608,23 @@ function printTypeNode(type) {
|
|
|
650
608
|
}
|
|
651
609
|
return type.name.value;
|
|
652
610
|
}
|
|
611
|
+
var CompareVal;
|
|
612
|
+
(function (CompareVal) {
|
|
613
|
+
CompareVal[CompareVal["A_SMALLER_THAN_B"] = -1] = "A_SMALLER_THAN_B";
|
|
614
|
+
CompareVal[CompareVal["A_EQUALS_B"] = 0] = "A_EQUALS_B";
|
|
615
|
+
CompareVal[CompareVal["A_GREATER_THAN_B"] = 1] = "A_GREATER_THAN_B";
|
|
616
|
+
})(CompareVal || (CompareVal = {}));
|
|
617
|
+
function defaultStringComparator(a, b) {
|
|
618
|
+
if (a < b)
|
|
619
|
+
return CompareVal.A_SMALLER_THAN_B;
|
|
620
|
+
if (a > b)
|
|
621
|
+
return CompareVal.A_GREATER_THAN_B;
|
|
622
|
+
return CompareVal.A_EQUALS_B;
|
|
623
|
+
}
|
|
653
624
|
|
|
654
|
-
function fieldAlreadyExists(fieldsArr, otherField) {
|
|
625
|
+
function fieldAlreadyExists(fieldsArr, otherField, config) {
|
|
655
626
|
var result = fieldsArr.find(function (field) { return field.name.value === otherField.name.value; });
|
|
656
|
-
if (result) {
|
|
627
|
+
if (result && !(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
657
628
|
var t1 = extractType(result.type);
|
|
658
629
|
var t2 = extractType(otherField.type);
|
|
659
630
|
if (t1.name.value !== t2.name.value) {
|
|
@@ -664,18 +635,20 @@ function fieldAlreadyExists(fieldsArr, otherField) {
|
|
|
664
635
|
}
|
|
665
636
|
function mergeFields(type, f1, f2, config) {
|
|
666
637
|
var e_1, _a;
|
|
667
|
-
var result =
|
|
638
|
+
var result = __spreadArray([], __read(f2));
|
|
668
639
|
var _loop_1 = function (field) {
|
|
669
|
-
if (fieldAlreadyExists(result, field)) {
|
|
640
|
+
if (fieldAlreadyExists(result, field, config)) {
|
|
670
641
|
var existing = result.find(function (f) { return f.name.value === field.name.value; });
|
|
671
|
-
if (config
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
642
|
+
if (!(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
643
|
+
if (config === null || config === void 0 ? void 0 : config.throwOnConflict) {
|
|
644
|
+
preventConflicts(type, existing, field);
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
preventConflicts(type, existing, field);
|
|
648
|
+
}
|
|
649
|
+
if (isNonNullTypeNode(field.type) && !isNonNullTypeNode(existing.type)) {
|
|
650
|
+
existing.type = field.type;
|
|
651
|
+
}
|
|
679
652
|
}
|
|
680
653
|
existing.arguments = mergeArguments(field['arguments'] || [], existing.arguments || [], config);
|
|
681
654
|
existing.directives = mergeDirectives(field.directives, existing.directives, config);
|
|
@@ -789,7 +762,7 @@ function alreadyExists(arr, other) {
|
|
|
789
762
|
return !!arr.find(function (i) { return i.name.value === other.name.value; });
|
|
790
763
|
}
|
|
791
764
|
function mergeNamedTypeArray(first, second, config) {
|
|
792
|
-
var result =
|
|
765
|
+
var result = __spreadArray(__spreadArray([], __read(second)), __read(first.filter(function (d) { return !alreadyExists(second, d); })));
|
|
793
766
|
if (config && config.sort) {
|
|
794
767
|
result.sort(compareNodes);
|
|
795
768
|
}
|
|
@@ -858,43 +831,107 @@ function mergeUnion(first, second, config) {
|
|
|
858
831
|
? __assign(__assign({}, first), { kind: 'UnionTypeDefinition' }) : first;
|
|
859
832
|
}
|
|
860
833
|
|
|
834
|
+
var operationTypeDefinitionNodeTypeRootTypeMap = {
|
|
835
|
+
query: 'Query',
|
|
836
|
+
mutation: 'Mutation',
|
|
837
|
+
subscription: 'Subscription',
|
|
838
|
+
};
|
|
839
|
+
function mergeOperationTypes(opNodeList, existingOpNodeList) {
|
|
840
|
+
if (opNodeList === void 0) { opNodeList = []; }
|
|
841
|
+
if (existingOpNodeList === void 0) { existingOpNodeList = []; }
|
|
842
|
+
var finalOpNodeList = [];
|
|
843
|
+
var _loop_1 = function (opNodeType) {
|
|
844
|
+
var opNode = opNodeList.find(function (n) { return n.operation === opNodeType; }) || existingOpNodeList.find(function (n) { return n.operation === opNodeType; });
|
|
845
|
+
if (opNode) {
|
|
846
|
+
finalOpNodeList.push(opNode);
|
|
847
|
+
}
|
|
848
|
+
};
|
|
849
|
+
for (var opNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
850
|
+
_loop_1(opNodeType);
|
|
851
|
+
}
|
|
852
|
+
return finalOpNodeList;
|
|
853
|
+
}
|
|
854
|
+
function mergeSchemaDefs(node, existingNode, config) {
|
|
855
|
+
if (existingNode) {
|
|
856
|
+
return {
|
|
857
|
+
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
|
|
858
|
+
node.kind === Kind.SCHEMA_DEFINITION ||
|
|
859
|
+
existingNode.kind === Kind.SCHEMA_DEFINITION
|
|
860
|
+
? Kind.SCHEMA_DEFINITION
|
|
861
|
+
: Kind.SCHEMA_EXTENSION,
|
|
862
|
+
description: node['description'] || existingNode['description'],
|
|
863
|
+
directives: mergeDirectives(node.directives, existingNode.directives, config),
|
|
864
|
+
operationTypes: mergeOperationTypes(node.operationTypes, existingNode.operationTypes),
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
return ((config === null || config === void 0 ? void 0 : config.convertExtensions)
|
|
868
|
+
? __assign(__assign({}, node), { kind: Kind.SCHEMA_EXTENSION }) : node);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
function isNamedDefinitionNode(definitionNode) {
|
|
872
|
+
return 'name' in definitionNode;
|
|
873
|
+
}
|
|
874
|
+
var schemaDefSymbol = Symbol('schemaDefSymbol');
|
|
861
875
|
function mergeGraphQLNodes(nodes, config) {
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
config.
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
876
|
+
var e_1, _a;
|
|
877
|
+
var _b, _c;
|
|
878
|
+
var mergedResultMap = {};
|
|
879
|
+
try {
|
|
880
|
+
for (var nodes_1 = __values(nodes), nodes_1_1 = nodes_1.next(); !nodes_1_1.done; nodes_1_1 = nodes_1.next()) {
|
|
881
|
+
var nodeDefinition = nodes_1_1.value;
|
|
882
|
+
if (isNamedDefinitionNode(nodeDefinition)) {
|
|
883
|
+
var name_1 = nodeDefinition.name.value;
|
|
884
|
+
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
|
|
885
|
+
collectComment(nodeDefinition);
|
|
886
|
+
}
|
|
887
|
+
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))) {
|
|
888
|
+
delete mergedResultMap[name_1];
|
|
889
|
+
}
|
|
890
|
+
else {
|
|
891
|
+
switch (nodeDefinition.kind) {
|
|
892
|
+
case Kind.OBJECT_TYPE_DEFINITION:
|
|
893
|
+
case Kind.OBJECT_TYPE_EXTENSION:
|
|
894
|
+
mergedResultMap[name_1] = mergeType(nodeDefinition, mergedResultMap[name_1], config);
|
|
895
|
+
break;
|
|
896
|
+
case Kind.ENUM_TYPE_DEFINITION:
|
|
897
|
+
case Kind.ENUM_TYPE_EXTENSION:
|
|
898
|
+
mergedResultMap[name_1] = mergeEnum(nodeDefinition, mergedResultMap[name_1], config);
|
|
899
|
+
break;
|
|
900
|
+
case Kind.UNION_TYPE_DEFINITION:
|
|
901
|
+
case Kind.UNION_TYPE_EXTENSION:
|
|
902
|
+
mergedResultMap[name_1] = mergeUnion(nodeDefinition, mergedResultMap[name_1], config);
|
|
903
|
+
break;
|
|
904
|
+
case Kind.SCALAR_TYPE_DEFINITION:
|
|
905
|
+
case Kind.SCALAR_TYPE_EXTENSION:
|
|
906
|
+
mergedResultMap[name_1] = mergeScalar(nodeDefinition, mergedResultMap[name_1], config);
|
|
907
|
+
break;
|
|
908
|
+
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
909
|
+
case Kind.INPUT_OBJECT_TYPE_EXTENSION:
|
|
910
|
+
mergedResultMap[name_1] = mergeInputType(nodeDefinition, mergedResultMap[name_1], config);
|
|
911
|
+
break;
|
|
912
|
+
case Kind.INTERFACE_TYPE_DEFINITION:
|
|
913
|
+
case Kind.INTERFACE_TYPE_EXTENSION:
|
|
914
|
+
mergedResultMap[name_1] = mergeInterface(nodeDefinition, mergedResultMap[name_1], config);
|
|
915
|
+
break;
|
|
916
|
+
case Kind.DIRECTIVE_DEFINITION:
|
|
917
|
+
mergedResultMap[name_1] = mergeDirective(nodeDefinition, mergedResultMap[name_1]);
|
|
918
|
+
break;
|
|
919
|
+
}
|
|
920
|
+
}
|
|
891
921
|
}
|
|
892
|
-
else if (
|
|
893
|
-
|
|
922
|
+
else if (nodeDefinition.kind === Kind.SCHEMA_DEFINITION || nodeDefinition.kind === Kind.SCHEMA_EXTENSION) {
|
|
923
|
+
mergedResultMap[schemaDefSymbol] = mergeSchemaDefs(nodeDefinition, mergedResultMap[schemaDefSymbol], config);
|
|
894
924
|
}
|
|
895
925
|
}
|
|
896
|
-
|
|
897
|
-
|
|
926
|
+
}
|
|
927
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
928
|
+
finally {
|
|
929
|
+
try {
|
|
930
|
+
if (nodes_1_1 && !nodes_1_1.done && (_a = nodes_1.return)) _a.call(nodes_1);
|
|
931
|
+
}
|
|
932
|
+
finally { if (e_1) throw e_1.error; }
|
|
933
|
+
}
|
|
934
|
+
return mergedResultMap;
|
|
898
935
|
}
|
|
899
936
|
|
|
900
937
|
function mergeTypeDefs(types, config) {
|
|
@@ -913,61 +950,100 @@ function mergeTypeDefs(types, config) {
|
|
|
913
950
|
resetComments();
|
|
914
951
|
return result;
|
|
915
952
|
}
|
|
916
|
-
function
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
.
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
953
|
+
function visitTypeSources(types, allNodes) {
|
|
954
|
+
var e_1, _a;
|
|
955
|
+
try {
|
|
956
|
+
for (var types_1 = __values(types), types_1_1 = types_1.next(); !types_1_1.done; types_1_1 = types_1.next()) {
|
|
957
|
+
var type = types_1_1.value;
|
|
958
|
+
if (type) {
|
|
959
|
+
if (Array.isArray(type)) {
|
|
960
|
+
visitTypeSources(types, allNodes);
|
|
961
|
+
}
|
|
962
|
+
else if (isSchema(type)) {
|
|
963
|
+
var documentNode = getDocumentNodeFromSchema(type);
|
|
964
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
965
|
+
}
|
|
966
|
+
else if (isStringTypes(type) || isSourceTypes(type)) {
|
|
967
|
+
var documentNode = parse(type);
|
|
968
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
969
|
+
}
|
|
970
|
+
else if (isDefinitionNode(type)) {
|
|
971
|
+
allNodes.push(type);
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
visitTypeSources(type.definitions, allNodes);
|
|
975
|
+
}
|
|
976
|
+
}
|
|
925
977
|
}
|
|
926
|
-
|
|
927
|
-
|
|
978
|
+
}
|
|
979
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
980
|
+
finally {
|
|
981
|
+
try {
|
|
982
|
+
if (types_1_1 && !types_1_1.done && (_a = types_1.return)) _a.call(types_1);
|
|
928
983
|
}
|
|
929
|
-
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
var schemaDef = allNodes.filter(isSchemaDefinition).reduce(function (def, node) {
|
|
938
|
-
node.operationTypes
|
|
939
|
-
.filter(function (op) { return op.type.name.value; })
|
|
940
|
-
.forEach(function (op) {
|
|
941
|
-
def[op.operation] = op.type.name.value;
|
|
942
|
-
});
|
|
943
|
-
return def;
|
|
944
|
-
}, {
|
|
945
|
-
query: null,
|
|
946
|
-
mutation: null,
|
|
947
|
-
subscription: null,
|
|
948
|
-
});
|
|
984
|
+
finally { if (e_1) throw e_1.error; }
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
function mergeGraphQLTypes(types, config) {
|
|
988
|
+
var _a, _b;
|
|
989
|
+
resetComments();
|
|
990
|
+
var allNodes = [];
|
|
991
|
+
visitTypeSources(types, allNodes);
|
|
949
992
|
var mergedNodes = mergeGraphQLNodes(allNodes, config);
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
993
|
+
// XXX: right now we don't handle multiple schema definitions
|
|
994
|
+
var schemaDef = mergedNodes[schemaDefSymbol] || {
|
|
995
|
+
kind: Kind.SCHEMA_DEFINITION,
|
|
996
|
+
operationTypes: [],
|
|
997
|
+
};
|
|
998
|
+
if (config === null || config === void 0 ? void 0 : config.useSchemaDefinition) {
|
|
999
|
+
var operationTypes = schemaDef.operationTypes;
|
|
1000
|
+
var _loop_1 = function (opTypeDefNodeType) {
|
|
1001
|
+
var opTypeDefNode = operationTypes.find(function (operationType) { return operationType.operation === opTypeDefNodeType; });
|
|
1002
|
+
if (!opTypeDefNode) {
|
|
1003
|
+
var existingPossibleRootType = mergedNodes[operationTypeDefinitionNodeTypeRootTypeMap[opTypeDefNodeType]];
|
|
1004
|
+
if (existingPossibleRootType) {
|
|
1005
|
+
operationTypes.push({
|
|
1006
|
+
kind: Kind.OPERATION_TYPE_DEFINITION,
|
|
1007
|
+
type: {
|
|
1008
|
+
kind: Kind.NAMED_TYPE,
|
|
1009
|
+
name: existingPossibleRootType.name,
|
|
1010
|
+
},
|
|
1011
|
+
operation: opTypeDefNodeType,
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
for (var opTypeDefNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
1017
|
+
_loop_1(opTypeDefNodeType);
|
|
1018
|
+
}
|
|
953
1019
|
}
|
|
954
|
-
if (config
|
|
955
|
-
var queryType = schemaDef.query ? schemaDef.query : allTypes.find(function (t) { return t === 'Query'; });
|
|
956
|
-
var mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find(function (t) { return t === 'Mutation'; });
|
|
957
|
-
var subscriptionType = schemaDef.subscription ? schemaDef.subscription : allTypes.find(function (t) { return t === 'Subscription'; });
|
|
1020
|
+
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)) {
|
|
958
1021
|
schemaDef = {
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
1022
|
+
kind: Kind.SCHEMA_DEFINITION,
|
|
1023
|
+
operationTypes: [
|
|
1024
|
+
{
|
|
1025
|
+
kind: Kind.OPERATION_TYPE_DEFINITION,
|
|
1026
|
+
operation: 'query',
|
|
1027
|
+
type: {
|
|
1028
|
+
kind: Kind.NAMED_TYPE,
|
|
1029
|
+
name: {
|
|
1030
|
+
kind: Kind.NAME,
|
|
1031
|
+
value: 'Query',
|
|
1032
|
+
},
|
|
1033
|
+
},
|
|
1034
|
+
},
|
|
1035
|
+
],
|
|
962
1036
|
};
|
|
963
1037
|
}
|
|
964
|
-
var
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
1038
|
+
var mergedNodeDefinitions = Object.values(mergedNodes);
|
|
1039
|
+
if ((_b = schemaDef.operationTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
1040
|
+
mergedNodeDefinitions.push(schemaDef);
|
|
1041
|
+
}
|
|
1042
|
+
if (config === null || config === void 0 ? void 0 : config.sort) {
|
|
1043
|
+
var sortFn_1 = typeof config.sort === 'function' ? config.sort : defaultStringComparator;
|
|
1044
|
+
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); });
|
|
969
1045
|
}
|
|
970
|
-
return
|
|
1046
|
+
return mergedNodeDefinitions;
|
|
971
1047
|
}
|
|
972
1048
|
|
|
973
1049
|
function travelSchemaPossibleExtensions(schema, hooks) {
|
|
@@ -1263,7 +1339,7 @@ function mergeSchemas(config) {
|
|
|
1263
1339
|
}
|
|
1264
1340
|
finally { if (e_1) throw e_1.error; }
|
|
1265
1341
|
}
|
|
1266
|
-
extractedResolvers.push.apply(extractedResolvers,
|
|
1342
|
+
extractedResolvers.push.apply(extractedResolvers, __spreadArray([], __read(ensureResolvers(config))));
|
|
1267
1343
|
var resolvers = mergeResolvers(extractedResolvers, config);
|
|
1268
1344
|
var extensions = mergeExtensions(extractedExtensions);
|
|
1269
1345
|
return makeSchema({ resolvers: resolvers, typeDefs: typeDefs, extensions: extensions }, config);
|
|
@@ -1283,7 +1359,7 @@ function mergeSchemasAsync(config) {
|
|
|
1283
1359
|
Promise.all(config.schemas.map(function (schema) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1284
1360
|
return [2 /*return*/, getResolversFromSchema(schema)];
|
|
1285
1361
|
}); }); })).then(function (extractedResolvers) {
|
|
1286
|
-
return mergeResolvers(
|
|
1362
|
+
return mergeResolvers(__spreadArray(__spreadArray([], __read(extractedResolvers)), __read(ensureResolvers(config))), config);
|
|
1287
1363
|
}),
|
|
1288
1364
|
Promise.all(config.schemas.map(function (schema) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1289
1365
|
return [2 /*return*/, extractExtensionsFromSchema(schema)];
|
|
@@ -1300,7 +1376,7 @@ function mergeSchemasAsync(config) {
|
|
|
1300
1376
|
}
|
|
1301
1377
|
function mergeTypes(_a) {
|
|
1302
1378
|
var schemas = _a.schemas, typeDefs = _a.typeDefs, config = __rest(_a, ["schemas", "typeDefs"]);
|
|
1303
|
-
return mergeTypeDefs(
|
|
1379
|
+
return mergeTypeDefs(__spreadArray(__spreadArray([], __read(schemas)), __read((typeDefs ? asArray(typeDefs) : []))), config);
|
|
1304
1380
|
}
|
|
1305
1381
|
function ensureResolvers(config) {
|
|
1306
1382
|
return config.resolvers ? asArray(config.resolvers) : [];
|
|
@@ -1329,5 +1405,5 @@ function makeSchema(_a, config) {
|
|
|
1329
1405
|
return schema;
|
|
1330
1406
|
}
|
|
1331
1407
|
|
|
1332
|
-
export { applyExtensions, collectComment, extractExtensionsFromSchema, extractType,
|
|
1408
|
+
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 };
|
|
1333
1409
|
//# sourceMappingURL=index.esm.js.map
|