@graphql-tools/merge
Advanced tools
Comparing version 9.0.1 to 9.0.2-rc-20240220122323-43df81236732631d10ea769020a3736f18c7e06d
"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"); | ||
@@ -72,23 +71,7 @@ function directiveAlreadyExists(directivesArr, otherDirective) { | ||
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, | ||
arguments: deduplicateLists(existingNode.arguments || [], node.arguments || [], (arg, existingArgs) => !nameAlreadyExists(arg.name, existingArgs.map(a => a.name))), | ||
locations: [ | ||
@@ -95,0 +78,0 @@ ...existingNode.locations, |
@@ -1,2 +0,1 @@ | ||
import { print, } from 'graphql'; | ||
import { isSome } from '@graphql-tools/utils'; | ||
@@ -68,23 +67,7 @@ function directiveAlreadyExists(directivesArr, otherDirective) { | ||
} | ||
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, | ||
arguments: deduplicateLists(existingNode.arguments || [], node.arguments || [], (arg, existingArgs) => !nameAlreadyExists(arg.name, existingArgs.map(a => a.name))), | ||
locations: [ | ||
@@ -91,0 +74,0 @@ ...existingNode.locations, |
{ | ||
"name": "@graphql-tools/merge", | ||
"version": "9.0.1", | ||
"version": "9.0.2-rc-20240220122323-43df81236732631d10ea769020a3736f18c7e06d", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
95513
1909
2