Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@graphql-tools/delegate

Package Overview
Dependencies
Maintainers
3
Versions
1538
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/delegate - npm Package Compare versions

Comparing version 10.0.28 to 10.0.29-alpha-20241031093119-758db604a5159bc55caa775bd733e0322cfb67ec

46

cjs/extractUnavailableFields.js

@@ -90,12 +90,35 @@ "use strict";

});
function getByPath(object, path) {
let current = object;
for (const pathSegment of path) {
if (current == null) {
return;
function fieldExistsInSelectionSet(node, path) {
let currentNode = node;
const isArrayOfSelectionNodes = (node) => Array.isArray(node);
for (const [segment, fieldName] of path) {
if (!currentNode) {
return false;
}
current = current[pathSegment];
if (isArrayOfSelectionNodes(currentNode) && fieldName) {
currentNode = currentNode.find(selectionNode => {
return selectionNode.name?.value === fieldName;
});
}
else {
currentNode = currentNode[segment];
}
}
return current;
return !!currentNode;
}
function getPathWithFieldNames(node, path) {
const pathWithFieldNames = [];
let currentNode = node;
const isArrayOfSelectionNodes = (node) => Array.isArray(node);
for (const segment of path) {
currentNode = currentNode[segment];
if (!isArrayOfSelectionNodes(currentNode) && currentNode.kind === graphql_1.Kind.FIELD) {
pathWithFieldNames.push([segment, currentNode.name.value]);
}
else {
pathWithFieldNames.push([segment]);
}
}
return pathWithFieldNames;
}
function subtractSelectionSets(selectionSetA, selectionSetB) {

@@ -105,5 +128,8 @@ return (0, graphql_1.visit)(selectionSetA, {

enter(node, _key, _parent, path) {
if (!node.selectionSet &&
getByPath(selectionSetB, path.slice(0, -1))?.some(selection => selection.kind === graphql_1.Kind.FIELD && selection.name.value === node.name.value)) {
return null;
if (!node.selectionSet) {
const pathWithFieldNames = getPathWithFieldNames(selectionSetA, path);
const fieldExists = fieldExistsInSelectionSet(selectionSetB, pathWithFieldNames);
if (fieldExists) {
return null;
}
}

@@ -110,0 +136,0 @@ },

@@ -87,12 +87,35 @@ import { getNamedType, isAbstractType, isInterfaceType, isLeafType, isObjectType, isUnionType, Kind, visit, } from 'graphql';

});
function getByPath(object, path) {
let current = object;
for (const pathSegment of path) {
if (current == null) {
return;
function fieldExistsInSelectionSet(node, path) {
let currentNode = node;
const isArrayOfSelectionNodes = (node) => Array.isArray(node);
for (const [segment, fieldName] of path) {
if (!currentNode) {
return false;
}
current = current[pathSegment];
if (isArrayOfSelectionNodes(currentNode) && fieldName) {
currentNode = currentNode.find(selectionNode => {
return selectionNode.name?.value === fieldName;
});
}
else {
currentNode = currentNode[segment];
}
}
return current;
return !!currentNode;
}
function getPathWithFieldNames(node, path) {
const pathWithFieldNames = [];
let currentNode = node;
const isArrayOfSelectionNodes = (node) => Array.isArray(node);
for (const segment of path) {
currentNode = currentNode[segment];
if (!isArrayOfSelectionNodes(currentNode) && currentNode.kind === Kind.FIELD) {
pathWithFieldNames.push([segment, currentNode.name.value]);
}
else {
pathWithFieldNames.push([segment]);
}
}
return pathWithFieldNames;
}
export function subtractSelectionSets(selectionSetA, selectionSetB) {

@@ -102,5 +125,8 @@ return visit(selectionSetA, {

enter(node, _key, _parent, path) {
if (!node.selectionSet &&
getByPath(selectionSetB, path.slice(0, -1))?.some(selection => selection.kind === Kind.FIELD && selection.name.value === node.name.value)) {
return null;
if (!node.selectionSet) {
const pathWithFieldNames = getPathWithFieldNames(selectionSetA, path);
const fieldExists = fieldExistsInSelectionSet(selectionSetB, pathWithFieldNames);
if (fieldExists) {
return null;
}
}

@@ -107,0 +133,0 @@ },

{
"name": "@graphql-tools/delegate",
"version": "10.0.28",
"version": "10.0.29-alpha-20241031093119-758db604a5159bc55caa775bd733e0322cfb67ec",
"description": "A set of utils for faster development of GraphQL tools",

@@ -5,0 +5,0 @@ "sideEffects": false,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc