Socket
Socket
Sign inDemoInstall

@graphql-tools/utils

Package Overview
Dependencies
Maintainers
0
Versions
1269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.3.0-alpha-20240702193839-5ddff7cfe353771d7175304a6feefa2c8b073e6c to 10.3.0-alpha-20240705095940-3ce4d8846c1d2640ad958b9619c1a6912f2e6f10

1

cjs/index.js

@@ -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.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) {
if (incrementalResult.id) {
const id = incrementalResult.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(...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]++;
}
else {
const path = ['data', ...(incrementalResult.path ?? [])];
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]++;
}
}
}
if (incrementalResult.data) {
if (incrementalResult.id) {
const id = incrementalResult.id;
if (id !== undefined) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
}
}
(0, merge_1.dset)(executionResult, path, incrementalResult.data);

@@ -71,13 +32,3 @@ }

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

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

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

@@ -1,50 +0,12 @@

import dlv 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) {
if (incrementalResult.id) {
const id = incrementalResult.id;
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
const list = dlv(executionResult, path);
list.push(...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]++;
}
else {
const path = ['data', ...(incrementalResult.path ?? [])];
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]++;
}
}
}
if (incrementalResult.data) {
if (incrementalResult.id) {
const id = incrementalResult.id;
if (id !== undefined) {
path = pathsMap.get(executionResult)?.get(id);
if (path === undefined) {
throw new Error('Invalid incremental delivery format.');
}
}
}
dset(executionResult, path, incrementalResult.data);

@@ -67,12 +29,2 @@ }

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

3

package.json
{
"name": "@graphql-tools/utils",
"version": "10.3.0-alpha-20240702193839-5ddff7cfe353771d7175304a6feefa2c8b073e6c",
"version": "10.3.0-alpha-20240705095940-3ce4d8846c1d2640ad958b9619c1a6912f2e6f10",
"description": "Common package containing utils and types for GraphQL tools",

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

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

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

@@ -7,1 +7,8 @@ import { ExecutionRequest, ExecutionResult } from './Interfaces.js';

export type Executor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = <TReturn = any, TArgs extends Record<string, any> = Record<string, any>, TContext extends TBaseContext = TBaseContext, TRoot = any, TExtensions extends TBaseExtensions = TBaseExtensions>(request: ExecutionRequest<TArgs, TContext, TRoot, TExtensions, TReturn>) => MaybePromise<MaybeAsyncIterable<ExecutionResult<TReturn>>>;
export type DisposableSyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = SyncExecutor<TBaseContext, TBaseExtensions> & {
[Symbol.dispose]?: () => void;
};
export type DisposableAsyncExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = AsyncExecutor<TBaseContext, TBaseExtensions> & {
[Symbol.dispose]?: () => void;
};
export type DisposableExecutor<TBaseContext = Record<string, any>, TBaseExtensions = Record<string, any>> = DisposableSyncExecutor<TBaseContext, TBaseExtensions> | DisposableAsyncExecutor<TBaseContext, TBaseExtensions>;

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

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

@@ -20,11 +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;
pending?: ReadonlyArray<{
id: string;
path: ReadonlyArray<string | number>;
}>;
completed?: ReadonlyArray<{
id: string;
errors?: ReadonlyArray<GraphQLError>;
}>;
}

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc