@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.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import { __values, __read, __spread, __assign, __awaiter, __generator, __rest } from 'tslib';
2
- import { mergeDeep, compareNodes, isNotEqual, getDocumentNodeFromSchema, createSchemaDefinition, asArray, getResolversFromSchema, SchemaDirectiveVisitor } from '@graphql-tools/utils/es5';
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, __spread(args)); });
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 = __spread(keys, [parent.name.value]).join('.');
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, __spread(commentsRegistry[key]));
205
+ items.push.apply(items, __spreadArray([], __read(commentsRegistry[key])));
206
206
  }
207
- return join(__spread(items.map(printComment), [node.description, cb(node)]), '\n');
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 = __spread(a2);
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(__spread(asNext));
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: __spread(existingNode.locations, node.locations.filter(function (name) { return !nameAlreadyExists(name, existingNode.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 = __spread(enumValueMap.values());
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 === 'ListType' || visitedType.kind === 'NonNullType') {
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 = __spread(f2);
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 && config.throwOnConflict) {
672
- preventConflicts(type, existing, field);
673
- }
674
- else {
675
- preventConflicts(type, existing, field);
676
- }
677
- if (isNonNullTypeNode(field.type) && !isNonNullTypeNode(existing.type)) {
678
- existing.type = field.type;
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 = __spread(second, first.filter(function (d) { return !alreadyExists(second, d); }));
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
- return nodes.reduce(function (prev, nodeDefinition) {
863
- var node = nodeDefinition;
864
- if (node && node.name && node.name.value) {
865
- var name_1 = node.name.value;
866
- if (config && config.commentDescriptions) {
867
- collectComment(node);
868
- }
869
- if (config &&
870
- config.exclusions &&
871
- (config.exclusions.includes(name_1 + '.*') || config.exclusions.includes(name_1))) {
872
- delete prev[name_1];
873
- }
874
- else if (isGraphQLType(nodeDefinition) || isGraphQLTypeExtension(nodeDefinition)) {
875
- prev[name_1] = mergeType(nodeDefinition, prev[name_1], config);
876
- }
877
- else if (isGraphQLEnum(nodeDefinition) || isGraphQLEnumExtension(nodeDefinition)) {
878
- prev[name_1] = mergeEnum(nodeDefinition, prev[name_1], config);
879
- }
880
- else if (isGraphQLUnion(nodeDefinition) || isGraphQLUnionExtension(nodeDefinition)) {
881
- prev[name_1] = mergeUnion(nodeDefinition, prev[name_1], config);
882
- }
883
- else if (isGraphQLScalar(nodeDefinition) || isGraphQLScalarExtension(nodeDefinition)) {
884
- prev[name_1] = mergeScalar(nodeDefinition, prev[name_1], config);
885
- }
886
- else if (isGraphQLInputType(nodeDefinition) || isGraphQLInputTypeExtension(nodeDefinition)) {
887
- prev[name_1] = mergeInputType(nodeDefinition, prev[name_1], config);
888
- }
889
- else if (isGraphQLInterface(nodeDefinition) || isGraphQLInterfaceExtension(nodeDefinition)) {
890
- prev[name_1] = mergeInterface(nodeDefinition, prev[name_1], config);
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 (isGraphQLDirective(nodeDefinition)) {
893
- prev[name_1] = mergeDirective(nodeDefinition, prev[name_1]);
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
- return prev;
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 mergeGraphQLTypes(types, config) {
917
- resetComments();
918
- var allNodes = types
919
- .map(function (type) {
920
- if (Array.isArray(type)) {
921
- type = mergeTypeDefs(type);
922
- }
923
- if (isSchema(type)) {
924
- return getDocumentNodeFromSchema(type);
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
- else if (isStringTypes(type) || isSourceTypes(type)) {
927
- return parse(type);
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
- return type;
930
- })
931
- .map(function (ast) { return ast.definitions; })
932
- .reduce(function (defs, newDef) {
933
- if (newDef === void 0) { newDef = []; }
934
- return __spread(defs, newDef);
935
- }, []);
936
- // XXX: right now we don't handle multiple schema definitions
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
- var allTypes = Object.keys(mergedNodes);
951
- if (config && config.sort) {
952
- allTypes.sort(typeof config.sort === 'function' ? config.sort : undefined);
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 && config.useSchemaDefinition) {
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
- query: queryType,
960
- mutation: mutationType,
961
- subscription: subscriptionType,
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 schemaDefinition = createSchemaDefinition(schemaDef, {
965
- force: config.forceSchemaDefinition,
966
- });
967
- if (!schemaDefinition) {
968
- return Object.values(mergedNodes);
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 __spread(Object.values(mergedNodes), [parse(schemaDefinition).definitions[0]]);
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, __spread(ensureResolvers(config)));
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(__spread(extractedResolvers, ensureResolvers(config)), config);
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(__spread(schemas, (typeDefs ? asArray(typeDefs) : [])), config);
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, isGraphQLDirective, isGraphQLEnum, isGraphQLEnumExtension, isGraphQLInputType, isGraphQLInputTypeExtension, isGraphQLInterface, isGraphQLInterfaceExtension, isGraphQLScalar, isGraphQLScalarExtension, isGraphQLType, isGraphQLTypeExtension, isGraphQLUnion, isGraphQLUnionExtension, isListTypeNode, isNonNullTypeNode, isSchemaDefinition, 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, travelSchemaPossibleExtensions };
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