initial update

This commit is contained in:
jackbeeby
2025-05-15 13:32:55 +10:00
commit 7b07a49fbe
4412 changed files with 909535 additions and 0 deletions

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;
}