Socket
Socket
Sign inDemoInstall

@graphql-tools/utils

Package Overview
Dependencies
Maintainers
3
Versions
1269
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.3.1 to 10.4.0-alpha-20240708191055-6aa94b70be0a68ccac6339230c2f5ff436909dc4

cjs/createDeferred.js

1

cjs/index.js

@@ -62,1 +62,2 @@ "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, }) {
const path = ['data', ...(incrementalResult.path ?? [])];
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]);
}
}
}
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]++;
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);
}
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);

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

}
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,1 +57,2 @@ export * from './loaders.js';

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

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

import dlv from 'dlv';
import { dset } from 'dset/merge';
const pathsMap = new WeakMap();
export function mergeIncrementalResult({ incrementalResult, executionResult, }) {
const path = ['data', ...(incrementalResult.path ?? [])];
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]);
}
}
}
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]++;
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);
}
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);

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

}
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.1",
"version": "10.4.0-alpha-20240708191055-6aa94b70be0a68ccac6339230c2f5ff436909dc4",
"description": "Common package containing utils and types for GraphQL tools",

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

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

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

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

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

@@ -20,2 +20,11 @@ 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>;
}>;
}

@@ -22,0 +31,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

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