UNPKG

@graphql-tools/stitch

Version:

A set of utils for faster development of GraphQL tools

46 lines (45 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mergeDirectives = void 0; const graphql_1 = require("graphql"); const utils_1 = require("@graphql-tools/utils"); function mergeDirectives(directives) { if (directives.size === 0) { return undefined; } if (directives.size === 1) { const directive = directives.values().next().value; return directive; } let name; let description; const locations = new Set(); const args = {}; const extensionsSet = new Set(); let isRepeatable = false; for (const directive of directives) { name = directive.name; if (directive.description) { description = directive.description; } for (const location of directive.locations) { locations.add(location); } for (const arg of directive.args) { args[arg.name] = arg; } isRepeatable = isRepeatable || directive.isRepeatable; if (directive.extensions) { extensionsSet.add(directive.extensions); } } return new graphql_1.GraphQLDirective({ name: name, description: description, locations: Array.from(locations), args, isRepeatable, extensions: extensionsSet.size > 0 ? (0, utils_1.mergeDeep)([...extensionsSet]) : undefined, }); } exports.mergeDirectives = mergeDirectives;