@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/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-tools/merge/es5",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.11",
|
|
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/schema": "7.
|
|
11
|
-
"@graphql-tools/utils": "7.
|
|
10
|
+
"@graphql-tools/schema": "^7.0.0",
|
|
11
|
+
"@graphql-tools/utils": "^7.7.0",
|
|
12
12
|
"tslib": "~2.1.0"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ASTNode } from 'graphql';
|
|
2
|
+
import { NamedDefinitionNode } from './merge-nodes';
|
|
2
3
|
export declare function resetComments(): void;
|
|
3
|
-
export declare function collectComment(node:
|
|
4
|
-
export declare function pushComment(node:
|
|
5
|
-
readonly description?: StringValueNode;
|
|
6
|
-
}, entity: string, field?: string, argument?: string): void;
|
|
4
|
+
export declare function collectComment(node: NamedDefinitionNode): void;
|
|
5
|
+
export declare function pushComment(node: any, entity: string, field?: string, argument?: string): void;
|
|
7
6
|
export declare function printComment(comment: string): string;
|
|
8
7
|
/**
|
|
9
8
|
* Converts an AST into a string, using one set of reasonable
|
|
@@ -2,4 +2,4 @@ import { Config } from './merge-typedefs';
|
|
|
2
2
|
import { FieldDefinitionNode, InputValueDefinitionNode, NameNode } from 'graphql';
|
|
3
3
|
export declare function mergeFields<T extends FieldDefinitionNode | InputValueDefinitionNode>(type: {
|
|
4
4
|
name: NameNode;
|
|
5
|
-
}, f1: ReadonlyArray<T>, f2: ReadonlyArray<T>, config
|
|
5
|
+
}, f1: ReadonlyArray<T>, f2: ReadonlyArray<T>, config?: Config): T[];
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Config } from './merge-typedefs';
|
|
2
|
-
import { DefinitionNode } from 'graphql';
|
|
3
|
-
export declare type MergedResultMap = {
|
|
4
|
-
[
|
|
2
|
+
import { DefinitionNode, NameNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
|
|
3
|
+
export declare type MergedResultMap = Record<string, NamedDefinitionNode> & {
|
|
4
|
+
[schemaDefSymbol]: SchemaDefinitionNode | SchemaExtensionNode;
|
|
5
5
|
};
|
|
6
|
+
export declare type NamedDefinitionNode = DefinitionNode & {
|
|
7
|
+
name?: NameNode;
|
|
8
|
+
};
|
|
9
|
+
export declare function isNamedDefinitionNode(definitionNode: DefinitionNode): definitionNode is NamedDefinitionNode;
|
|
10
|
+
export declare const schemaDefSymbol: unique symbol;
|
|
6
11
|
export declare function mergeGraphQLNodes(nodes: ReadonlyArray<DefinitionNode>, config?: Config): MergedResultMap;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DefinitionNode, DocumentNode, GraphQLSchema, Source } from 'graphql';
|
|
2
|
+
import { CompareFn } from './utils';
|
|
2
3
|
declare type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
|
|
3
|
-
declare type CompareFn<T> = (a: T, b: T) => number;
|
|
4
4
|
export interface Config {
|
|
5
5
|
/**
|
|
6
6
|
* Produces `schema { query: ..., mutation: ..., subscription: ... }`
|
|
@@ -52,6 +52,7 @@ export interface Config {
|
|
|
52
52
|
sort?: boolean | CompareFn<string>;
|
|
53
53
|
convertExtensions?: boolean;
|
|
54
54
|
consistentEnumMerge?: boolean;
|
|
55
|
+
ignoreFieldConflicts?: boolean;
|
|
55
56
|
}
|
|
56
57
|
/**
|
|
57
58
|
* Merges multiple type definitions into a single `DocumentNode`
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
|
|
2
|
+
import { Config } from './merge-typedefs';
|
|
3
|
+
export declare const operationTypeDefinitionNodeTypeRootTypeMap: {
|
|
4
|
+
readonly query: "Query";
|
|
5
|
+
readonly mutation: "Mutation";
|
|
6
|
+
readonly subscription: "Subscription";
|
|
7
|
+
};
|
|
8
|
+
export declare function mergeSchemaDefs(node: SchemaDefinitionNode | SchemaExtensionNode, existingNode: SchemaDefinitionNode | SchemaExtensionNode, config?: Config): SchemaDefinitionNode | SchemaExtensionNode;
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
import { TypeNode,
|
|
1
|
+
import { TypeNode, NamedTypeNode, ListTypeNode, NonNullTypeNode, Source } from 'graphql';
|
|
2
2
|
export declare function isStringTypes(types: any): types is string;
|
|
3
3
|
export declare function isSourceTypes(types: any): types is Source;
|
|
4
|
-
export declare function isGraphQLType(definition: DefinitionNode): definition is ObjectTypeDefinitionNode;
|
|
5
|
-
export declare function isGraphQLTypeExtension(definition: DefinitionNode): definition is ObjectTypeExtensionNode;
|
|
6
|
-
export declare function isGraphQLEnum(definition: DefinitionNode): definition is EnumTypeDefinitionNode;
|
|
7
|
-
export declare function isGraphQLEnumExtension(definition: DefinitionNode): definition is EnumTypeExtensionNode;
|
|
8
|
-
export declare function isGraphQLUnion(definition: DefinitionNode): definition is UnionTypeDefinitionNode;
|
|
9
|
-
export declare function isGraphQLUnionExtension(definition: DefinitionNode): definition is UnionTypeExtensionNode;
|
|
10
|
-
export declare function isGraphQLScalar(definition: DefinitionNode): definition is ScalarTypeDefinitionNode;
|
|
11
|
-
export declare function isGraphQLScalarExtension(definition: DefinitionNode): definition is ScalarTypeExtensionNode;
|
|
12
|
-
export declare function isGraphQLInputType(definition: DefinitionNode): definition is InputObjectTypeDefinitionNode;
|
|
13
|
-
export declare function isGraphQLInputTypeExtension(definition: DefinitionNode): definition is InputObjectTypeExtensionNode;
|
|
14
|
-
export declare function isGraphQLInterface(definition: DefinitionNode): definition is InterfaceTypeDefinitionNode;
|
|
15
|
-
export declare function isGraphQLInterfaceExtension(definition: DefinitionNode): definition is InterfaceTypeExtensionNode;
|
|
16
|
-
export declare function isGraphQLDirective(definition: DefinitionNode): definition is DirectiveDefinitionNode;
|
|
17
4
|
export declare function extractType(type: TypeNode): NamedTypeNode;
|
|
18
|
-
export declare function isSchemaDefinition(node: DefinitionNode): node is SchemaDefinitionNode;
|
|
19
5
|
export declare function isWrappingTypeNode(type: TypeNode): type is ListTypeNode | NonNullTypeNode;
|
|
20
6
|
export declare function isListTypeNode(type: TypeNode): type is ListTypeNode;
|
|
21
7
|
export declare function isNonNullTypeNode(type: TypeNode): type is NonNullTypeNode;
|
|
22
8
|
export declare function printTypeNode(type: TypeNode): string;
|
|
9
|
+
export declare enum CompareVal {
|
|
10
|
+
A_SMALLER_THAN_B = -1,
|
|
11
|
+
A_EQUALS_B = 0,
|
|
12
|
+
A_GREATER_THAN_B = 1
|
|
13
|
+
}
|
|
14
|
+
export declare type CompareFn<T> = (a: T, b: T) => -1 | 0 | 1;
|
|
15
|
+
export declare function defaultStringComparator(a: string, b: string): CompareVal;
|
package/index.cjs.js
CHANGED
|
@@ -416,55 +416,13 @@ function isStringTypes(types) {
|
|
|
416
416
|
function isSourceTypes(types) {
|
|
417
417
|
return types instanceof graphql.Source;
|
|
418
418
|
}
|
|
419
|
-
function isGraphQLType(definition) {
|
|
420
|
-
return definition.kind === 'ObjectTypeDefinition';
|
|
421
|
-
}
|
|
422
|
-
function isGraphQLTypeExtension(definition) {
|
|
423
|
-
return definition.kind === 'ObjectTypeExtension';
|
|
424
|
-
}
|
|
425
|
-
function isGraphQLEnum(definition) {
|
|
426
|
-
return definition.kind === 'EnumTypeDefinition';
|
|
427
|
-
}
|
|
428
|
-
function isGraphQLEnumExtension(definition) {
|
|
429
|
-
return definition.kind === 'EnumTypeExtension';
|
|
430
|
-
}
|
|
431
|
-
function isGraphQLUnion(definition) {
|
|
432
|
-
return definition.kind === 'UnionTypeDefinition';
|
|
433
|
-
}
|
|
434
|
-
function isGraphQLUnionExtension(definition) {
|
|
435
|
-
return definition.kind === 'UnionTypeExtension';
|
|
436
|
-
}
|
|
437
|
-
function isGraphQLScalar(definition) {
|
|
438
|
-
return definition.kind === 'ScalarTypeDefinition';
|
|
439
|
-
}
|
|
440
|
-
function isGraphQLScalarExtension(definition) {
|
|
441
|
-
return definition.kind === 'ScalarTypeExtension';
|
|
442
|
-
}
|
|
443
|
-
function isGraphQLInputType(definition) {
|
|
444
|
-
return definition.kind === 'InputObjectTypeDefinition';
|
|
445
|
-
}
|
|
446
|
-
function isGraphQLInputTypeExtension(definition) {
|
|
447
|
-
return definition.kind === 'InputObjectTypeExtension';
|
|
448
|
-
}
|
|
449
|
-
function isGraphQLInterface(definition) {
|
|
450
|
-
return definition.kind === 'InterfaceTypeDefinition';
|
|
451
|
-
}
|
|
452
|
-
function isGraphQLInterfaceExtension(definition) {
|
|
453
|
-
return definition.kind === 'InterfaceTypeExtension';
|
|
454
|
-
}
|
|
455
|
-
function isGraphQLDirective(definition) {
|
|
456
|
-
return definition.kind === 'DirectiveDefinition';
|
|
457
|
-
}
|
|
458
419
|
function extractType(type) {
|
|
459
420
|
let visitedType = type;
|
|
460
|
-
while (visitedType.kind ===
|
|
421
|
+
while (visitedType.kind === graphql.Kind.LIST_TYPE || visitedType.kind === 'NonNullType') {
|
|
461
422
|
visitedType = visitedType.type;
|
|
462
423
|
}
|
|
463
424
|
return visitedType;
|
|
464
425
|
}
|
|
465
|
-
function isSchemaDefinition(node) {
|
|
466
|
-
return node.kind === 'SchemaDefinition';
|
|
467
|
-
}
|
|
468
426
|
function isWrappingTypeNode(type) {
|
|
469
427
|
return type.kind !== graphql.Kind.NAMED_TYPE;
|
|
470
428
|
}
|
|
@@ -483,10 +441,22 @@ function printTypeNode(type) {
|
|
|
483
441
|
}
|
|
484
442
|
return type.name.value;
|
|
485
443
|
}
|
|
444
|
+
(function (CompareVal) {
|
|
445
|
+
CompareVal[CompareVal["A_SMALLER_THAN_B"] = -1] = "A_SMALLER_THAN_B";
|
|
446
|
+
CompareVal[CompareVal["A_EQUALS_B"] = 0] = "A_EQUALS_B";
|
|
447
|
+
CompareVal[CompareVal["A_GREATER_THAN_B"] = 1] = "A_GREATER_THAN_B";
|
|
448
|
+
})(exports.CompareVal || (exports.CompareVal = {}));
|
|
449
|
+
function defaultStringComparator(a, b) {
|
|
450
|
+
if (a < b)
|
|
451
|
+
return exports.CompareVal.A_SMALLER_THAN_B;
|
|
452
|
+
if (a > b)
|
|
453
|
+
return exports.CompareVal.A_GREATER_THAN_B;
|
|
454
|
+
return exports.CompareVal.A_EQUALS_B;
|
|
455
|
+
}
|
|
486
456
|
|
|
487
|
-
function fieldAlreadyExists(fieldsArr, otherField) {
|
|
457
|
+
function fieldAlreadyExists(fieldsArr, otherField, config) {
|
|
488
458
|
const result = fieldsArr.find(field => field.name.value === otherField.name.value);
|
|
489
|
-
if (result) {
|
|
459
|
+
if (result && !(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
490
460
|
const t1 = extractType(result.type);
|
|
491
461
|
const t2 = extractType(otherField.type);
|
|
492
462
|
if (t1.name.value !== t2.name.value) {
|
|
@@ -498,16 +468,18 @@ function fieldAlreadyExists(fieldsArr, otherField) {
|
|
|
498
468
|
function mergeFields(type, f1, f2, config) {
|
|
499
469
|
const result = [...f2];
|
|
500
470
|
for (const field of f1) {
|
|
501
|
-
if (fieldAlreadyExists(result, field)) {
|
|
471
|
+
if (fieldAlreadyExists(result, field, config)) {
|
|
502
472
|
const existing = result.find((f) => f.name.value === field.name.value);
|
|
503
|
-
if (config
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
473
|
+
if (!(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
|
|
474
|
+
if (config === null || config === void 0 ? void 0 : config.throwOnConflict) {
|
|
475
|
+
preventConflicts(type, existing, field, false);
|
|
476
|
+
}
|
|
477
|
+
else {
|
|
478
|
+
preventConflicts(type, existing, field, true);
|
|
479
|
+
}
|
|
480
|
+
if (isNonNullTypeNode(field.type) && !isNonNullTypeNode(existing.type)) {
|
|
481
|
+
existing.type = field.type;
|
|
482
|
+
}
|
|
511
483
|
}
|
|
512
484
|
existing.arguments = mergeArguments(field['arguments'] || [], existing.arguments || [], config);
|
|
513
485
|
existing.directives = mergeDirectives(field.directives, existing.directives, config);
|
|
@@ -697,43 +669,95 @@ function mergeUnion(first, second, config) {
|
|
|
697
669
|
: first;
|
|
698
670
|
}
|
|
699
671
|
|
|
672
|
+
const operationTypeDefinitionNodeTypeRootTypeMap = {
|
|
673
|
+
query: 'Query',
|
|
674
|
+
mutation: 'Mutation',
|
|
675
|
+
subscription: 'Subscription',
|
|
676
|
+
};
|
|
677
|
+
function mergeOperationTypes(opNodeList = [], existingOpNodeList = []) {
|
|
678
|
+
const finalOpNodeList = [];
|
|
679
|
+
for (const opNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
680
|
+
const opNode = opNodeList.find(n => n.operation === opNodeType) || existingOpNodeList.find(n => n.operation === opNodeType);
|
|
681
|
+
if (opNode) {
|
|
682
|
+
finalOpNodeList.push(opNode);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return finalOpNodeList;
|
|
686
|
+
}
|
|
687
|
+
function mergeSchemaDefs(node, existingNode, config) {
|
|
688
|
+
if (existingNode) {
|
|
689
|
+
return {
|
|
690
|
+
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
|
|
691
|
+
node.kind === graphql.Kind.SCHEMA_DEFINITION ||
|
|
692
|
+
existingNode.kind === graphql.Kind.SCHEMA_DEFINITION
|
|
693
|
+
? graphql.Kind.SCHEMA_DEFINITION
|
|
694
|
+
: graphql.Kind.SCHEMA_EXTENSION,
|
|
695
|
+
description: node['description'] || existingNode['description'],
|
|
696
|
+
directives: mergeDirectives(node.directives, existingNode.directives, config),
|
|
697
|
+
operationTypes: mergeOperationTypes(node.operationTypes, existingNode.operationTypes),
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
return ((config === null || config === void 0 ? void 0 : config.convertExtensions)
|
|
701
|
+
? {
|
|
702
|
+
...node,
|
|
703
|
+
kind: graphql.Kind.SCHEMA_EXTENSION,
|
|
704
|
+
}
|
|
705
|
+
: node);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
function isNamedDefinitionNode(definitionNode) {
|
|
709
|
+
return 'name' in definitionNode;
|
|
710
|
+
}
|
|
711
|
+
const schemaDefSymbol = Symbol('schemaDefSymbol');
|
|
700
712
|
function mergeGraphQLNodes(nodes, config) {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
713
|
+
var _a, _b;
|
|
714
|
+
const mergedResultMap = {};
|
|
715
|
+
for (const nodeDefinition of nodes) {
|
|
716
|
+
if (isNamedDefinitionNode(nodeDefinition)) {
|
|
717
|
+
const name = nodeDefinition.name.value;
|
|
718
|
+
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
|
|
719
|
+
collectComment(nodeDefinition);
|
|
707
720
|
}
|
|
708
|
-
if (config
|
|
709
|
-
|
|
710
|
-
(config.exclusions.includes(name + '.*') || config.exclusions.includes(name))) {
|
|
711
|
-
delete prev[name];
|
|
721
|
+
if (((_a = config === null || config === void 0 ? void 0 : config.exclusions) === null || _a === void 0 ? void 0 : _a.includes(name + '.*')) || ((_b = config === null || config === void 0 ? void 0 : config.exclusions) === null || _b === void 0 ? void 0 : _b.includes(name))) {
|
|
722
|
+
delete mergedResultMap[name];
|
|
712
723
|
}
|
|
713
|
-
else
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
724
|
+
else {
|
|
725
|
+
switch (nodeDefinition.kind) {
|
|
726
|
+
case graphql.Kind.OBJECT_TYPE_DEFINITION:
|
|
727
|
+
case graphql.Kind.OBJECT_TYPE_EXTENSION:
|
|
728
|
+
mergedResultMap[name] = mergeType(nodeDefinition, mergedResultMap[name], config);
|
|
729
|
+
break;
|
|
730
|
+
case graphql.Kind.ENUM_TYPE_DEFINITION:
|
|
731
|
+
case graphql.Kind.ENUM_TYPE_EXTENSION:
|
|
732
|
+
mergedResultMap[name] = mergeEnum(nodeDefinition, mergedResultMap[name], config);
|
|
733
|
+
break;
|
|
734
|
+
case graphql.Kind.UNION_TYPE_DEFINITION:
|
|
735
|
+
case graphql.Kind.UNION_TYPE_EXTENSION:
|
|
736
|
+
mergedResultMap[name] = mergeUnion(nodeDefinition, mergedResultMap[name], config);
|
|
737
|
+
break;
|
|
738
|
+
case graphql.Kind.SCALAR_TYPE_DEFINITION:
|
|
739
|
+
case graphql.Kind.SCALAR_TYPE_EXTENSION:
|
|
740
|
+
mergedResultMap[name] = mergeScalar(nodeDefinition, mergedResultMap[name], config);
|
|
741
|
+
break;
|
|
742
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
743
|
+
case graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION:
|
|
744
|
+
mergedResultMap[name] = mergeInputType(nodeDefinition, mergedResultMap[name], config);
|
|
745
|
+
break;
|
|
746
|
+
case graphql.Kind.INTERFACE_TYPE_DEFINITION:
|
|
747
|
+
case graphql.Kind.INTERFACE_TYPE_EXTENSION:
|
|
748
|
+
mergedResultMap[name] = mergeInterface(nodeDefinition, mergedResultMap[name], config);
|
|
749
|
+
break;
|
|
750
|
+
case graphql.Kind.DIRECTIVE_DEFINITION:
|
|
751
|
+
mergedResultMap[name] = mergeDirective(nodeDefinition, mergedResultMap[name]);
|
|
752
|
+
break;
|
|
753
|
+
}
|
|
733
754
|
}
|
|
734
755
|
}
|
|
735
|
-
|
|
736
|
-
|
|
756
|
+
else if (nodeDefinition.kind === graphql.Kind.SCHEMA_DEFINITION || nodeDefinition.kind === graphql.Kind.SCHEMA_EXTENSION) {
|
|
757
|
+
mergedResultMap[schemaDefSymbol] = mergeSchemaDefs(nodeDefinition, mergedResultMap[schemaDefSymbol], config);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return mergedResultMap;
|
|
737
761
|
}
|
|
738
762
|
|
|
739
763
|
function mergeTypeDefs(types, config) {
|
|
@@ -758,58 +782,86 @@ function mergeTypeDefs(types, config) {
|
|
|
758
782
|
resetComments();
|
|
759
783
|
return result;
|
|
760
784
|
}
|
|
785
|
+
function visitTypeSources(types, allNodes) {
|
|
786
|
+
for (const type of types) {
|
|
787
|
+
if (type) {
|
|
788
|
+
if (Array.isArray(type)) {
|
|
789
|
+
visitTypeSources(types, allNodes);
|
|
790
|
+
}
|
|
791
|
+
else if (graphql.isSchema(type)) {
|
|
792
|
+
const documentNode = utils.getDocumentNodeFromSchema(type);
|
|
793
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
794
|
+
}
|
|
795
|
+
else if (isStringTypes(type) || isSourceTypes(type)) {
|
|
796
|
+
const documentNode = graphql.parse(type);
|
|
797
|
+
visitTypeSources(documentNode.definitions, allNodes);
|
|
798
|
+
}
|
|
799
|
+
else if (graphql.isDefinitionNode(type)) {
|
|
800
|
+
allNodes.push(type);
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
visitTypeSources(type.definitions, allNodes);
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
761
808
|
function mergeGraphQLTypes(types, config) {
|
|
809
|
+
var _a, _b;
|
|
762
810
|
resetComments();
|
|
763
|
-
const allNodes =
|
|
764
|
-
|
|
765
|
-
if (Array.isArray(type)) {
|
|
766
|
-
type = mergeTypeDefs(type);
|
|
767
|
-
}
|
|
768
|
-
if (graphql.isSchema(type)) {
|
|
769
|
-
return utils.getDocumentNodeFromSchema(type);
|
|
770
|
-
}
|
|
771
|
-
else if (isStringTypes(type) || isSourceTypes(type)) {
|
|
772
|
-
return graphql.parse(type);
|
|
773
|
-
}
|
|
774
|
-
return type;
|
|
775
|
-
})
|
|
776
|
-
.map(ast => ast.definitions)
|
|
777
|
-
.reduce((defs, newDef = []) => [...defs, ...newDef], []);
|
|
778
|
-
// XXX: right now we don't handle multiple schema definitions
|
|
779
|
-
let schemaDef = allNodes.filter(isSchemaDefinition).reduce((def, node) => {
|
|
780
|
-
node.operationTypes
|
|
781
|
-
.filter(op => op.type.name.value)
|
|
782
|
-
.forEach(op => {
|
|
783
|
-
def[op.operation] = op.type.name.value;
|
|
784
|
-
});
|
|
785
|
-
return def;
|
|
786
|
-
}, {
|
|
787
|
-
query: null,
|
|
788
|
-
mutation: null,
|
|
789
|
-
subscription: null,
|
|
790
|
-
});
|
|
811
|
+
const allNodes = [];
|
|
812
|
+
visitTypeSources(types, allNodes);
|
|
791
813
|
const mergedNodes = mergeGraphQLNodes(allNodes, config);
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
814
|
+
// XXX: right now we don't handle multiple schema definitions
|
|
815
|
+
let schemaDef = mergedNodes[schemaDefSymbol] || {
|
|
816
|
+
kind: graphql.Kind.SCHEMA_DEFINITION,
|
|
817
|
+
operationTypes: [],
|
|
818
|
+
};
|
|
819
|
+
if (config === null || config === void 0 ? void 0 : config.useSchemaDefinition) {
|
|
820
|
+
const operationTypes = schemaDef.operationTypes;
|
|
821
|
+
for (const opTypeDefNodeType in operationTypeDefinitionNodeTypeRootTypeMap) {
|
|
822
|
+
const opTypeDefNode = operationTypes.find(operationType => operationType.operation === opTypeDefNodeType);
|
|
823
|
+
if (!opTypeDefNode) {
|
|
824
|
+
const existingPossibleRootType = mergedNodes[operationTypeDefinitionNodeTypeRootTypeMap[opTypeDefNodeType]];
|
|
825
|
+
if (existingPossibleRootType) {
|
|
826
|
+
operationTypes.push({
|
|
827
|
+
kind: graphql.Kind.OPERATION_TYPE_DEFINITION,
|
|
828
|
+
type: {
|
|
829
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
830
|
+
name: existingPossibleRootType.name,
|
|
831
|
+
},
|
|
832
|
+
operation: opTypeDefNodeType,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
795
837
|
}
|
|
796
|
-
if (config
|
|
797
|
-
const queryType = schemaDef.query ? schemaDef.query : allTypes.find(t => t === 'Query');
|
|
798
|
-
const mutationType = schemaDef.mutation ? schemaDef.mutation : allTypes.find(t => t === 'Mutation');
|
|
799
|
-
const subscriptionType = schemaDef.subscription ? schemaDef.subscription : allTypes.find(t => t === 'Subscription');
|
|
838
|
+
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)) {
|
|
800
839
|
schemaDef = {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
840
|
+
kind: graphql.Kind.SCHEMA_DEFINITION,
|
|
841
|
+
operationTypes: [
|
|
842
|
+
{
|
|
843
|
+
kind: graphql.Kind.OPERATION_TYPE_DEFINITION,
|
|
844
|
+
operation: 'query',
|
|
845
|
+
type: {
|
|
846
|
+
kind: graphql.Kind.NAMED_TYPE,
|
|
847
|
+
name: {
|
|
848
|
+
kind: graphql.Kind.NAME,
|
|
849
|
+
value: 'Query',
|
|
850
|
+
},
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
],
|
|
804
854
|
};
|
|
805
855
|
}
|
|
806
|
-
const
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
856
|
+
const mergedNodeDefinitions = Object.values(mergedNodes);
|
|
857
|
+
if ((_b = schemaDef.operationTypes) === null || _b === void 0 ? void 0 : _b.length) {
|
|
858
|
+
mergedNodeDefinitions.push(schemaDef);
|
|
859
|
+
}
|
|
860
|
+
if (config === null || config === void 0 ? void 0 : config.sort) {
|
|
861
|
+
const sortFn = typeof config.sort === 'function' ? config.sort : defaultStringComparator;
|
|
862
|
+
mergedNodeDefinitions.sort((a, b) => { var _a, _b; return sortFn((_a = a.name) === null || _a === void 0 ? void 0 : _a.value, (_b = b.name) === null || _b === void 0 ? void 0 : _b.value); });
|
|
811
863
|
}
|
|
812
|
-
return
|
|
864
|
+
return mergedNodeDefinitions;
|
|
813
865
|
}
|
|
814
866
|
|
|
815
867
|
function travelSchemaPossibleExtensions(schema, hooks) {
|
|
@@ -1006,24 +1058,12 @@ function makeSchema({ resolvers, typeDefs, extensions, }, config) {
|
|
|
1006
1058
|
|
|
1007
1059
|
exports.applyExtensions = applyExtensions;
|
|
1008
1060
|
exports.collectComment = collectComment;
|
|
1061
|
+
exports.defaultStringComparator = defaultStringComparator;
|
|
1009
1062
|
exports.extractExtensionsFromSchema = extractExtensionsFromSchema;
|
|
1010
1063
|
exports.extractType = extractType;
|
|
1011
|
-
exports.isGraphQLDirective = isGraphQLDirective;
|
|
1012
|
-
exports.isGraphQLEnum = isGraphQLEnum;
|
|
1013
|
-
exports.isGraphQLEnumExtension = isGraphQLEnumExtension;
|
|
1014
|
-
exports.isGraphQLInputType = isGraphQLInputType;
|
|
1015
|
-
exports.isGraphQLInputTypeExtension = isGraphQLInputTypeExtension;
|
|
1016
|
-
exports.isGraphQLInterface = isGraphQLInterface;
|
|
1017
|
-
exports.isGraphQLInterfaceExtension = isGraphQLInterfaceExtension;
|
|
1018
|
-
exports.isGraphQLScalar = isGraphQLScalar;
|
|
1019
|
-
exports.isGraphQLScalarExtension = isGraphQLScalarExtension;
|
|
1020
|
-
exports.isGraphQLType = isGraphQLType;
|
|
1021
|
-
exports.isGraphQLTypeExtension = isGraphQLTypeExtension;
|
|
1022
|
-
exports.isGraphQLUnion = isGraphQLUnion;
|
|
1023
|
-
exports.isGraphQLUnionExtension = isGraphQLUnionExtension;
|
|
1024
1064
|
exports.isListTypeNode = isListTypeNode;
|
|
1065
|
+
exports.isNamedDefinitionNode = isNamedDefinitionNode;
|
|
1025
1066
|
exports.isNonNullTypeNode = isNonNullTypeNode;
|
|
1026
|
-
exports.isSchemaDefinition = isSchemaDefinition;
|
|
1027
1067
|
exports.isSourceTypes = isSourceTypes;
|
|
1028
1068
|
exports.isStringTypes = isStringTypes;
|
|
1029
1069
|
exports.isWrappingTypeNode = isWrappingTypeNode;
|
|
@@ -1051,5 +1091,6 @@ exports.printTypeNode = printTypeNode;
|
|
|
1051
1091
|
exports.printWithComments = printWithComments;
|
|
1052
1092
|
exports.pushComment = pushComment;
|
|
1053
1093
|
exports.resetComments = resetComments;
|
|
1094
|
+
exports.schemaDefSymbol = schemaDefSymbol;
|
|
1054
1095
|
exports.travelSchemaPossibleExtensions = travelSchemaPossibleExtensions;
|
|
1055
1096
|
//# sourceMappingURL=index.cjs.js.map
|