Socket
Socket
Sign inDemoInstall

@graphql-tools/utils

Package Overview
Dependencies
Maintainers
3
Versions
1273
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/utils - npm Package Compare versions

Comparing version 10.4.0-alpha-20240811044002-bee8e8bea376d3e2e707ec5857defd33a935ae27 to 10.4.0-rc-20240811220920-e7aa7ff2bc82aad4be9e4eaf38fc887a51be9239

cjs/getDirectiveExtensions.js

43

cjs/extractExtensionsFromSchema.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractExtensionsFromSchema = void 0;
const helpers_js_1 = require("./helpers.js");
const Interfaces_js_1 = require("./Interfaces.js");
const mapSchema_js_1 = require("./mapSchema.js");
function handleDirectiveExtensions(extensions = {}) {
function handleDirectiveExtensions(extensions, removeDirectives) {
extensions = extensions || {};
const { directives: existingDirectives, ...rest } = extensions;
const finalExtensions = {
...extensions,
...rest,
};
const directives = finalExtensions.directives;
if (directives != null) {
for (const directiveName in directives) {
const directiveObj = directives[directiveName];
if (!Array.isArray(directiveObj)) {
directives[directiveName] = [directiveObj];
if (!removeDirectives) {
if (existingDirectives != null) {
const directives = {};
for (const directiveName in existingDirectives) {
directives[directiveName] = [...(0, helpers_js_1.asArray)(existingDirectives[directiveName])];
}
finalExtensions.directives = directives;
}

@@ -21,5 +24,5 @@ }

}
function extractExtensionsFromSchema(schema) {
function extractExtensionsFromSchema(schema, removeDirectives = false) {
const result = {
schemaExtensions: handleDirectiveExtensions(schema.extensions),
schemaExtensions: handleDirectiveExtensions(schema.extensions, removeDirectives),
types: {},

@@ -32,3 +35,3 @@ };

type: 'object',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -41,3 +44,3 @@ return type;

type: 'interface',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -49,3 +52,3 @@ return type;

arguments: {},
extensions: handleDirectiveExtensions(field.extensions),
extensions: handleDirectiveExtensions(field.extensions, removeDirectives),
};

@@ -56,3 +59,3 @@ const args = field.args;

result.types[typeName].fields[fieldName].arguments[argName] =
handleDirectiveExtensions(args[argName].extensions);
handleDirectiveExtensions(args[argName].extensions, removeDirectives);
}

@@ -66,3 +69,3 @@ }

type: 'enum',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -72,3 +75,3 @@ return type;

[Interfaces_js_1.MapperKind.ENUM_VALUE]: (value, typeName, _schema, valueName) => {
result.types[typeName].values[valueName] = handleDirectiveExtensions(value.extensions);
result.types[typeName].values[valueName] = handleDirectiveExtensions(value.extensions, removeDirectives);
return value;

@@ -79,3 +82,3 @@ },

type: 'scalar',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -87,3 +90,3 @@ return type;

type: 'union',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -96,3 +99,3 @@ return type;

type: 'input',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -103,3 +106,3 @@ return type;

result.types[typeName].fields[fieldName] = {
extensions: handleDirectiveExtensions(field.extensions),
extensions: handleDirectiveExtensions(field.extensions, removeDirectives),
};

@@ -106,0 +109,0 @@ return field;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDirective = exports.getDirectives = exports.getDirectiveInExtensions = exports.getDirectivesInExtensions = void 0;
const getArgumentValues_js_1 = require("./getArgumentValues.js");
const getDirectiveExtensions_js_1 = require("./getDirectiveExtensions.js");
function getDirectivesInExtensions(node, pathToDirectivesInExtensions = ['directives']) {
return pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node?.extensions);
const directiveExtensions = (0, getDirectiveExtensions_js_1.getDirectiveExtensions)(node, undefined, pathToDirectivesInExtensions);
return Object.entries(directiveExtensions)
.map(([directiveName, directiveArgsArr]) => directiveArgsArr?.map(directiveArgs => ({
name: directiveName,
args: directiveArgs,
})))
.flat(Infinity)
.filter(Boolean);
}
exports.getDirectivesInExtensions = getDirectivesInExtensions;
function _getDirectiveInExtensions(directivesInExtensions, directiveName) {
const directiveInExtensions = directivesInExtensions.filter(directiveAnnotation => directiveAnnotation.name === directiveName);
if (!directiveInExtensions.length) {
return undefined;
}
return directiveInExtensions.map(directive => directive.args ?? {});
}
function getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions = ['directives']) {
const directivesInExtensions = pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node?.extensions);
if (directivesInExtensions === undefined) {
return undefined;
}
if (Array.isArray(directivesInExtensions)) {
return _getDirectiveInExtensions(directivesInExtensions, directiveName);
}
// Support condensed format by converting to longer format
// The condensed format does not preserve ordering of directives when repeatable directives are used.
// See https://github.com/ardatan/graphql-tools/issues/2534
const reformattedDirectivesInExtensions = [];
for (const [name, argsOrArrayOfArgs] of Object.entries(directivesInExtensions)) {
if (Array.isArray(argsOrArrayOfArgs)) {
for (const args of argsOrArrayOfArgs) {
reformattedDirectivesInExtensions.push({ name, args });
}
}
else {
reformattedDirectivesInExtensions.push({ name, args: argsOrArrayOfArgs });
}
}
return _getDirectiveInExtensions(reformattedDirectivesInExtensions, directiveName);
const directiveExtensions = (0, getDirectiveExtensions_js_1.getDirectiveExtensions)(node, undefined, pathToDirectivesInExtensions);
return directiveExtensions[directiveName];
}
exports.getDirectiveInExtensions = getDirectiveInExtensions;
function getDirectives(schema, node, pathToDirectivesInExtensions = ['directives']) {
const directivesInExtensions = getDirectivesInExtensions(node, pathToDirectivesInExtensions);
if (directivesInExtensions != null && directivesInExtensions.length > 0) {
return directivesInExtensions;
}
const schemaDirectives = schema && schema.getDirectives ? schema.getDirectives() : [];
const schemaDirectiveMap = schemaDirectives.reduce((schemaDirectiveMap, schemaDirective) => {
schemaDirectiveMap[schemaDirective.name] = schemaDirective;
return schemaDirectiveMap;
}, {});
let astNodes = [];
if (node.astNode) {
astNodes.push(node.astNode);
}
if ('extensionASTNodes' in node && node.extensionASTNodes) {
astNodes = [...astNodes, ...node.extensionASTNodes];
}
const result = [];
for (const astNode of astNodes) {
if (astNode.directives) {
for (const directiveNode of astNode.directives) {
const schemaDirective = schemaDirectiveMap[directiveNode.name.value];
if (schemaDirective) {
result.push({
name: directiveNode.name.value,
args: (0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode),
});
}
}
}
}
return result;
const directiveExtensions = (0, getDirectiveExtensions_js_1.getDirectiveExtensions)(node, schema, pathToDirectivesInExtensions);
return Object.entries(directiveExtensions)
.map(([directiveName, directiveArgsArr]) => directiveArgsArr?.map(directiveArgs => ({
name: directiveName,
args: directiveArgs,
})))
.flat(Infinity)
.filter(Boolean);
}
exports.getDirectives = getDirectives;
function getDirective(schema, node, directiveName, pathToDirectivesInExtensions = ['directives']) {
const directiveInExtensions = getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions);
if (directiveInExtensions != null) {
return directiveInExtensions;
}
const schemaDirective = schema && schema.getDirective ? schema.getDirective(directiveName) : undefined;
if (schemaDirective == null) {
return undefined;
}
let astNodes = [];
if (node.astNode) {
astNodes.push(node.astNode);
}
if ('extensionASTNodes' in node && node.extensionASTNodes) {
astNodes = [...astNodes, ...node.extensionASTNodes];
}
const result = [];
for (const astNode of astNodes) {
if (astNode.directives) {
for (const directiveNode of astNode.directives) {
if (directiveNode.name.value === directiveName) {
result.push((0, getArgumentValues_js_1.getArgumentValues)(schemaDirective, directiveNode));
}
}
}
}
if (!result.length) {
return undefined;
}
return result;
const directiveExtensions = (0, getDirectiveExtensions_js_1.getDirectiveExtensions)(node, schema, pathToDirectivesInExtensions);
return directiveExtensions[directiveName];
}
exports.getDirective = getDirective;

@@ -62,2 +62,1 @@ "use strict";

tslib_1.__exportStar(require("./debugTimer.js"), exports);
tslib_1.__exportStar(require("./createDeferred.js"), exports);
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoize2of5 = exports.memoize2of4 = exports.memoize5 = exports.memoize4 = exports.memoize3of4 = exports.memoize3 = exports.memoize2 = exports.memoize1 = void 0;
exports.memoize2of5 = exports.memoize2of4 = exports.memoize5 = exports.memoize4 = exports.memoize3 = exports.memoize2 = exports.memoize1 = void 0;
function memoize1(fn) {

@@ -69,33 +69,2 @@ const memoize1cache = new WeakMap();

exports.memoize3 = memoize3;
function memoize3of4(fn) {
const memoize3Cache = new WeakMap();
return function memoized(a1, a2, a3, a4) {
let cache2 = memoize3Cache.get(a1);
if (!cache2) {
cache2 = new WeakMap();
memoize3Cache.set(a1, cache2);
const cache3 = new WeakMap();
cache2.set(a2, cache3);
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
let cache3 = cache2.get(a2);
if (!cache3) {
cache3 = new WeakMap();
cache2.set(a2, cache3);
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
const cachedValue = cache3.get(a3);
if (cachedValue === undefined) {
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
return cachedValue;
};
}
exports.memoize3of4 = memoize3of4;
function memoize4(fn) {

@@ -102,0 +71,0 @@ const memoize4Cache = new WeakMap();

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.mergeIncrementalResult = void 0;
const tslib_1 = require("tslib");
const dlv_1 = tslib_1.__importDefault(require("dlv"));
const merge_1 = require("dset/merge");
const pathsMap = new WeakMap();
function mergeIncrementalResult({ incrementalResult, executionResult, }) {
let path = [
'data',
...(incrementalResult.path ?? []),
];
for (const result of [executionResult, incrementalResult]) {
if (result.pending) {
let paths = pathsMap.get(executionResult);
if (paths === undefined) {
paths = new Map();
pathsMap.set(executionResult, paths);
}
for (const { id, path } of result.pending) {
paths.set(id, ['data', ...path]);
}
const path = ['data', ...(incrementalResult.path ?? [])];
if (incrementalResult.items) {
for (const item of incrementalResult.items) {
(0, merge_1.dset)(executionResult, path, item);
// Increment the last path segment (the array index) to merge the next item at the next index
path[path.length - 1]++;
}
}
const items = incrementalResult.items;
if (items) {
const id = incrementalResult.id;
if (id) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
const list = (0, dlv_1.default)(executionResult, path);
list.push(...items);
}
else {
const path = ['data', ...(incrementalResult.path ?? [])];
for (const item of items) {
(0, merge_1.dset)(executionResult, path, item);
// Increment the last path segment (the array index) to merge the next item at the next index
path[path.length - 1]++;
}
}
if (incrementalResult.data) {
(0, merge_1.dset)(executionResult, path, incrementalResult.data);
}
const data = incrementalResult.data;
if (data) {
const id = incrementalResult.id;
if (id) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
const subPath = incrementalResult.subPath;
if (subPath !== undefined) {
path = [...path, ...subPath];
}
}
(0, merge_1.dset)(executionResult, path, data);
}
if (incrementalResult.errors) {

@@ -75,13 +32,3 @@ executionResult.errors = executionResult.errors || [];

}
if (incrementalResult.completed) {
// Remove tracking and add additional errors
for (const { id, errors } of incrementalResult.completed) {
pathsMap.get(executionResult)?.delete(id);
if (errors) {
executionResult.errors = executionResult.errors || [];
executionResult.errors.push(...errors);
}
}
}
}
exports.mergeIncrementalResult = mergeIncrementalResult;

@@ -358,3 +358,3 @@ "use strict";

const argName = arg.name;
const argValue = args[argName];
const argValue = args?.[argName];
if (argValue !== undefined) {

@@ -403,13 +403,5 @@ const value = (0, astFromValue_js_1.astFromValue)(argValue, arg.type);

const directiveNodes = [];
for (const directiveName in directiveValues) {
const arrayOrSingleValue = directiveValues[directiveName];
const directive = schema?.getDirective(directiveName);
if (Array.isArray(arrayOrSingleValue)) {
for (const value of arrayOrSingleValue) {
directiveNodes.push(makeDirectiveNode(directiveName, value, directive));
}
}
else {
directiveNodes.push(makeDirectiveNode(directiveName, arrayOrSingleValue, directive));
}
for (const { name, args } of directiveValues) {
const directive = schema?.getDirective(name);
directiveNodes.push(makeDirectiveNode(name, args, directive));
}

@@ -416,0 +408,0 @@ return directiveNodes;

@@ -0,14 +1,17 @@

import { asArray } from './helpers.js';
import { MapperKind } from './Interfaces.js';
import { mapSchema } from './mapSchema.js';
function handleDirectiveExtensions(extensions = {}) {
function handleDirectiveExtensions(extensions, removeDirectives) {
extensions = extensions || {};
const { directives: existingDirectives, ...rest } = extensions;
const finalExtensions = {
...extensions,
...rest,
};
const directives = finalExtensions.directives;
if (directives != null) {
for (const directiveName in directives) {
const directiveObj = directives[directiveName];
if (!Array.isArray(directiveObj)) {
directives[directiveName] = [directiveObj];
if (!removeDirectives) {
if (existingDirectives != null) {
const directives = {};
for (const directiveName in existingDirectives) {
directives[directiveName] = [...asArray(existingDirectives[directiveName])];
}
finalExtensions.directives = directives;
}

@@ -18,5 +21,5 @@ }

}
export function extractExtensionsFromSchema(schema) {
export function extractExtensionsFromSchema(schema, removeDirectives = false) {
const result = {
schemaExtensions: handleDirectiveExtensions(schema.extensions),
schemaExtensions: handleDirectiveExtensions(schema.extensions, removeDirectives),
types: {},

@@ -29,3 +32,3 @@ };

type: 'object',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -38,3 +41,3 @@ return type;

type: 'interface',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -46,3 +49,3 @@ return type;

arguments: {},
extensions: handleDirectiveExtensions(field.extensions),
extensions: handleDirectiveExtensions(field.extensions, removeDirectives),
};

@@ -53,3 +56,3 @@ const args = field.args;

result.types[typeName].fields[fieldName].arguments[argName] =
handleDirectiveExtensions(args[argName].extensions);
handleDirectiveExtensions(args[argName].extensions, removeDirectives);
}

@@ -63,3 +66,3 @@ }

type: 'enum',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -69,3 +72,3 @@ return type;

[MapperKind.ENUM_VALUE]: (value, typeName, _schema, valueName) => {
result.types[typeName].values[valueName] = handleDirectiveExtensions(value.extensions);
result.types[typeName].values[valueName] = handleDirectiveExtensions(value.extensions, removeDirectives);
return value;

@@ -76,3 +79,3 @@ },

type: 'scalar',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -84,3 +87,3 @@ return type;

type: 'union',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -93,3 +96,3 @@ return type;

type: 'input',
extensions: handleDirectiveExtensions(type.extensions),
extensions: handleDirectiveExtensions(type.extensions, removeDirectives),
};

@@ -100,3 +103,3 @@ return type;

result.types[typeName].fields[fieldName] = {
extensions: handleDirectiveExtensions(field.extensions),
extensions: handleDirectiveExtensions(field.extensions, removeDirectives),
};

@@ -103,0 +106,0 @@ return field;

@@ -1,99 +0,29 @@

import { getArgumentValues } from './getArgumentValues.js';
import { getDirectiveExtensions } from './getDirectiveExtensions.js';
export function getDirectivesInExtensions(node, pathToDirectivesInExtensions = ['directives']) {
return pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node?.extensions);
const directiveExtensions = getDirectiveExtensions(node, undefined, pathToDirectivesInExtensions);
return Object.entries(directiveExtensions)
.map(([directiveName, directiveArgsArr]) => directiveArgsArr?.map(directiveArgs => ({
name: directiveName,
args: directiveArgs,
})))
.flat(Infinity)
.filter(Boolean);
}
function _getDirectiveInExtensions(directivesInExtensions, directiveName) {
const directiveInExtensions = directivesInExtensions.filter(directiveAnnotation => directiveAnnotation.name === directiveName);
if (!directiveInExtensions.length) {
return undefined;
}
return directiveInExtensions.map(directive => directive.args ?? {});
}
export function getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions = ['directives']) {
const directivesInExtensions = pathToDirectivesInExtensions.reduce((acc, pathSegment) => (acc == null ? acc : acc[pathSegment]), node?.extensions);
if (directivesInExtensions === undefined) {
return undefined;
}
if (Array.isArray(directivesInExtensions)) {
return _getDirectiveInExtensions(directivesInExtensions, directiveName);
}
// Support condensed format by converting to longer format
// The condensed format does not preserve ordering of directives when repeatable directives are used.
// See https://github.com/ardatan/graphql-tools/issues/2534
const reformattedDirectivesInExtensions = [];
for (const [name, argsOrArrayOfArgs] of Object.entries(directivesInExtensions)) {
if (Array.isArray(argsOrArrayOfArgs)) {
for (const args of argsOrArrayOfArgs) {
reformattedDirectivesInExtensions.push({ name, args });
}
}
else {
reformattedDirectivesInExtensions.push({ name, args: argsOrArrayOfArgs });
}
}
return _getDirectiveInExtensions(reformattedDirectivesInExtensions, directiveName);
const directiveExtensions = getDirectiveExtensions(node, undefined, pathToDirectivesInExtensions);
return directiveExtensions[directiveName];
}
export function getDirectives(schema, node, pathToDirectivesInExtensions = ['directives']) {
const directivesInExtensions = getDirectivesInExtensions(node, pathToDirectivesInExtensions);
if (directivesInExtensions != null && directivesInExtensions.length > 0) {
return directivesInExtensions;
}
const schemaDirectives = schema && schema.getDirectives ? schema.getDirectives() : [];
const schemaDirectiveMap = schemaDirectives.reduce((schemaDirectiveMap, schemaDirective) => {
schemaDirectiveMap[schemaDirective.name] = schemaDirective;
return schemaDirectiveMap;
}, {});
let astNodes = [];
if (node.astNode) {
astNodes.push(node.astNode);
}
if ('extensionASTNodes' in node && node.extensionASTNodes) {
astNodes = [...astNodes, ...node.extensionASTNodes];
}
const result = [];
for (const astNode of astNodes) {
if (astNode.directives) {
for (const directiveNode of astNode.directives) {
const schemaDirective = schemaDirectiveMap[directiveNode.name.value];
if (schemaDirective) {
result.push({
name: directiveNode.name.value,
args: getArgumentValues(schemaDirective, directiveNode),
});
}
}
}
}
return result;
const directiveExtensions = getDirectiveExtensions(node, schema, pathToDirectivesInExtensions);
return Object.entries(directiveExtensions)
.map(([directiveName, directiveArgsArr]) => directiveArgsArr?.map(directiveArgs => ({
name: directiveName,
args: directiveArgs,
})))
.flat(Infinity)
.filter(Boolean);
}
export function getDirective(schema, node, directiveName, pathToDirectivesInExtensions = ['directives']) {
const directiveInExtensions = getDirectiveInExtensions(node, directiveName, pathToDirectivesInExtensions);
if (directiveInExtensions != null) {
return directiveInExtensions;
}
const schemaDirective = schema && schema.getDirective ? schema.getDirective(directiveName) : undefined;
if (schemaDirective == null) {
return undefined;
}
let astNodes = [];
if (node.astNode) {
astNodes.push(node.astNode);
}
if ('extensionASTNodes' in node && node.extensionASTNodes) {
astNodes = [...astNodes, ...node.extensionASTNodes];
}
const result = [];
for (const astNode of astNodes) {
if (astNode.directives) {
for (const directiveNode of astNode.directives) {
if (directiveNode.name.value === directiveName) {
result.push(getArgumentValues(schemaDirective, directiveNode));
}
}
}
}
if (!result.length) {
return undefined;
}
return result;
const directiveExtensions = getDirectiveExtensions(node, schema, pathToDirectivesInExtensions);
return directiveExtensions[directiveName];
}

@@ -57,2 +57,1 @@ export * from './loaders.js';

export * from './debugTimer.js';
export * from './createDeferred.js';

@@ -63,32 +63,2 @@ export function memoize1(fn) {

}
export function memoize3of4(fn) {
const memoize3Cache = new WeakMap();
return function memoized(a1, a2, a3, a4) {
let cache2 = memoize3Cache.get(a1);
if (!cache2) {
cache2 = new WeakMap();
memoize3Cache.set(a1, cache2);
const cache3 = new WeakMap();
cache2.set(a2, cache3);
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
let cache3 = cache2.get(a2);
if (!cache3) {
cache3 = new WeakMap();
cache2.set(a2, cache3);
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
const cachedValue = cache3.get(a3);
if (cachedValue === undefined) {
const newValue = fn(a1, a2, a3, a4);
cache3.set(a3, newValue);
return newValue;
}
return cachedValue;
};
}
export function memoize4(fn) {

@@ -95,0 +65,0 @@ const memoize4Cache = new WeakMap();

@@ -1,56 +0,14 @@

import delve from 'dlv';
import { dset } from 'dset/merge';
const pathsMap = new WeakMap();
export function mergeIncrementalResult({ incrementalResult, executionResult, }) {
let path = [
'data',
...(incrementalResult.path ?? []),
];
for (const result of [executionResult, incrementalResult]) {
if (result.pending) {
let paths = pathsMap.get(executionResult);
if (paths === undefined) {
paths = new Map();
pathsMap.set(executionResult, paths);
}
for (const { id, path } of result.pending) {
paths.set(id, ['data', ...path]);
}
const path = ['data', ...(incrementalResult.path ?? [])];
if (incrementalResult.items) {
for (const item of incrementalResult.items) {
dset(executionResult, path, item);
// Increment the last path segment (the array index) to merge the next item at the next index
path[path.length - 1]++;
}
}
const items = incrementalResult.items;
if (items) {
const id = incrementalResult.id;
if (id) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
const list = delve(executionResult, path);
list.push(...items);
}
else {
const path = ['data', ...(incrementalResult.path ?? [])];
for (const item of items) {
dset(executionResult, path, item);
// Increment the last path segment (the array index) to merge the next item at the next index
path[path.length - 1]++;
}
}
if (incrementalResult.data) {
dset(executionResult, path, incrementalResult.data);
}
const data = incrementalResult.data;
if (data) {
const id = incrementalResult.id;
if (id) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
const subPath = incrementalResult.subPath;
if (subPath !== undefined) {
path = [...path, ...subPath];
}
}
dset(executionResult, path, data);
}
if (incrementalResult.errors) {

@@ -71,12 +29,2 @@ executionResult.errors = executionResult.errors || [];

}
if (incrementalResult.completed) {
// Remove tracking and add additional errors
for (const { id, errors } of incrementalResult.completed) {
pathsMap.get(executionResult)?.delete(id);
if (errors) {
executionResult.errors = executionResult.errors || [];
executionResult.errors.push(...errors);
}
}
}
}

@@ -338,3 +338,3 @@ import { GraphQLDeprecatedDirective, isEnumType, isInputObjectType, isInterfaceType, isIntrospectionType, isObjectType, isScalarType, isSpecifiedDirective, isSpecifiedScalarType, isUnionType, Kind, print, } from 'graphql';

const argName = arg.name;
const argValue = args[argName];
const argValue = args?.[argName];
if (argValue !== undefined) {

@@ -382,15 +382,7 @@ const value = astFromValue(argValue, arg.type);

const directiveNodes = [];
for (const directiveName in directiveValues) {
const arrayOrSingleValue = directiveValues[directiveName];
const directive = schema?.getDirective(directiveName);
if (Array.isArray(arrayOrSingleValue)) {
for (const value of arrayOrSingleValue) {
directiveNodes.push(makeDirectiveNode(directiveName, value, directive));
}
}
else {
directiveNodes.push(makeDirectiveNode(directiveName, arrayOrSingleValue, directive));
}
for (const { name, args } of directiveValues) {
const directive = schema?.getDirective(name);
directiveNodes.push(makeDirectiveNode(name, args, directive));
}
return directiveNodes;
}
{
"name": "@graphql-tools/utils",
"version": "10.4.0-alpha-20240811044002-bee8e8bea376d3e2e707ec5857defd33a935ae27",
"version": "10.4.0-rc-20240811220920-e7aa7ff2bc82aad4be9e4eaf38fc887a51be9239",
"description": "Common package containing utils and types for GraphQL tools",

@@ -12,3 +12,2 @@ "sideEffects": false,

"cross-inspect": "1.0.1",
"dlv": "^1.1.3",
"dset": "^3.1.2",

@@ -15,0 +14,0 @@ "tslib": "^2.4.0"

import { GraphQLSchema } from 'graphql';
import { SchemaExtensions } from './types.js';
export declare function extractExtensionsFromSchema(schema: GraphQLSchema): SchemaExtensions;
export declare function extractExtensionsFromSchema(schema: GraphQLSchema, removeDirectives?: boolean): SchemaExtensions;

@@ -57,2 +57,1 @@ export * from './loaders.js';

export * from './debugTimer.js';
export * from './createDeferred.js';

@@ -20,12 +20,2 @@ import { DefinitionNode, DocumentNode, EnumTypeDefinitionNode, EnumTypeExtensionNode, FieldDefinitionNode, FieldNode, FragmentDefinitionNode, GraphQLArgument, GraphQLArgumentConfig, GraphQLDirective, GraphQLEnumType, GraphQLEnumValue, GraphQLEnumValueConfig, GraphQLError, GraphQLField, GraphQLFieldConfig, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLIsTypeOfFn, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLScalarLiteralParser, GraphQLScalarSerializer, GraphQLScalarType, GraphQLScalarValueParser, GraphQLSchema, GraphQLType, GraphQLTypeResolver, GraphQLUnionType, InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, OperationTypeNode, ScalarTypeDefinitionNode, ScalarTypeExtensionNode, SelectionNode, Source, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql';

items?: TData | null;
id?: string;
subPath?: ReadonlyArray<string | number>;
pending?: ReadonlyArray<{
id: string;
path: ReadonlyArray<string | number>;
}>;
completed?: ReadonlyArray<{
id: string;
errors?: ReadonlyArray<GraphQLError>;
}>;
}

@@ -32,0 +22,0 @@ export interface ExecutionRequest<TVariables extends Record<string, any> = any, TContext = any, TRootValue = any, TExtensions = Record<string, any>, TReturn = any> {

export declare function memoize1<F extends (a1: any) => any>(fn: F): F;
export declare function memoize2<F extends (a1: any, a2: any) => any>(fn: F): F;
export declare function memoize3<F extends (a1: any, a2: any, a3: any) => any>(fn: F): F;
export declare function memoize3of4<F extends (a1: any, a2: any, a3: any, a4: any) => any>(fn: F): F;
export declare function memoize4<F extends (a1: any, a2: any, a3: any, a4: any) => any>(fn: F): F;

@@ -6,0 +5,0 @@ export declare function memoize5<F extends (a1: any, a2: any, a3: any, a4: any, a5: any) => any>(fn: F): F;

import { DirectiveDefinitionNode, DirectiveNode, DocumentNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLArgument, GraphQLDirective, GraphQLEnumType, GraphQLEnumValue, GraphQLField, GraphQLInputField, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLUnionType, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, SchemaDefinitionNode, SchemaExtensionNode, UnionTypeDefinitionNode } from 'graphql';
import { DirectiveAnnotation } from './get-directives.js';
import { GetDocumentNodeFromSchemaOptions, Maybe, PrintSchemaWithDirectivesOptions } from './types.js';

@@ -20,3 +21,3 @@ export declare function getDocumentNodeFromSchema(schema: GraphQLSchema, options?: GetDocumentNodeFromSchemaOptions): DocumentNode;

export declare function makeDeprecatedDirective(deprecationReason: string): DirectiveNode;
export declare function makeDirectiveNode(name: string, args: Record<string, any>, directive?: Maybe<GraphQLDirective>): DirectiveNode;
export declare function makeDirectiveNodes(schema: Maybe<GraphQLSchema>, directiveValues: Record<string, any>): Array<DirectiveNode>;
export declare function makeDirectiveNode(name: string, args?: Record<string, any>, directive?: Maybe<GraphQLDirective>): DirectiveNode;
export declare function makeDirectiveNodes(schema: Maybe<GraphQLSchema>, directiveValues: DirectiveAnnotation[]): Array<DirectiveNode>;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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