Initialisation

Added the packages and files for the backend server
This commit is contained in:
jackbeeby
2024-12-15 17:48:45 +11:00
parent 25066e1ee8
commit b412dfe2ca
2732 changed files with 330572 additions and 0 deletions

5
node_modules/@graphql-tools/merge/README.md generated vendored Normal file
View File

@@ -0,0 +1,5 @@
Check API Reference for more information about this package;
https://www.graphql-tools.com/docs/api/modules/merge_src
You can also learn more about Schema Merging in this chapter;
https://www.graphql-tools.com/docs/schema-merging

50
node_modules/@graphql-tools/merge/cjs/extensions.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyExtensions = exports.mergeExtensions = exports.extractExtensionsFromSchema = void 0;
const utils_1 = require("@graphql-tools/utils");
var utils_2 = require("@graphql-tools/utils");
Object.defineProperty(exports, "extractExtensionsFromSchema", { enumerable: true, get: function () { return utils_2.extractExtensionsFromSchema; } });
function mergeExtensions(extensions) {
return (0, utils_1.mergeDeep)(extensions);
}
exports.mergeExtensions = mergeExtensions;
function applyExtensionObject(obj, extensions) {
if (!obj) {
return;
}
obj.extensions = (0, utils_1.mergeDeep)([obj.extensions || {}, extensions || {}]);
}
function applyExtensions(schema, extensions) {
applyExtensionObject(schema, extensions.schemaExtensions);
for (const [typeName, data] of Object.entries(extensions.types || {})) {
const type = schema.getType(typeName);
if (type) {
applyExtensionObject(type, data.extensions);
if (data.type === 'object' || data.type === 'interface') {
for (const [fieldName, fieldData] of Object.entries(data.fields)) {
const field = type.getFields()[fieldName];
if (field) {
applyExtensionObject(field, fieldData.extensions);
for (const [arg, argData] of Object.entries(fieldData.arguments)) {
applyExtensionObject(field.args.find(a => a.name === arg), argData);
}
}
}
}
else if (data.type === 'input') {
for (const [fieldName, fieldData] of Object.entries(data.fields)) {
const field = type.getFields()[fieldName];
applyExtensionObject(field, fieldData.extensions);
}
}
else if (data.type === 'enum') {
for (const [valueName, valueData] of Object.entries(data.values)) {
const value = type.getValue(valueName);
applyExtensionObject(value, valueData);
}
}
}
}
return schema;
}
exports.applyExtensions = applyExtensions;

6
node_modules/@graphql-tools/merge/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./merge-resolvers.js"), exports);
tslib_1.__exportStar(require("./typedefs-mergers/index.js"), exports);
tslib_1.__exportStar(require("./extensions.js"), exports);

View File

@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeResolvers = void 0;
const utils_1 = require("@graphql-tools/utils");
/**
* Deep merges multiple resolver definition objects into a single definition.
* @param resolversDefinitions Resolver definitions to be merged
* @param options Additional options
*
* ```js
* const { mergeResolvers } = require('@graphql-tools/merge');
* const clientResolver = require('./clientResolver');
* const productResolver = require('./productResolver');
*
* const resolvers = mergeResolvers([
* clientResolver,
* productResolver,
* ]);
* ```
*
* If you don't want to manually create the array of resolver objects, you can
* also use this function along with loadFiles:
*
* ```js
* const path = require('path');
* const { mergeResolvers } = require('@graphql-tools/merge');
* const { loadFilesSync } = require('@graphql-tools/load-files');
*
* const resolversArray = loadFilesSync(path.join(__dirname, './resolvers'));
*
* const resolvers = mergeResolvers(resolversArray)
* ```
*/
function mergeResolvers(resolversDefinitions, options) {
if (!resolversDefinitions || (Array.isArray(resolversDefinitions) && resolversDefinitions.length === 0)) {
return {};
}
if (!Array.isArray(resolversDefinitions)) {
return resolversDefinitions;
}
if (resolversDefinitions.length === 1) {
return resolversDefinitions[0] || {};
}
const resolvers = new Array();
for (let resolversDefinition of resolversDefinitions) {
if (Array.isArray(resolversDefinition)) {
resolversDefinition = mergeResolvers(resolversDefinition);
}
if (typeof resolversDefinition === 'object' && resolversDefinition) {
resolvers.push(resolversDefinition);
}
}
const result = (0, utils_1.mergeDeep)(resolvers, true);
if (options === null || options === void 0 ? void 0 : options.exclusions) {
for (const exclusion of options.exclusions) {
const [typeName, fieldName] = exclusion.split('.');
if (!fieldName || fieldName === '*') {
delete result[typeName];
}
else if (result[typeName]) {
delete result[typeName][fieldName];
}
}
}
return result;
}
exports.mergeResolvers = mergeResolvers;

1
node_modules/@graphql-tools/merge/cjs/package.json generated vendored Normal file
View File

@@ -0,0 +1 @@
{"type":"commonjs"}

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeArguments = void 0;
const utils_1 = require("@graphql-tools/utils");
function mergeArguments(args1, args2, config) {
const result = deduplicateArguments([...args2, ...args1].filter(utils_1.isSome), config);
if (config && config.sort) {
result.sort(utils_1.compareNodes);
}
return result;
}
exports.mergeArguments = mergeArguments;
function deduplicateArguments(args, config) {
return args.reduce((acc, current) => {
const dupIndex = acc.findIndex(arg => arg.name.value === current.name.value);
if (dupIndex === -1) {
return acc.concat([current]);
}
else if (!(config === null || config === void 0 ? void 0 : config.reverseArguments)) {
acc[dupIndex] = current;
}
return acc;
}, []);
}

View File

@@ -0,0 +1,104 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeDirective = exports.mergeDirectives = void 0;
const graphql_1 = require("graphql");
const utils_1 = require("@graphql-tools/utils");
function directiveAlreadyExists(directivesArr, otherDirective) {
return !!directivesArr.find(directive => directive.name.value === otherDirective.name.value);
}
function isRepeatableDirective(directive, directives) {
var _a;
return !!((_a = directives === null || directives === void 0 ? void 0 : directives[directive.name.value]) === null || _a === void 0 ? void 0 : _a.repeatable);
}
function nameAlreadyExists(name, namesArr) {
return namesArr.some(({ value }) => value === name.value);
}
function mergeArguments(a1, a2) {
const result = [...a2];
for (const argument of a1) {
const existingIndex = result.findIndex(a => a.name.value === argument.name.value);
if (existingIndex > -1) {
const existingArg = result[existingIndex];
if (existingArg.value.kind === 'ListValue') {
const source = existingArg.value.values;
const target = argument.value.values;
// merge values of two lists
existingArg.value.values = deduplicateLists(source, target, (targetVal, source) => {
const value = targetVal.value;
return !value || !source.some((sourceVal) => sourceVal.value === value);
});
}
else {
existingArg.value = argument.value;
}
}
else {
result.push(argument);
}
}
return result;
}
function deduplicateDirectives(directives, definitions) {
return directives
.map((directive, i, all) => {
const firstAt = all.findIndex(d => d.name.value === directive.name.value);
if (firstAt !== i && !isRepeatableDirective(directive, definitions)) {
const dup = all[firstAt];
directive.arguments = mergeArguments(directive.arguments, dup.arguments);
return null;
}
return directive;
})
.filter(utils_1.isSome);
}
function mergeDirectives(d1 = [], d2 = [], config, directives) {
const reverseOrder = config && config.reverseDirectives;
const asNext = reverseOrder ? d1 : d2;
const asFirst = reverseOrder ? d2 : d1;
const result = deduplicateDirectives([...asNext], directives);
for (const directive of asFirst) {
if (directiveAlreadyExists(result, directive) && !isRepeatableDirective(directive, directives)) {
const existingDirectiveIndex = result.findIndex(d => d.name.value === directive.name.value);
const existingDirective = result[existingDirectiveIndex];
result[existingDirectiveIndex].arguments = mergeArguments(directive.arguments || [], existingDirective.arguments || []);
}
else {
result.push(directive);
}
}
return result;
}
exports.mergeDirectives = mergeDirectives;
function validateInputs(node, existingNode) {
const printedNode = (0, graphql_1.print)({
...node,
description: undefined,
});
const printedExistingNode = (0, graphql_1.print)({
...existingNode,
description: undefined,
});
// eslint-disable-next-line
const leaveInputs = new RegExp('(directive @w*d*)|( on .*$)', 'g');
const sameArguments = printedNode.replace(leaveInputs, '') === printedExistingNode.replace(leaveInputs, '');
if (!sameArguments) {
throw new Error(`Unable to merge GraphQL directive "${node.name.value}". \nExisting directive: \n\t${printedExistingNode} \nReceived directive: \n\t${printedNode}`);
}
}
function mergeDirective(node, existingNode) {
if (existingNode) {
validateInputs(node, existingNode);
return {
...node,
locations: [
...existingNode.locations,
...node.locations.filter(name => !nameAlreadyExists(name, existingNode.locations)),
],
};
}
return node;
}
exports.mergeDirective = mergeDirective;
function deduplicateLists(source, target, filterFn) {
return source.concat(target.filter(val => filterFn(val, source)));
}

View File

@@ -0,0 +1,40 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeEnumValues = void 0;
const directives_js_1 = require("./directives.js");
const utils_1 = require("@graphql-tools/utils");
function mergeEnumValues(first, second, config, directives) {
if (config === null || config === void 0 ? void 0 : config.consistentEnumMerge) {
const reversed = [];
if (first) {
reversed.push(...first);
}
first = second;
second = reversed;
}
const enumValueMap = new Map();
if (first) {
for (const firstValue of first) {
enumValueMap.set(firstValue.name.value, firstValue);
}
}
if (second) {
for (const secondValue of second) {
const enumValue = secondValue.name.value;
if (enumValueMap.has(enumValue)) {
const firstValue = enumValueMap.get(enumValue);
firstValue.description = secondValue.description || firstValue.description;
firstValue.directives = (0, directives_js_1.mergeDirectives)(secondValue.directives, firstValue.directives, directives);
}
else {
enumValueMap.set(enumValue, secondValue);
}
}
}
const result = [...enumValueMap.values()];
if (config && config.sort) {
result.sort(utils_1.compareNodes);
}
return result;
}
exports.mergeEnumValues = mergeEnumValues;

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeEnum = void 0;
const graphql_1 = require("graphql");
const directives_js_1 = require("./directives.js");
const enum_values_js_1 = require("./enum-values.js");
function mergeEnum(e1, e2, config, directives) {
if (e2) {
return {
name: e1.name,
description: e1['description'] || e2['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) || e1.kind === 'EnumTypeDefinition' || e2.kind === 'EnumTypeDefinition'
? 'EnumTypeDefinition'
: 'EnumTypeExtension',
loc: e1.loc,
directives: (0, directives_js_1.mergeDirectives)(e1.directives, e2.directives, config, directives),
values: (0, enum_values_js_1.mergeEnumValues)(e1.values, e2.values, config),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...e1,
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
}
: e1;
}
exports.mergeEnum = mergeEnum;

View File

@@ -0,0 +1,81 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeFields = void 0;
const utils_js_1 = require("./utils.js");
const directives_js_1 = require("./directives.js");
const utils_1 = require("@graphql-tools/utils");
const arguments_js_1 = require("./arguments.js");
function fieldAlreadyExists(fieldsArr, otherField) {
const resultIndex = fieldsArr.findIndex(field => field.name.value === otherField.name.value);
return [resultIndex > -1 ? fieldsArr[resultIndex] : null, resultIndex];
}
function mergeFields(type, f1, f2, config, directives) {
const result = [];
if (f2 != null) {
result.push(...f2);
}
if (f1 != null) {
for (const field of f1) {
const [existing, existingIndex] = fieldAlreadyExists(result, field);
if (existing && !(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
const newField = ((config === null || config === void 0 ? void 0 : config.onFieldTypeConflict) && config.onFieldTypeConflict(existing, field, type, config === null || config === void 0 ? void 0 : config.throwOnConflict)) ||
preventConflicts(type, existing, field, config === null || config === void 0 ? void 0 : config.throwOnConflict);
newField.arguments = (0, arguments_js_1.mergeArguments)(field['arguments'] || [], existing['arguments'] || [], config);
newField.directives = (0, directives_js_1.mergeDirectives)(field.directives, existing.directives, config, directives);
newField.description = field.description || existing.description;
result[existingIndex] = newField;
}
else {
result.push(field);
}
}
}
if (config && config.sort) {
result.sort(utils_1.compareNodes);
}
if (config && config.exclusions) {
const exclusions = config.exclusions;
return result.filter(field => !exclusions.includes(`${type.name.value}.${field.name.value}`));
}
return result;
}
exports.mergeFields = mergeFields;
function preventConflicts(type, a, b, ignoreNullability = false) {
const aType = (0, utils_js_1.printTypeNode)(a.type);
const bType = (0, utils_js_1.printTypeNode)(b.type);
if (aType !== bType) {
const t1 = (0, utils_js_1.extractType)(a.type);
const t2 = (0, utils_js_1.extractType)(b.type);
if (t1.name.value !== t2.name.value) {
throw new Error(`Field "${b.name.value}" already defined with a different type. Declared as "${t1.name.value}", but you tried to override with "${t2.name.value}"`);
}
if (!safeChangeForFieldType(a.type, b.type, !ignoreNullability)) {
throw new Error(`Field '${type.name.value}.${a.name.value}' changed type from '${aType}' to '${bType}'`);
}
}
if ((0, utils_js_1.isNonNullTypeNode)(b.type) && !(0, utils_js_1.isNonNullTypeNode)(a.type)) {
a.type = b.type;
}
return a;
}
function safeChangeForFieldType(oldType, newType, ignoreNullability = false) {
// both are named
if (!(0, utils_js_1.isWrappingTypeNode)(oldType) && !(0, utils_js_1.isWrappingTypeNode)(newType)) {
return oldType.toString() === newType.toString();
}
// new is non-null
if ((0, utils_js_1.isNonNullTypeNode)(newType)) {
const ofType = (0, utils_js_1.isNonNullTypeNode)(oldType) ? oldType.type : oldType;
return safeChangeForFieldType(ofType, newType.type);
}
// old is non-null
if ((0, utils_js_1.isNonNullTypeNode)(oldType)) {
return safeChangeForFieldType(newType, oldType, ignoreNullability);
}
// old is list
if ((0, utils_js_1.isListTypeNode)(oldType)) {
return (((0, utils_js_1.isListTypeNode)(newType) && safeChangeForFieldType(oldType.type, newType.type)) ||
((0, utils_js_1.isNonNullTypeNode)(newType) && safeChangeForFieldType(oldType, newType['type'])));
}
return false;
}

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./arguments.js"), exports);
tslib_1.__exportStar(require("./directives.js"), exports);
tslib_1.__exportStar(require("./enum-values.js"), exports);
tslib_1.__exportStar(require("./enum.js"), exports);
tslib_1.__exportStar(require("./fields.js"), exports);
tslib_1.__exportStar(require("./input-type.js"), exports);
tslib_1.__exportStar(require("./interface.js"), exports);
tslib_1.__exportStar(require("./merge-named-type-array.js"), exports);
tslib_1.__exportStar(require("./merge-nodes.js"), exports);
tslib_1.__exportStar(require("./merge-typedefs.js"), exports);
tslib_1.__exportStar(require("./scalar.js"), exports);
tslib_1.__exportStar(require("./type.js"), exports);
tslib_1.__exportStar(require("./union.js"), exports);
tslib_1.__exportStar(require("./utils.js"), exports);

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeInputType = void 0;
const graphql_1 = require("graphql");
const fields_js_1 = require("./fields.js");
const directives_js_1 = require("./directives.js");
function mergeInputType(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'InputObjectTypeDefinition' ||
existingNode.kind === 'InputObjectTypeDefinition'
? 'InputObjectTypeDefinition'
: 'InputObjectTypeExtension',
loc: node.loc,
fields: (0, fields_js_1.mergeFields)(node, node.fields, existingNode.fields, config),
directives: (0, directives_js_1.mergeDirectives)(node.directives, existingNode.directives, config, directives),
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL input type "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
}
: node;
}
exports.mergeInputType = mergeInputType;

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeInterface = void 0;
const graphql_1 = require("graphql");
const fields_js_1 = require("./fields.js");
const directives_js_1 = require("./directives.js");
const merge_named_type_array_js_1 = require("./merge-named-type-array.js");
function mergeInterface(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'InterfaceTypeDefinition' ||
existingNode.kind === 'InterfaceTypeDefinition'
? 'InterfaceTypeDefinition'
: 'InterfaceTypeExtension',
loc: node.loc,
fields: (0, fields_js_1.mergeFields)(node, node.fields, existingNode.fields, config),
directives: (0, directives_js_1.mergeDirectives)(node.directives, existingNode.directives, config, directives),
interfaces: node['interfaces']
? (0, merge_named_type_array_js_1.mergeNamedTypeArray)(node['interfaces'], existingNode['interfaces'], config)
: undefined,
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL interface "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
}
: node;
}
exports.mergeInterface = mergeInterface;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeNamedTypeArray = void 0;
const utils_1 = require("@graphql-tools/utils");
function alreadyExists(arr, other) {
return !!arr.find(i => i.name.value === other.name.value);
}
function mergeNamedTypeArray(first = [], second = [], config = {}) {
const result = [...second, ...first.filter(d => !alreadyExists(second, d))];
if (config && config.sort) {
result.sort(utils_1.compareNodes);
}
return result;
}
exports.mergeNamedTypeArray = mergeNamedTypeArray;

View File

@@ -0,0 +1,72 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeGraphQLNodes = exports.isNamedDefinitionNode = exports.schemaDefSymbol = void 0;
const graphql_1 = require("graphql");
const type_js_1 = require("./type.js");
const enum_js_1 = require("./enum.js");
const scalar_js_1 = require("./scalar.js");
const union_js_1 = require("./union.js");
const input_type_js_1 = require("./input-type.js");
const interface_js_1 = require("./interface.js");
const directives_js_1 = require("./directives.js");
const schema_def_js_1 = require("./schema-def.js");
const utils_1 = require("@graphql-tools/utils");
exports.schemaDefSymbol = 'SCHEMA_DEF_SYMBOL';
function isNamedDefinitionNode(definitionNode) {
return 'name' in definitionNode;
}
exports.isNamedDefinitionNode = isNamedDefinitionNode;
function mergeGraphQLNodes(nodes, config, directives = {}) {
var _a, _b, _c;
const mergedResultMap = directives;
for (const nodeDefinition of nodes) {
if (isNamedDefinitionNode(nodeDefinition)) {
const name = (_a = nodeDefinition.name) === null || _a === void 0 ? void 0 : _a.value;
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
(0, utils_1.collectComment)(nodeDefinition);
}
if (name == null) {
continue;
}
if (((_b = config === null || config === void 0 ? void 0 : config.exclusions) === null || _b === void 0 ? void 0 : _b.includes(name + '.*')) || ((_c = config === null || config === void 0 ? void 0 : config.exclusions) === null || _c === void 0 ? void 0 : _c.includes(name))) {
delete mergedResultMap[name];
}
else {
switch (nodeDefinition.kind) {
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
case graphql_1.Kind.OBJECT_TYPE_EXTENSION:
mergedResultMap[name] = (0, type_js_1.mergeType)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.ENUM_TYPE_DEFINITION:
case graphql_1.Kind.ENUM_TYPE_EXTENSION:
mergedResultMap[name] = (0, enum_js_1.mergeEnum)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.UNION_TYPE_DEFINITION:
case graphql_1.Kind.UNION_TYPE_EXTENSION:
mergedResultMap[name] = (0, union_js_1.mergeUnion)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.SCALAR_TYPE_DEFINITION:
case graphql_1.Kind.SCALAR_TYPE_EXTENSION:
mergedResultMap[name] = (0, scalar_js_1.mergeScalar)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
case graphql_1.Kind.INPUT_OBJECT_TYPE_EXTENSION:
mergedResultMap[name] = (0, input_type_js_1.mergeInputType)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
case graphql_1.Kind.INTERFACE_TYPE_EXTENSION:
mergedResultMap[name] = (0, interface_js_1.mergeInterface)(nodeDefinition, mergedResultMap[name], config, directives);
break;
case graphql_1.Kind.DIRECTIVE_DEFINITION:
mergedResultMap[name] = (0, directives_js_1.mergeDirective)(nodeDefinition, mergedResultMap[name]);
break;
}
}
}
else if (nodeDefinition.kind === graphql_1.Kind.SCHEMA_DEFINITION || nodeDefinition.kind === graphql_1.Kind.SCHEMA_EXTENSION) {
mergedResultMap[exports.schemaDefSymbol] = (0, schema_def_js_1.mergeSchemaDefs)(nodeDefinition, mergedResultMap[exports.schemaDefSymbol], config);
}
}
return mergedResultMap;
}
exports.mergeGraphQLNodes = mergeGraphQLNodes;

View File

@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeGraphQLTypes = exports.mergeTypeDefs = void 0;
const graphql_1 = require("graphql");
const utils_js_1 = require("./utils.js");
const merge_nodes_js_1 = require("./merge-nodes.js");
const utils_1 = require("@graphql-tools/utils");
const schema_def_js_1 = require("./schema-def.js");
function mergeTypeDefs(typeSource, config) {
(0, utils_1.resetComments)();
const doc = {
kind: graphql_1.Kind.DOCUMENT,
definitions: mergeGraphQLTypes(typeSource, {
useSchemaDefinition: true,
forceSchemaDefinition: false,
throwOnConflict: false,
commentDescriptions: false,
...config,
}),
};
let result;
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
result = (0, utils_1.printWithComments)(doc);
}
else {
result = doc;
}
(0, utils_1.resetComments)();
return result;
}
exports.mergeTypeDefs = mergeTypeDefs;
function visitTypeSources(typeSource, options, allDirectives = [], allNodes = [], visitedTypeSources = new Set()) {
if (typeSource && !visitedTypeSources.has(typeSource)) {
visitedTypeSources.add(typeSource);
if (typeof typeSource === 'function') {
visitTypeSources(typeSource(), options, allDirectives, allNodes, visitedTypeSources);
}
else if (Array.isArray(typeSource)) {
for (const type of typeSource) {
visitTypeSources(type, options, allDirectives, allNodes, visitedTypeSources);
}
}
else if ((0, graphql_1.isSchema)(typeSource)) {
const documentNode = (0, utils_1.getDocumentNodeFromSchema)(typeSource, options);
visitTypeSources(documentNode.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else if ((0, utils_js_1.isStringTypes)(typeSource) || (0, utils_js_1.isSourceTypes)(typeSource)) {
const documentNode = (0, graphql_1.parse)(typeSource, options);
visitTypeSources(documentNode.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else if (typeof typeSource === 'object' && (0, graphql_1.isDefinitionNode)(typeSource)) {
if (typeSource.kind === graphql_1.Kind.DIRECTIVE_DEFINITION) {
allDirectives.push(typeSource);
}
else {
allNodes.push(typeSource);
}
}
else if ((0, utils_1.isDocumentNode)(typeSource)) {
visitTypeSources(typeSource.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else {
throw new Error(`typeDefs must contain only strings, documents, schemas, or functions, got ${typeof typeSource}`);
}
}
return { allDirectives, allNodes };
}
function mergeGraphQLTypes(typeSource, config) {
var _a, _b, _c;
(0, utils_1.resetComments)();
const { allDirectives, allNodes } = visitTypeSources(typeSource, config);
const mergedDirectives = (0, merge_nodes_js_1.mergeGraphQLNodes)(allDirectives, config);
const mergedNodes = (0, merge_nodes_js_1.mergeGraphQLNodes)(allNodes, config, mergedDirectives);
if (config === null || config === void 0 ? void 0 : config.useSchemaDefinition) {
// XXX: right now we don't handle multiple schema definitions
const schemaDef = mergedNodes[merge_nodes_js_1.schemaDefSymbol] || {
kind: graphql_1.Kind.SCHEMA_DEFINITION,
operationTypes: [],
};
const operationTypes = schemaDef.operationTypes;
for (const opTypeDefNodeType in schema_def_js_1.DEFAULT_OPERATION_TYPE_NAME_MAP) {
const opTypeDefNode = operationTypes.find(operationType => operationType.operation === opTypeDefNodeType);
if (!opTypeDefNode) {
const possibleRootTypeName = schema_def_js_1.DEFAULT_OPERATION_TYPE_NAME_MAP[opTypeDefNodeType];
const existingPossibleRootType = mergedNodes[possibleRootTypeName];
if (existingPossibleRootType != null && existingPossibleRootType.name != null) {
operationTypes.push({
kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
type: {
kind: graphql_1.Kind.NAMED_TYPE,
name: existingPossibleRootType.name,
},
operation: opTypeDefNodeType,
});
}
}
}
if (((_a = schemaDef === null || schemaDef === void 0 ? void 0 : schemaDef.operationTypes) === null || _a === void 0 ? void 0 : _a.length) != null && schemaDef.operationTypes.length > 0) {
mergedNodes[merge_nodes_js_1.schemaDefSymbol] = schemaDef;
}
}
if ((config === null || config === void 0 ? void 0 : config.forceSchemaDefinition) && !((_c = (_b = mergedNodes[merge_nodes_js_1.schemaDefSymbol]) === null || _b === void 0 ? void 0 : _b.operationTypes) === null || _c === void 0 ? void 0 : _c.length)) {
mergedNodes[merge_nodes_js_1.schemaDefSymbol] = {
kind: graphql_1.Kind.SCHEMA_DEFINITION,
operationTypes: [
{
kind: graphql_1.Kind.OPERATION_TYPE_DEFINITION,
operation: 'query',
type: {
kind: graphql_1.Kind.NAMED_TYPE,
name: {
kind: graphql_1.Kind.NAME,
value: 'Query',
},
},
},
],
};
}
const mergedNodeDefinitions = Object.values(mergedNodes);
if (config === null || config === void 0 ? void 0 : config.sort) {
const sortFn = typeof config.sort === 'function' ? config.sort : utils_js_1.defaultStringComparator;
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); });
}
return mergedNodeDefinitions;
}
exports.mergeGraphQLTypes = mergeGraphQLTypes;

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeScalar = void 0;
const graphql_1 = require("graphql");
const directives_js_1 = require("./directives.js");
function mergeScalar(node, existingNode, config, directives) {
if (existingNode) {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'ScalarTypeDefinition' ||
existingNode.kind === 'ScalarTypeDefinition'
? 'ScalarTypeDefinition'
: 'ScalarTypeExtension',
loc: node.loc,
directives: (0, directives_js_1.mergeDirectives)(node.directives, existingNode.directives, config, directives),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
}
: node;
}
exports.mergeScalar = mergeScalar;

View File

@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeSchemaDefs = exports.DEFAULT_OPERATION_TYPE_NAME_MAP = void 0;
const graphql_1 = require("graphql");
const directives_js_1 = require("./directives.js");
exports.DEFAULT_OPERATION_TYPE_NAME_MAP = {
query: 'Query',
mutation: 'Mutation',
subscription: 'Subscription',
};
function mergeOperationTypes(opNodeList = [], existingOpNodeList = []) {
const finalOpNodeList = [];
for (const opNodeType in exports.DEFAULT_OPERATION_TYPE_NAME_MAP) {
const opNode = opNodeList.find(n => n.operation === opNodeType) || existingOpNodeList.find(n => n.operation === opNodeType);
if (opNode) {
finalOpNodeList.push(opNode);
}
}
return finalOpNodeList;
}
function mergeSchemaDefs(node, existingNode, config, directives) {
if (existingNode) {
return {
kind: node.kind === graphql_1.Kind.SCHEMA_DEFINITION || existingNode.kind === graphql_1.Kind.SCHEMA_DEFINITION
? graphql_1.Kind.SCHEMA_DEFINITION
: graphql_1.Kind.SCHEMA_EXTENSION,
description: node['description'] || existingNode['description'],
directives: (0, directives_js_1.mergeDirectives)(node.directives, existingNode.directives, config, directives),
operationTypes: mergeOperationTypes(node.operationTypes, existingNode.operationTypes),
};
}
return ((config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: graphql_1.Kind.SCHEMA_DEFINITION,
}
: node);
}
exports.mergeSchemaDefs = mergeSchemaDefs;

View File

@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeType = void 0;
const graphql_1 = require("graphql");
const fields_js_1 = require("./fields.js");
const directives_js_1 = require("./directives.js");
const merge_named_type_array_js_1 = require("./merge-named-type-array.js");
function mergeType(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'ObjectTypeDefinition' ||
existingNode.kind === 'ObjectTypeDefinition'
? 'ObjectTypeDefinition'
: 'ObjectTypeExtension',
loc: node.loc,
fields: (0, fields_js_1.mergeFields)(node, node.fields, existingNode.fields, config),
directives: (0, directives_js_1.mergeDirectives)(node.directives, existingNode.directives, config, directives),
interfaces: (0, merge_named_type_array_js_1.mergeNamedTypeArray)(node.interfaces, existingNode.interfaces, config),
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL type "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
}
: node;
}
exports.mergeType = mergeType;

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeUnion = void 0;
const graphql_1 = require("graphql");
const directives_js_1 = require("./directives.js");
const merge_named_type_array_js_1 = require("./merge-named-type-array.js");
function mergeUnion(first, second, config, directives) {
if (second) {
return {
name: first.name,
description: first['description'] || second['description'],
// ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
directives: (0, directives_js_1.mergeDirectives)(first.directives, second.directives, config, directives),
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) || first.kind === 'UnionTypeDefinition' || second.kind === 'UnionTypeDefinition'
? graphql_1.Kind.UNION_TYPE_DEFINITION
: graphql_1.Kind.UNION_TYPE_EXTENSION,
loc: first.loc,
types: (0, merge_named_type_array_js_1.mergeNamedTypeArray)(first.types, second.types, config),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...first,
kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
}
: first;
}
exports.mergeUnion = mergeUnion;

View File

@@ -0,0 +1,65 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultStringComparator = exports.CompareVal = exports.printTypeNode = exports.isNonNullTypeNode = exports.isListTypeNode = exports.isWrappingTypeNode = exports.extractType = exports.isSourceTypes = exports.isStringTypes = void 0;
const graphql_1 = require("graphql");
function isStringTypes(types) {
return typeof types === 'string';
}
exports.isStringTypes = isStringTypes;
function isSourceTypes(types) {
return types instanceof graphql_1.Source;
}
exports.isSourceTypes = isSourceTypes;
function extractType(type) {
let visitedType = type;
while (visitedType.kind === graphql_1.Kind.LIST_TYPE || visitedType.kind === 'NonNullType') {
visitedType = visitedType.type;
}
return visitedType;
}
exports.extractType = extractType;
function isWrappingTypeNode(type) {
return type.kind !== graphql_1.Kind.NAMED_TYPE;
}
exports.isWrappingTypeNode = isWrappingTypeNode;
function isListTypeNode(type) {
return type.kind === graphql_1.Kind.LIST_TYPE;
}
exports.isListTypeNode = isListTypeNode;
function isNonNullTypeNode(type) {
return type.kind === graphql_1.Kind.NON_NULL_TYPE;
}
exports.isNonNullTypeNode = isNonNullTypeNode;
function printTypeNode(type) {
if (isListTypeNode(type)) {
return `[${printTypeNode(type.type)}]`;
}
if (isNonNullTypeNode(type)) {
return `${printTypeNode(type.type)}!`;
}
return type.name.value;
}
exports.printTypeNode = printTypeNode;
var CompareVal;
(function (CompareVal) {
CompareVal[CompareVal["A_SMALLER_THAN_B"] = -1] = "A_SMALLER_THAN_B";
CompareVal[CompareVal["A_EQUALS_B"] = 0] = "A_EQUALS_B";
CompareVal[CompareVal["A_GREATER_THAN_B"] = 1] = "A_GREATER_THAN_B";
})(CompareVal = exports.CompareVal || (exports.CompareVal = {}));
function defaultStringComparator(a, b) {
if (a == null && b == null) {
return CompareVal.A_EQUALS_B;
}
if (a == null) {
return CompareVal.A_SMALLER_THAN_B;
}
if (b == null) {
return CompareVal.A_GREATER_THAN_B;
}
if (a < b)
return CompareVal.A_SMALLER_THAN_B;
if (a > b)
return CompareVal.A_GREATER_THAN_B;
return CompareVal.A_EQUALS_B;
}
exports.defaultStringComparator = defaultStringComparator;

44
node_modules/@graphql-tools/merge/esm/extensions.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import { mergeDeep } from '@graphql-tools/utils';
export { extractExtensionsFromSchema } from '@graphql-tools/utils';
export function mergeExtensions(extensions) {
return mergeDeep(extensions);
}
function applyExtensionObject(obj, extensions) {
if (!obj) {
return;
}
obj.extensions = mergeDeep([obj.extensions || {}, extensions || {}]);
}
export function applyExtensions(schema, extensions) {
applyExtensionObject(schema, extensions.schemaExtensions);
for (const [typeName, data] of Object.entries(extensions.types || {})) {
const type = schema.getType(typeName);
if (type) {
applyExtensionObject(type, data.extensions);
if (data.type === 'object' || data.type === 'interface') {
for (const [fieldName, fieldData] of Object.entries(data.fields)) {
const field = type.getFields()[fieldName];
if (field) {
applyExtensionObject(field, fieldData.extensions);
for (const [arg, argData] of Object.entries(fieldData.arguments)) {
applyExtensionObject(field.args.find(a => a.name === arg), argData);
}
}
}
}
else if (data.type === 'input') {
for (const [fieldName, fieldData] of Object.entries(data.fields)) {
const field = type.getFields()[fieldName];
applyExtensionObject(field, fieldData.extensions);
}
}
else if (data.type === 'enum') {
for (const [valueName, valueData] of Object.entries(data.values)) {
const value = type.getValue(valueName);
applyExtensionObject(value, valueData);
}
}
}
}
return schema;
}

3
node_modules/@graphql-tools/merge/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export * from './merge-resolvers.js';
export * from './typedefs-mergers/index.js';
export * from './extensions.js';

View File

@@ -0,0 +1,63 @@
import { mergeDeep } from '@graphql-tools/utils';
/**
* Deep merges multiple resolver definition objects into a single definition.
* @param resolversDefinitions Resolver definitions to be merged
* @param options Additional options
*
* ```js
* const { mergeResolvers } = require('@graphql-tools/merge');
* const clientResolver = require('./clientResolver');
* const productResolver = require('./productResolver');
*
* const resolvers = mergeResolvers([
* clientResolver,
* productResolver,
* ]);
* ```
*
* If you don't want to manually create the array of resolver objects, you can
* also use this function along with loadFiles:
*
* ```js
* const path = require('path');
* const { mergeResolvers } = require('@graphql-tools/merge');
* const { loadFilesSync } = require('@graphql-tools/load-files');
*
* const resolversArray = loadFilesSync(path.join(__dirname, './resolvers'));
*
* const resolvers = mergeResolvers(resolversArray)
* ```
*/
export function mergeResolvers(resolversDefinitions, options) {
if (!resolversDefinitions || (Array.isArray(resolversDefinitions) && resolversDefinitions.length === 0)) {
return {};
}
if (!Array.isArray(resolversDefinitions)) {
return resolversDefinitions;
}
if (resolversDefinitions.length === 1) {
return resolversDefinitions[0] || {};
}
const resolvers = new Array();
for (let resolversDefinition of resolversDefinitions) {
if (Array.isArray(resolversDefinition)) {
resolversDefinition = mergeResolvers(resolversDefinition);
}
if (typeof resolversDefinition === 'object' && resolversDefinition) {
resolvers.push(resolversDefinition);
}
}
const result = mergeDeep(resolvers, true);
if (options === null || options === void 0 ? void 0 : options.exclusions) {
for (const exclusion of options.exclusions) {
const [typeName, fieldName] = exclusion.split('.');
if (!fieldName || fieldName === '*') {
delete result[typeName];
}
else if (result[typeName]) {
delete result[typeName][fieldName];
}
}
}
return result;
}

View File

@@ -0,0 +1,20 @@
import { compareNodes, isSome } from '@graphql-tools/utils';
export function mergeArguments(args1, args2, config) {
const result = deduplicateArguments([...args2, ...args1].filter(isSome), config);
if (config && config.sort) {
result.sort(compareNodes);
}
return result;
}
function deduplicateArguments(args, config) {
return args.reduce((acc, current) => {
const dupIndex = acc.findIndex(arg => arg.name.value === current.name.value);
if (dupIndex === -1) {
return acc.concat([current]);
}
else if (!(config === null || config === void 0 ? void 0 : config.reverseArguments)) {
acc[dupIndex] = current;
}
return acc;
}, []);
}

View File

@@ -0,0 +1,99 @@
import { print } from 'graphql';
import { isSome } from '@graphql-tools/utils';
function directiveAlreadyExists(directivesArr, otherDirective) {
return !!directivesArr.find(directive => directive.name.value === otherDirective.name.value);
}
function isRepeatableDirective(directive, directives) {
var _a;
return !!((_a = directives === null || directives === void 0 ? void 0 : directives[directive.name.value]) === null || _a === void 0 ? void 0 : _a.repeatable);
}
function nameAlreadyExists(name, namesArr) {
return namesArr.some(({ value }) => value === name.value);
}
function mergeArguments(a1, a2) {
const result = [...a2];
for (const argument of a1) {
const existingIndex = result.findIndex(a => a.name.value === argument.name.value);
if (existingIndex > -1) {
const existingArg = result[existingIndex];
if (existingArg.value.kind === 'ListValue') {
const source = existingArg.value.values;
const target = argument.value.values;
// merge values of two lists
existingArg.value.values = deduplicateLists(source, target, (targetVal, source) => {
const value = targetVal.value;
return !value || !source.some((sourceVal) => sourceVal.value === value);
});
}
else {
existingArg.value = argument.value;
}
}
else {
result.push(argument);
}
}
return result;
}
function deduplicateDirectives(directives, definitions) {
return directives
.map((directive, i, all) => {
const firstAt = all.findIndex(d => d.name.value === directive.name.value);
if (firstAt !== i && !isRepeatableDirective(directive, definitions)) {
const dup = all[firstAt];
directive.arguments = mergeArguments(directive.arguments, dup.arguments);
return null;
}
return directive;
})
.filter(isSome);
}
export function mergeDirectives(d1 = [], d2 = [], config, directives) {
const reverseOrder = config && config.reverseDirectives;
const asNext = reverseOrder ? d1 : d2;
const asFirst = reverseOrder ? d2 : d1;
const result = deduplicateDirectives([...asNext], directives);
for (const directive of asFirst) {
if (directiveAlreadyExists(result, directive) && !isRepeatableDirective(directive, directives)) {
const existingDirectiveIndex = result.findIndex(d => d.name.value === directive.name.value);
const existingDirective = result[existingDirectiveIndex];
result[existingDirectiveIndex].arguments = mergeArguments(directive.arguments || [], existingDirective.arguments || []);
}
else {
result.push(directive);
}
}
return result;
}
function validateInputs(node, existingNode) {
const printedNode = print({
...node,
description: undefined,
});
const printedExistingNode = print({
...existingNode,
description: undefined,
});
// eslint-disable-next-line
const leaveInputs = new RegExp('(directive @w*d*)|( on .*$)', 'g');
const sameArguments = printedNode.replace(leaveInputs, '') === printedExistingNode.replace(leaveInputs, '');
if (!sameArguments) {
throw new Error(`Unable to merge GraphQL directive "${node.name.value}". \nExisting directive: \n\t${printedExistingNode} \nReceived directive: \n\t${printedNode}`);
}
}
export function mergeDirective(node, existingNode) {
if (existingNode) {
validateInputs(node, existingNode);
return {
...node,
locations: [
...existingNode.locations,
...node.locations.filter(name => !nameAlreadyExists(name, existingNode.locations)),
],
};
}
return node;
}
function deduplicateLists(source, target, filterFn) {
return source.concat(target.filter(val => filterFn(val, source)));
}

View File

@@ -0,0 +1,36 @@
import { mergeDirectives } from './directives.js';
import { compareNodes } from '@graphql-tools/utils';
export function mergeEnumValues(first, second, config, directives) {
if (config === null || config === void 0 ? void 0 : config.consistentEnumMerge) {
const reversed = [];
if (first) {
reversed.push(...first);
}
first = second;
second = reversed;
}
const enumValueMap = new Map();
if (first) {
for (const firstValue of first) {
enumValueMap.set(firstValue.name.value, firstValue);
}
}
if (second) {
for (const secondValue of second) {
const enumValue = secondValue.name.value;
if (enumValueMap.has(enumValue)) {
const firstValue = enumValueMap.get(enumValue);
firstValue.description = secondValue.description || firstValue.description;
firstValue.directives = mergeDirectives(secondValue.directives, firstValue.directives, directives);
}
else {
enumValueMap.set(enumValue, secondValue);
}
}
}
const result = [...enumValueMap.values()];
if (config && config.sort) {
result.sort(compareNodes);
}
return result;
}

View File

@@ -0,0 +1,23 @@
import { Kind } from 'graphql';
import { mergeDirectives } from './directives.js';
import { mergeEnumValues } from './enum-values.js';
export function mergeEnum(e1, e2, config, directives) {
if (e2) {
return {
name: e1.name,
description: e1['description'] || e2['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) || e1.kind === 'EnumTypeDefinition' || e2.kind === 'EnumTypeDefinition'
? 'EnumTypeDefinition'
: 'EnumTypeExtension',
loc: e1.loc,
directives: mergeDirectives(e1.directives, e2.directives, config, directives),
values: mergeEnumValues(e1.values, e2.values, config),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...e1,
kind: Kind.ENUM_TYPE_DEFINITION,
}
: e1;
}

View File

@@ -0,0 +1,77 @@
import { extractType, isWrappingTypeNode, isListTypeNode, isNonNullTypeNode, printTypeNode } from './utils.js';
import { mergeDirectives } from './directives.js';
import { compareNodes } from '@graphql-tools/utils';
import { mergeArguments } from './arguments.js';
function fieldAlreadyExists(fieldsArr, otherField) {
const resultIndex = fieldsArr.findIndex(field => field.name.value === otherField.name.value);
return [resultIndex > -1 ? fieldsArr[resultIndex] : null, resultIndex];
}
export function mergeFields(type, f1, f2, config, directives) {
const result = [];
if (f2 != null) {
result.push(...f2);
}
if (f1 != null) {
for (const field of f1) {
const [existing, existingIndex] = fieldAlreadyExists(result, field);
if (existing && !(config === null || config === void 0 ? void 0 : config.ignoreFieldConflicts)) {
const newField = ((config === null || config === void 0 ? void 0 : config.onFieldTypeConflict) && config.onFieldTypeConflict(existing, field, type, config === null || config === void 0 ? void 0 : config.throwOnConflict)) ||
preventConflicts(type, existing, field, config === null || config === void 0 ? void 0 : config.throwOnConflict);
newField.arguments = mergeArguments(field['arguments'] || [], existing['arguments'] || [], config);
newField.directives = mergeDirectives(field.directives, existing.directives, config, directives);
newField.description = field.description || existing.description;
result[existingIndex] = newField;
}
else {
result.push(field);
}
}
}
if (config && config.sort) {
result.sort(compareNodes);
}
if (config && config.exclusions) {
const exclusions = config.exclusions;
return result.filter(field => !exclusions.includes(`${type.name.value}.${field.name.value}`));
}
return result;
}
function preventConflicts(type, a, b, ignoreNullability = false) {
const aType = printTypeNode(a.type);
const bType = printTypeNode(b.type);
if (aType !== bType) {
const t1 = extractType(a.type);
const t2 = extractType(b.type);
if (t1.name.value !== t2.name.value) {
throw new Error(`Field "${b.name.value}" already defined with a different type. Declared as "${t1.name.value}", but you tried to override with "${t2.name.value}"`);
}
if (!safeChangeForFieldType(a.type, b.type, !ignoreNullability)) {
throw new Error(`Field '${type.name.value}.${a.name.value}' changed type from '${aType}' to '${bType}'`);
}
}
if (isNonNullTypeNode(b.type) && !isNonNullTypeNode(a.type)) {
a.type = b.type;
}
return a;
}
function safeChangeForFieldType(oldType, newType, ignoreNullability = false) {
// both are named
if (!isWrappingTypeNode(oldType) && !isWrappingTypeNode(newType)) {
return oldType.toString() === newType.toString();
}
// new is non-null
if (isNonNullTypeNode(newType)) {
const ofType = isNonNullTypeNode(oldType) ? oldType.type : oldType;
return safeChangeForFieldType(ofType, newType.type);
}
// old is non-null
if (isNonNullTypeNode(oldType)) {
return safeChangeForFieldType(newType, oldType, ignoreNullability);
}
// old is list
if (isListTypeNode(oldType)) {
return ((isListTypeNode(newType) && safeChangeForFieldType(oldType.type, newType.type)) ||
(isNonNullTypeNode(newType) && safeChangeForFieldType(oldType, newType['type'])));
}
return false;
}

View File

@@ -0,0 +1,14 @@
export * from './arguments.js';
export * from './directives.js';
export * from './enum-values.js';
export * from './enum.js';
export * from './fields.js';
export * from './input-type.js';
export * from './interface.js';
export * from './merge-named-type-array.js';
export * from './merge-nodes.js';
export * from './merge-typedefs.js';
export * from './scalar.js';
export * from './type.js';
export * from './union.js';
export * from './utils.js';

View File

@@ -0,0 +1,30 @@
import { Kind, } from 'graphql';
import { mergeFields } from './fields.js';
import { mergeDirectives } from './directives.js';
export function mergeInputType(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'InputObjectTypeDefinition' ||
existingNode.kind === 'InputObjectTypeDefinition'
? 'InputObjectTypeDefinition'
: 'InputObjectTypeExtension',
loc: node.loc,
fields: mergeFields(node, node.fields, existingNode.fields, config),
directives: mergeDirectives(node.directives, existingNode.directives, config, directives),
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL input type "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: Kind.INPUT_OBJECT_TYPE_DEFINITION,
}
: node;
}

View File

@@ -0,0 +1,34 @@
import { Kind } from 'graphql';
import { mergeFields } from './fields.js';
import { mergeDirectives } from './directives.js';
import { mergeNamedTypeArray } from './merge-named-type-array.js';
export function mergeInterface(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'InterfaceTypeDefinition' ||
existingNode.kind === 'InterfaceTypeDefinition'
? 'InterfaceTypeDefinition'
: 'InterfaceTypeExtension',
loc: node.loc,
fields: mergeFields(node, node.fields, existingNode.fields, config),
directives: mergeDirectives(node.directives, existingNode.directives, config, directives),
interfaces: node['interfaces']
? mergeNamedTypeArray(node['interfaces'], existingNode['interfaces'], config)
: undefined,
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL interface "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: Kind.INTERFACE_TYPE_DEFINITION,
}
: node;
}

View File

@@ -0,0 +1,11 @@
import { compareNodes } from '@graphql-tools/utils';
function alreadyExists(arr, other) {
return !!arr.find(i => i.name.value === other.name.value);
}
export function mergeNamedTypeArray(first = [], second = [], config = {}) {
const result = [...second, ...first.filter(d => !alreadyExists(second, d))];
if (config && config.sort) {
result.sort(compareNodes);
}
return result;
}

View File

@@ -0,0 +1,67 @@
import { Kind } from 'graphql';
import { mergeType } from './type.js';
import { mergeEnum } from './enum.js';
import { mergeScalar } from './scalar.js';
import { mergeUnion } from './union.js';
import { mergeInputType } from './input-type.js';
import { mergeInterface } from './interface.js';
import { mergeDirective } from './directives.js';
import { mergeSchemaDefs } from './schema-def.js';
import { collectComment } from '@graphql-tools/utils';
export const schemaDefSymbol = 'SCHEMA_DEF_SYMBOL';
export function isNamedDefinitionNode(definitionNode) {
return 'name' in definitionNode;
}
export function mergeGraphQLNodes(nodes, config, directives = {}) {
var _a, _b, _c;
const mergedResultMap = directives;
for (const nodeDefinition of nodes) {
if (isNamedDefinitionNode(nodeDefinition)) {
const name = (_a = nodeDefinition.name) === null || _a === void 0 ? void 0 : _a.value;
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
collectComment(nodeDefinition);
}
if (name == null) {
continue;
}
if (((_b = config === null || config === void 0 ? void 0 : config.exclusions) === null || _b === void 0 ? void 0 : _b.includes(name + '.*')) || ((_c = config === null || config === void 0 ? void 0 : config.exclusions) === null || _c === void 0 ? void 0 : _c.includes(name))) {
delete mergedResultMap[name];
}
else {
switch (nodeDefinition.kind) {
case Kind.OBJECT_TYPE_DEFINITION:
case Kind.OBJECT_TYPE_EXTENSION:
mergedResultMap[name] = mergeType(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.ENUM_TYPE_DEFINITION:
case Kind.ENUM_TYPE_EXTENSION:
mergedResultMap[name] = mergeEnum(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.UNION_TYPE_DEFINITION:
case Kind.UNION_TYPE_EXTENSION:
mergedResultMap[name] = mergeUnion(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.SCALAR_TYPE_DEFINITION:
case Kind.SCALAR_TYPE_EXTENSION:
mergedResultMap[name] = mergeScalar(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.INPUT_OBJECT_TYPE_DEFINITION:
case Kind.INPUT_OBJECT_TYPE_EXTENSION:
mergedResultMap[name] = mergeInputType(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.INTERFACE_TYPE_DEFINITION:
case Kind.INTERFACE_TYPE_EXTENSION:
mergedResultMap[name] = mergeInterface(nodeDefinition, mergedResultMap[name], config, directives);
break;
case Kind.DIRECTIVE_DEFINITION:
mergedResultMap[name] = mergeDirective(nodeDefinition, mergedResultMap[name]);
break;
}
}
}
else if (nodeDefinition.kind === Kind.SCHEMA_DEFINITION || nodeDefinition.kind === Kind.SCHEMA_EXTENSION) {
mergedResultMap[schemaDefSymbol] = mergeSchemaDefs(nodeDefinition, mergedResultMap[schemaDefSymbol], config);
}
}
return mergedResultMap;
}

View File

@@ -0,0 +1,122 @@
import { parse, Kind, isSchema, isDefinitionNode, } from 'graphql';
import { defaultStringComparator, isSourceTypes, isStringTypes } from './utils.js';
import { mergeGraphQLNodes, schemaDefSymbol } from './merge-nodes.js';
import { getDocumentNodeFromSchema, isDocumentNode, resetComments, printWithComments, } from '@graphql-tools/utils';
import { DEFAULT_OPERATION_TYPE_NAME_MAP } from './schema-def.js';
export function mergeTypeDefs(typeSource, config) {
resetComments();
const doc = {
kind: Kind.DOCUMENT,
definitions: mergeGraphQLTypes(typeSource, {
useSchemaDefinition: true,
forceSchemaDefinition: false,
throwOnConflict: false,
commentDescriptions: false,
...config,
}),
};
let result;
if (config === null || config === void 0 ? void 0 : config.commentDescriptions) {
result = printWithComments(doc);
}
else {
result = doc;
}
resetComments();
return result;
}
function visitTypeSources(typeSource, options, allDirectives = [], allNodes = [], visitedTypeSources = new Set()) {
if (typeSource && !visitedTypeSources.has(typeSource)) {
visitedTypeSources.add(typeSource);
if (typeof typeSource === 'function') {
visitTypeSources(typeSource(), options, allDirectives, allNodes, visitedTypeSources);
}
else if (Array.isArray(typeSource)) {
for (const type of typeSource) {
visitTypeSources(type, options, allDirectives, allNodes, visitedTypeSources);
}
}
else if (isSchema(typeSource)) {
const documentNode = getDocumentNodeFromSchema(typeSource, options);
visitTypeSources(documentNode.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else if (isStringTypes(typeSource) || isSourceTypes(typeSource)) {
const documentNode = parse(typeSource, options);
visitTypeSources(documentNode.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else if (typeof typeSource === 'object' && isDefinitionNode(typeSource)) {
if (typeSource.kind === Kind.DIRECTIVE_DEFINITION) {
allDirectives.push(typeSource);
}
else {
allNodes.push(typeSource);
}
}
else if (isDocumentNode(typeSource)) {
visitTypeSources(typeSource.definitions, options, allDirectives, allNodes, visitedTypeSources);
}
else {
throw new Error(`typeDefs must contain only strings, documents, schemas, or functions, got ${typeof typeSource}`);
}
}
return { allDirectives, allNodes };
}
export function mergeGraphQLTypes(typeSource, config) {
var _a, _b, _c;
resetComments();
const { allDirectives, allNodes } = visitTypeSources(typeSource, config);
const mergedDirectives = mergeGraphQLNodes(allDirectives, config);
const mergedNodes = mergeGraphQLNodes(allNodes, config, mergedDirectives);
if (config === null || config === void 0 ? void 0 : config.useSchemaDefinition) {
// XXX: right now we don't handle multiple schema definitions
const schemaDef = mergedNodes[schemaDefSymbol] || {
kind: Kind.SCHEMA_DEFINITION,
operationTypes: [],
};
const operationTypes = schemaDef.operationTypes;
for (const opTypeDefNodeType in DEFAULT_OPERATION_TYPE_NAME_MAP) {
const opTypeDefNode = operationTypes.find(operationType => operationType.operation === opTypeDefNodeType);
if (!opTypeDefNode) {
const possibleRootTypeName = DEFAULT_OPERATION_TYPE_NAME_MAP[opTypeDefNodeType];
const existingPossibleRootType = mergedNodes[possibleRootTypeName];
if (existingPossibleRootType != null && existingPossibleRootType.name != null) {
operationTypes.push({
kind: Kind.OPERATION_TYPE_DEFINITION,
type: {
kind: Kind.NAMED_TYPE,
name: existingPossibleRootType.name,
},
operation: opTypeDefNodeType,
});
}
}
}
if (((_a = schemaDef === null || schemaDef === void 0 ? void 0 : schemaDef.operationTypes) === null || _a === void 0 ? void 0 : _a.length) != null && schemaDef.operationTypes.length > 0) {
mergedNodes[schemaDefSymbol] = schemaDef;
}
}
if ((config === null || config === void 0 ? void 0 : config.forceSchemaDefinition) && !((_c = (_b = mergedNodes[schemaDefSymbol]) === null || _b === void 0 ? void 0 : _b.operationTypes) === null || _c === void 0 ? void 0 : _c.length)) {
mergedNodes[schemaDefSymbol] = {
kind: Kind.SCHEMA_DEFINITION,
operationTypes: [
{
kind: Kind.OPERATION_TYPE_DEFINITION,
operation: 'query',
type: {
kind: Kind.NAMED_TYPE,
name: {
kind: Kind.NAME,
value: 'Query',
},
},
},
],
};
}
const mergedNodeDefinitions = Object.values(mergedNodes);
if (config === null || config === void 0 ? void 0 : config.sort) {
const sortFn = typeof config.sort === 'function' ? config.sort : defaultStringComparator;
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); });
}
return mergedNodeDefinitions;
}

View File

@@ -0,0 +1,23 @@
import { Kind } from 'graphql';
import { mergeDirectives } from './directives.js';
export function mergeScalar(node, existingNode, config, directives) {
if (existingNode) {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'ScalarTypeDefinition' ||
existingNode.kind === 'ScalarTypeDefinition'
? 'ScalarTypeDefinition'
: 'ScalarTypeExtension',
loc: node.loc,
directives: mergeDirectives(node.directives, existingNode.directives, config, directives),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: Kind.SCALAR_TYPE_DEFINITION,
}
: node;
}

View File

@@ -0,0 +1,35 @@
import { Kind, } from 'graphql';
import { mergeDirectives } from './directives.js';
export const DEFAULT_OPERATION_TYPE_NAME_MAP = {
query: 'Query',
mutation: 'Mutation',
subscription: 'Subscription',
};
function mergeOperationTypes(opNodeList = [], existingOpNodeList = []) {
const finalOpNodeList = [];
for (const opNodeType in DEFAULT_OPERATION_TYPE_NAME_MAP) {
const opNode = opNodeList.find(n => n.operation === opNodeType) || existingOpNodeList.find(n => n.operation === opNodeType);
if (opNode) {
finalOpNodeList.push(opNode);
}
}
return finalOpNodeList;
}
export function mergeSchemaDefs(node, existingNode, config, directives) {
if (existingNode) {
return {
kind: node.kind === Kind.SCHEMA_DEFINITION || existingNode.kind === Kind.SCHEMA_DEFINITION
? Kind.SCHEMA_DEFINITION
: Kind.SCHEMA_EXTENSION,
description: node['description'] || existingNode['description'],
directives: mergeDirectives(node.directives, existingNode.directives, config, directives),
operationTypes: mergeOperationTypes(node.operationTypes, existingNode.operationTypes),
};
}
return ((config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: Kind.SCHEMA_DEFINITION,
}
: node);
}

View File

@@ -0,0 +1,32 @@
import { Kind } from 'graphql';
import { mergeFields } from './fields.js';
import { mergeDirectives } from './directives.js';
import { mergeNamedTypeArray } from './merge-named-type-array.js';
export function mergeType(node, existingNode, config, directives) {
if (existingNode) {
try {
return {
name: node.name,
description: node['description'] || existingNode['description'],
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) ||
node.kind === 'ObjectTypeDefinition' ||
existingNode.kind === 'ObjectTypeDefinition'
? 'ObjectTypeDefinition'
: 'ObjectTypeExtension',
loc: node.loc,
fields: mergeFields(node, node.fields, existingNode.fields, config),
directives: mergeDirectives(node.directives, existingNode.directives, config, directives),
interfaces: mergeNamedTypeArray(node.interfaces, existingNode.interfaces, config),
};
}
catch (e) {
throw new Error(`Unable to merge GraphQL type "${node.name.value}": ${e.message}`);
}
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...node,
kind: Kind.OBJECT_TYPE_DEFINITION,
}
: node;
}

View File

@@ -0,0 +1,24 @@
import { Kind } from 'graphql';
import { mergeDirectives } from './directives.js';
import { mergeNamedTypeArray } from './merge-named-type-array.js';
export function mergeUnion(first, second, config, directives) {
if (second) {
return {
name: first.name,
description: first['description'] || second['description'],
// ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
directives: mergeDirectives(first.directives, second.directives, config, directives),
kind: (config === null || config === void 0 ? void 0 : config.convertExtensions) || first.kind === 'UnionTypeDefinition' || second.kind === 'UnionTypeDefinition'
? Kind.UNION_TYPE_DEFINITION
: Kind.UNION_TYPE_EXTENSION,
loc: first.loc,
types: mergeNamedTypeArray(first.types, second.types, config),
};
}
return (config === null || config === void 0 ? void 0 : config.convertExtensions)
? {
...first,
kind: Kind.UNION_TYPE_DEFINITION,
}
: first;
}

View File

@@ -0,0 +1,54 @@
import { Source, Kind } from 'graphql';
export function isStringTypes(types) {
return typeof types === 'string';
}
export function isSourceTypes(types) {
return types instanceof Source;
}
export function extractType(type) {
let visitedType = type;
while (visitedType.kind === Kind.LIST_TYPE || visitedType.kind === 'NonNullType') {
visitedType = visitedType.type;
}
return visitedType;
}
export function isWrappingTypeNode(type) {
return type.kind !== Kind.NAMED_TYPE;
}
export function isListTypeNode(type) {
return type.kind === Kind.LIST_TYPE;
}
export function isNonNullTypeNode(type) {
return type.kind === Kind.NON_NULL_TYPE;
}
export function printTypeNode(type) {
if (isListTypeNode(type)) {
return `[${printTypeNode(type.type)}]`;
}
if (isNonNullTypeNode(type)) {
return `${printTypeNode(type.type)}!`;
}
return type.name.value;
}
export var CompareVal;
(function (CompareVal) {
CompareVal[CompareVal["A_SMALLER_THAN_B"] = -1] = "A_SMALLER_THAN_B";
CompareVal[CompareVal["A_EQUALS_B"] = 0] = "A_EQUALS_B";
CompareVal[CompareVal["A_GREATER_THAN_B"] = 1] = "A_GREATER_THAN_B";
})(CompareVal || (CompareVal = {}));
export function defaultStringComparator(a, b) {
if (a == null && b == null) {
return CompareVal.A_EQUALS_B;
}
if (a == null) {
return CompareVal.A_SMALLER_THAN_B;
}
if (b == null) {
return CompareVal.A_GREATER_THAN_B;
}
if (a < b)
return CompareVal.A_SMALLER_THAN_B;
if (a > b)
return CompareVal.A_GREATER_THAN_B;
return CompareVal.A_EQUALS_B;
}

58
node_modules/@graphql-tools/merge/package.json generated vendored Normal file
View File

@@ -0,0 +1,58 @@
{
"name": "@graphql-tools/merge",
"version": "8.4.2",
"description": "A set of utils for faster development of GraphQL tools",
"sideEffects": false,
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0"
},
"dependencies": {
"@graphql-tools/utils": "^9.2.1",
"tslib": "^2.4.0"
},
"repository": {
"type": "git",
"url": "ardatan/graphql-tools",
"directory": "packages/merge"
},
"author": "Dotan Simha <dotansimha@gmail.com>",
"license": "MIT",
"main": "cjs/index.js",
"module": "esm/index.js",
"typings": "typings/index.d.ts",
"typescript": {
"definition": "typings/index.d.ts"
},
"type": "module",
"exports": {
".": {
"require": {
"types": "./typings/index.d.cts",
"default": "./cjs/index.js"
},
"import": {
"types": "./typings/index.d.ts",
"default": "./esm/index.js"
},
"default": {
"types": "./typings/index.d.ts",
"default": "./esm/index.js"
}
},
"./*": {
"require": {
"types": "./typings/*.d.cts",
"default": "./cjs/*.js"
},
"import": {
"types": "./typings/*.d.ts",
"default": "./esm/*.js"
},
"default": {
"types": "./typings/*.d.ts",
"default": "./esm/*.js"
}
},
"./package.json": "./package.json"
}
}

View File

@@ -0,0 +1,5 @@
import { GraphQLSchema } from 'graphql';
import { SchemaExtensions } from '@graphql-tools/utils';
export { extractExtensionsFromSchema } from '@graphql-tools/utils';
export declare function mergeExtensions(extensions: SchemaExtensions[]): SchemaExtensions;
export declare function applyExtensions(schema: GraphQLSchema, extensions: SchemaExtensions): GraphQLSchema;

View File

@@ -0,0 +1,5 @@
import { GraphQLSchema } from 'graphql';
import { SchemaExtensions } from '@graphql-tools/utils';
export { extractExtensionsFromSchema } from '@graphql-tools/utils';
export declare function mergeExtensions(extensions: SchemaExtensions[]): SchemaExtensions;
export declare function applyExtensions(schema: GraphQLSchema, extensions: SchemaExtensions): GraphQLSchema;

View File

@@ -0,0 +1,3 @@
export * from './merge-resolvers.cjs';
export * from './typedefs-mergers/index.cjs';
export * from './extensions.cjs';

3
node_modules/@graphql-tools/merge/typings/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export * from './merge-resolvers.js';
export * from './typedefs-mergers/index.js';
export * from './extensions.js';

View File

@@ -0,0 +1,37 @@
import { IResolvers, Maybe } from '@graphql-tools/utils';
/**
* Additional options for merging resolvers
*/
export interface MergeResolversOptions {
exclusions?: string[];
}
/**
* Deep merges multiple resolver definition objects into a single definition.
* @param resolversDefinitions Resolver definitions to be merged
* @param options Additional options
*
* ```js
* const { mergeResolvers } = require('@graphql-tools/merge');
* const clientResolver = require('./clientResolver');
* const productResolver = require('./productResolver');
*
* const resolvers = mergeResolvers([
* clientResolver,
* productResolver,
* ]);
* ```
*
* If you don't want to manually create the array of resolver objects, you can
* also use this function along with loadFiles:
*
* ```js
* const path = require('path');
* const { mergeResolvers } = require('@graphql-tools/merge');
* const { loadFilesSync } = require('@graphql-tools/load-files');
*
* const resolversArray = loadFilesSync(path.join(__dirname, './resolvers'));
*
* const resolvers = mergeResolvers(resolversArray)
* ```
*/
export declare function mergeResolvers<TSource, TContext>(resolversDefinitions: Maybe<IResolvers<TSource, TContext>> | Maybe<Maybe<IResolvers<TSource, TContext>>[]>, options?: MergeResolversOptions): IResolvers<TSource, TContext>;

View File

@@ -0,0 +1,37 @@
import { IResolvers, Maybe } from '@graphql-tools/utils';
/**
* Additional options for merging resolvers
*/
export interface MergeResolversOptions {
exclusions?: string[];
}
/**
* Deep merges multiple resolver definition objects into a single definition.
* @param resolversDefinitions Resolver definitions to be merged
* @param options Additional options
*
* ```js
* const { mergeResolvers } = require('@graphql-tools/merge');
* const clientResolver = require('./clientResolver');
* const productResolver = require('./productResolver');
*
* const resolvers = mergeResolvers([
* clientResolver,
* productResolver,
* ]);
* ```
*
* If you don't want to manually create the array of resolver objects, you can
* also use this function along with loadFiles:
*
* ```js
* const path = require('path');
* const { mergeResolvers } = require('@graphql-tools/merge');
* const { loadFilesSync } = require('@graphql-tools/load-files');
*
* const resolversArray = loadFilesSync(path.join(__dirname, './resolvers'));
*
* const resolvers = mergeResolvers(resolversArray)
* ```
*/
export declare function mergeResolvers<TSource, TContext>(resolversDefinitions: Maybe<IResolvers<TSource, TContext>> | Maybe<Maybe<IResolvers<TSource, TContext>>[]>, options?: MergeResolversOptions): IResolvers<TSource, TContext>;

View File

@@ -0,0 +1,3 @@
import { InputValueDefinitionNode } from 'graphql';
import { Config } from './index.cjs';
export declare function mergeArguments(args1: InputValueDefinitionNode[], args2: InputValueDefinitionNode[], config?: Config): InputValueDefinitionNode[];

View File

@@ -0,0 +1,3 @@
import { InputValueDefinitionNode } from 'graphql';
import { Config } from './index.js';
export declare function mergeArguments(args1: InputValueDefinitionNode[], args2: InputValueDefinitionNode[], config?: Config): InputValueDefinitionNode[];

View File

@@ -0,0 +1,4 @@
import { DirectiveNode, DirectiveDefinitionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare function mergeDirectives(d1?: ReadonlyArray<DirectiveNode>, d2?: ReadonlyArray<DirectiveNode>, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): DirectiveNode[];
export declare function mergeDirective(node: DirectiveDefinitionNode, existingNode?: DirectiveDefinitionNode): DirectiveDefinitionNode;

View File

@@ -0,0 +1,4 @@
import { DirectiveNode, DirectiveDefinitionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare function mergeDirectives(d1?: ReadonlyArray<DirectiveNode>, d2?: ReadonlyArray<DirectiveNode>, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): DirectiveNode[];
export declare function mergeDirective(node: DirectiveDefinitionNode, existingNode?: DirectiveDefinitionNode): DirectiveDefinitionNode;

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, EnumValueDefinitionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare function mergeEnumValues(first: ReadonlyArray<EnumValueDefinitionNode> | undefined, second: ReadonlyArray<EnumValueDefinitionNode> | undefined, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): EnumValueDefinitionNode[];

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, EnumValueDefinitionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare function mergeEnumValues(first: ReadonlyArray<EnumValueDefinitionNode> | undefined, second: ReadonlyArray<EnumValueDefinitionNode> | undefined, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): EnumValueDefinitionNode[];

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare function mergeEnum(e1: EnumTypeDefinitionNode | EnumTypeExtensionNode, e2: EnumTypeDefinitionNode | EnumTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): EnumTypeDefinitionNode | EnumTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, EnumTypeDefinitionNode, EnumTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare function mergeEnum(e1: EnumTypeDefinitionNode | EnumTypeExtensionNode, e2: EnumTypeDefinitionNode | EnumTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): EnumTypeDefinitionNode | EnumTypeExtensionNode;

View File

@@ -0,0 +1,11 @@
import { Config } from './merge-typedefs.cjs';
import { FieldDefinitionNode, InputValueDefinitionNode, NameNode, DirectiveDefinitionNode } from 'graphql';
type FieldDefNode = FieldDefinitionNode | InputValueDefinitionNode;
type NamedDefNode = {
name: NameNode;
};
export type OnFieldTypeConflict = (existingField: FieldDefNode, otherField: FieldDefNode, type: NamedDefNode, ignoreNullability: boolean | undefined) => FieldDefNode;
export declare function mergeFields<T extends FieldDefNode>(type: {
name: NameNode;
}, f1: ReadonlyArray<T> | undefined, f2: ReadonlyArray<T> | undefined, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): T[];
export {};

View File

@@ -0,0 +1,11 @@
import { Config } from './merge-typedefs.js';
import { FieldDefinitionNode, InputValueDefinitionNode, NameNode, DirectiveDefinitionNode } from 'graphql';
type FieldDefNode = FieldDefinitionNode | InputValueDefinitionNode;
type NamedDefNode = {
name: NameNode;
};
export type OnFieldTypeConflict = (existingField: FieldDefNode, otherField: FieldDefNode, type: NamedDefNode, ignoreNullability: boolean | undefined) => FieldDefNode;
export declare function mergeFields<T extends FieldDefNode>(type: {
name: NameNode;
}, f1: ReadonlyArray<T> | undefined, f2: ReadonlyArray<T> | undefined, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): T[];
export {};

View File

@@ -0,0 +1,14 @@
export * from './arguments.cjs';
export * from './directives.cjs';
export * from './enum-values.cjs';
export * from './enum.cjs';
export * from './fields.cjs';
export * from './input-type.cjs';
export * from './interface.cjs';
export * from './merge-named-type-array.cjs';
export * from './merge-nodes.cjs';
export * from './merge-typedefs.cjs';
export * from './scalar.cjs';
export * from './type.cjs';
export * from './union.cjs';
export * from './utils.cjs';

View File

@@ -0,0 +1,14 @@
export * from './arguments.js';
export * from './directives.js';
export * from './enum-values.js';
export * from './enum.js';
export * from './fields.js';
export * from './input-type.js';
export * from './interface.js';
export * from './merge-named-type-array.js';
export * from './merge-nodes.js';
export * from './merge-typedefs.js';
export * from './scalar.js';
export * from './type.js';
export * from './union.js';
export * from './utils.js';

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.cjs';
import { InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, DirectiveDefinitionNode } from 'graphql';
export declare function mergeInputType(node: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, existingNode: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.js';
import { InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, DirectiveDefinitionNode } from 'graphql';
export declare function mergeInputType(node: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, existingNode: InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): InputObjectTypeDefinitionNode | InputObjectTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.cjs';
import { DirectiveDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode } from 'graphql';
export declare function mergeInterface(node: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, existingNode: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.js';
import { DirectiveDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode } from 'graphql';
export declare function mergeInterface(node: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, existingNode: InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): InterfaceTypeDefinitionNode | InterfaceTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { NamedTypeNode } from 'graphql';
import { Config } from '../index.cjs';
export declare function mergeNamedTypeArray(first?: ReadonlyArray<NamedTypeNode>, second?: ReadonlyArray<NamedTypeNode>, config?: Config): NamedTypeNode[];

View File

@@ -0,0 +1,3 @@
import { NamedTypeNode } from 'graphql';
import { Config } from '../index.js';
export declare function mergeNamedTypeArray(first?: ReadonlyArray<NamedTypeNode>, second?: ReadonlyArray<NamedTypeNode>, config?: Config): NamedTypeNode[];

View File

@@ -0,0 +1,9 @@
import { Config } from './merge-typedefs.cjs';
import { DefinitionNode, DirectiveDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
import { NamedDefinitionNode } from '@graphql-tools/utils';
export declare const schemaDefSymbol = "SCHEMA_DEF_SYMBOL";
export type MergedResultMap = Record<string, NamedDefinitionNode> & {
[schemaDefSymbol]: SchemaDefinitionNode | SchemaExtensionNode;
};
export declare function isNamedDefinitionNode(definitionNode: DefinitionNode): definitionNode is NamedDefinitionNode;
export declare function mergeGraphQLNodes(nodes: ReadonlyArray<DefinitionNode>, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): MergedResultMap;

View File

@@ -0,0 +1,9 @@
import { Config } from './merge-typedefs.js';
import { DefinitionNode, DirectiveDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
import { NamedDefinitionNode } from '@graphql-tools/utils';
export declare const schemaDefSymbol = "SCHEMA_DEF_SYMBOL";
export type MergedResultMap = Record<string, NamedDefinitionNode> & {
[schemaDefSymbol]: SchemaDefinitionNode | SchemaExtensionNode;
};
export declare function isNamedDefinitionNode(definitionNode: DefinitionNode): definitionNode is NamedDefinitionNode;
export declare function mergeGraphQLNodes(nodes: ReadonlyArray<DefinitionNode>, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): MergedResultMap;

View File

@@ -0,0 +1,86 @@
import { DefinitionNode, DocumentNode, ParseOptions } from 'graphql';
import { CompareFn } from './utils.cjs';
import { GetDocumentNodeFromSchemaOptions, TypeSource } from '@graphql-tools/utils';
import { OnFieldTypeConflict } from './fields.cjs';
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
export interface Config extends ParseOptions, GetDocumentNodeFromSchemaOptions {
/**
* Produces `schema { query: ..., mutation: ..., subscription: ... }`
*
* Default: true
*/
useSchemaDefinition?: boolean;
/**
* Creates schema definition, even when no types are available
* Produces: `schema { query: Query }`
*
* Default: false
*/
forceSchemaDefinition?: boolean;
/**
* Throws an error on a merge conflict
*
* Default: false
*/
throwOnConflict?: boolean;
/**
* Descriptions are defined as preceding string literals, however an older
* experimental version of the SDL supported preceding comments as
* descriptions. Set to true to enable this deprecated behavior.
* This option is provided to ease adoption and will be removed in v16.
*
* Default: false
*/
commentDescriptions?: boolean;
/**
* Puts the next directive first.
*
* Default: false
*
* @example:
* Given:
* ```graphql
* type User { a: String @foo }
* type User { a: String @bar }
* ```
*
* Results:
* ```
* type User { a: @bar @foo }
* ```
*/
reverseDirectives?: boolean;
exclusions?: string[];
sort?: boolean | CompareFn<string>;
convertExtensions?: boolean;
consistentEnumMerge?: boolean;
ignoreFieldConflicts?: boolean;
/**
* Called if types of the same fields are different
*
* Default: false
*
* @example:
* Given:
* ```graphql
* type User { a: String }
* type User { a: Int }
* ```
*
* Instead of throwing `already defined with a different type` error,
* `onFieldTypeConflict` function is called.
*/
onFieldTypeConflict?: OnFieldTypeConflict;
reverseArguments?: boolean;
}
/**
* Merges multiple type definitions into a single `DocumentNode`
* @param types The type definitions to be merged
*/
export declare function mergeTypeDefs(typeSource: TypeSource): DocumentNode;
export declare function mergeTypeDefs(typeSource: TypeSource, config?: Partial<Config> & {
commentDescriptions: true;
}): string;
export declare function mergeTypeDefs(typeSource: TypeSource, config?: Omit<Partial<Config>, 'commentDescriptions'>): DocumentNode;
export declare function mergeGraphQLTypes(typeSource: TypeSource, config: Config): DefinitionNode[];
export {};

View File

@@ -0,0 +1,86 @@
import { DefinitionNode, DocumentNode, ParseOptions } from 'graphql';
import { CompareFn } from './utils.js';
import { GetDocumentNodeFromSchemaOptions, TypeSource } from '@graphql-tools/utils';
import { OnFieldTypeConflict } from './fields.js';
type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
export interface Config extends ParseOptions, GetDocumentNodeFromSchemaOptions {
/**
* Produces `schema { query: ..., mutation: ..., subscription: ... }`
*
* Default: true
*/
useSchemaDefinition?: boolean;
/**
* Creates schema definition, even when no types are available
* Produces: `schema { query: Query }`
*
* Default: false
*/
forceSchemaDefinition?: boolean;
/**
* Throws an error on a merge conflict
*
* Default: false
*/
throwOnConflict?: boolean;
/**
* Descriptions are defined as preceding string literals, however an older
* experimental version of the SDL supported preceding comments as
* descriptions. Set to true to enable this deprecated behavior.
* This option is provided to ease adoption and will be removed in v16.
*
* Default: false
*/
commentDescriptions?: boolean;
/**
* Puts the next directive first.
*
* Default: false
*
* @example:
* Given:
* ```graphql
* type User { a: String @foo }
* type User { a: String @bar }
* ```
*
* Results:
* ```
* type User { a: @bar @foo }
* ```
*/
reverseDirectives?: boolean;
exclusions?: string[];
sort?: boolean | CompareFn<string>;
convertExtensions?: boolean;
consistentEnumMerge?: boolean;
ignoreFieldConflicts?: boolean;
/**
* Called if types of the same fields are different
*
* Default: false
*
* @example:
* Given:
* ```graphql
* type User { a: String }
* type User { a: Int }
* ```
*
* Instead of throwing `already defined with a different type` error,
* `onFieldTypeConflict` function is called.
*/
onFieldTypeConflict?: OnFieldTypeConflict;
reverseArguments?: boolean;
}
/**
* Merges multiple type definitions into a single `DocumentNode`
* @param types The type definitions to be merged
*/
export declare function mergeTypeDefs(typeSource: TypeSource): DocumentNode;
export declare function mergeTypeDefs(typeSource: TypeSource, config?: Partial<Config> & {
commentDescriptions: true;
}): string;
export declare function mergeTypeDefs(typeSource: TypeSource, config?: Omit<Partial<Config>, 'commentDescriptions'>): DocumentNode;
export declare function mergeGraphQLTypes(typeSource: TypeSource, config: Config): DefinitionNode[];
export {};

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare function mergeScalar(node: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, existingNode: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): ScalarTypeDefinitionNode | ScalarTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare function mergeScalar(node: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, existingNode: ScalarTypeDefinitionNode | ScalarTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): ScalarTypeDefinitionNode | ScalarTypeExtensionNode;

View File

@@ -0,0 +1,8 @@
import { DirectiveDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare const DEFAULT_OPERATION_TYPE_NAME_MAP: {
readonly query: "Query";
readonly mutation: "Mutation";
readonly subscription: "Subscription";
};
export declare function mergeSchemaDefs(node: SchemaDefinitionNode | SchemaExtensionNode, existingNode: SchemaDefinitionNode | SchemaExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): SchemaDefinitionNode | SchemaExtensionNode;

View File

@@ -0,0 +1,8 @@
import { DirectiveDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare const DEFAULT_OPERATION_TYPE_NAME_MAP: {
readonly query: "Query";
readonly mutation: "Mutation";
readonly subscription: "Subscription";
};
export declare function mergeSchemaDefs(node: SchemaDefinitionNode | SchemaExtensionNode, existingNode: SchemaDefinitionNode | SchemaExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): SchemaDefinitionNode | SchemaExtensionNode;

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.cjs';
import { DirectiveDefinitionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode } from 'graphql';
export declare function mergeType(node: ObjectTypeDefinitionNode | ObjectTypeExtensionNode, existingNode: ObjectTypeDefinitionNode | ObjectTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): ObjectTypeDefinitionNode | ObjectTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { Config } from './merge-typedefs.js';
import { DirectiveDefinitionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode } from 'graphql';
export declare function mergeType(node: ObjectTypeDefinitionNode | ObjectTypeExtensionNode, existingNode: ObjectTypeDefinitionNode | ObjectTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): ObjectTypeDefinitionNode | ObjectTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.cjs';
export declare function mergeUnion(first: UnionTypeDefinitionNode | UnionTypeExtensionNode, second: UnionTypeDefinitionNode | UnionTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): UnionTypeDefinitionNode | UnionTypeExtensionNode;

View File

@@ -0,0 +1,3 @@
import { DirectiveDefinitionNode, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';
import { Config } from './merge-typedefs.js';
export declare function mergeUnion(first: UnionTypeDefinitionNode | UnionTypeExtensionNode, second: UnionTypeDefinitionNode | UnionTypeExtensionNode, config?: Config, directives?: Record<string, DirectiveDefinitionNode>): UnionTypeDefinitionNode | UnionTypeExtensionNode;

View File

@@ -0,0 +1,15 @@
import { TypeNode, NamedTypeNode, ListTypeNode, NonNullTypeNode, Source } from 'graphql';
export declare function isStringTypes(types: any): types is string;
export declare function isSourceTypes(types: any): types is Source;
export declare function extractType(type: TypeNode): NamedTypeNode;
export declare function isWrappingTypeNode(type: TypeNode): type is ListTypeNode | NonNullTypeNode;
export declare function isListTypeNode(type: TypeNode): type is ListTypeNode;
export declare function isNonNullTypeNode(type: TypeNode): type is NonNullTypeNode;
export declare function printTypeNode(type: TypeNode): string;
export declare enum CompareVal {
A_SMALLER_THAN_B = -1,
A_EQUALS_B = 0,
A_GREATER_THAN_B = 1
}
export type CompareFn<T> = (a: T | undefined, b: T | undefined) => -1 | 0 | 1;
export declare function defaultStringComparator(a: string | undefined, b: string | undefined): CompareVal;

View File

@@ -0,0 +1,15 @@
import { TypeNode, NamedTypeNode, ListTypeNode, NonNullTypeNode, Source } from 'graphql';
export declare function isStringTypes(types: any): types is string;
export declare function isSourceTypes(types: any): types is Source;
export declare function extractType(type: TypeNode): NamedTypeNode;
export declare function isWrappingTypeNode(type: TypeNode): type is ListTypeNode | NonNullTypeNode;
export declare function isListTypeNode(type: TypeNode): type is ListTypeNode;
export declare function isNonNullTypeNode(type: TypeNode): type is NonNullTypeNode;
export declare function printTypeNode(type: TypeNode): string;
export declare enum CompareVal {
A_SMALLER_THAN_B = -1,
A_EQUALS_B = 0,
A_GREATER_THAN_B = 1
}
export type CompareFn<T> = (a: T | undefined, b: T | undefined) => -1 | 0 | 1;
export declare function defaultStringComparator(a: string | undefined, b: string | undefined): CompareVal;