@graphql-tools/utils 10.10.0 → 10.10.2-alpha-20251111213942-9ac3293e7ae48505cbdeea7fb5e7ceaeb76a64ae

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeIncrementalResult = mergeIncrementalResult;
4
- const merge_1 = require("dset/merge");
4
+ const mergeDeep_js_1 = require("./mergeDeep.js");
5
5
  function mergeIncrementalResult({ incrementalResult, executionResult, }) {
6
6
  const path = ['data', ...(incrementalResult.path ?? [])];
7
7
  if (incrementalResult.items) {
8
8
  for (const item of incrementalResult.items) {
9
- (0, merge_1.dset)(executionResult, path, item);
9
+ setObjectKeyPath(executionResult, path, item);
10
10
  // Increment the last path segment (the array index) to merge the next item at the next index
11
11
  path[path.length - 1]++;
12
12
  }
13
13
  }
14
14
  if (incrementalResult.data) {
15
- (0, merge_1.dset)(executionResult, path, incrementalResult.data);
15
+ setObjectKeyPath(executionResult, path, incrementalResult.data);
16
16
  }
17
17
  if (incrementalResult.errors) {
18
18
  executionResult.errors = executionResult.errors || [];
19
19
  executionResult.errors.push(...incrementalResult.errors);
20
20
  }
21
21
  if (incrementalResult.extensions) {
22
- (0, merge_1.dset)(executionResult, 'extensions', incrementalResult.extensions);
22
+ setObjectKeyPath(executionResult, ['extensions'], incrementalResult.extensions);
23
23
  }
24
24
  if (incrementalResult.incremental) {
25
25
  incrementalResult.incremental.forEach(incrementalSubResult => {
@@ -30,3 +30,24 @@ function mergeIncrementalResult({ incrementalResult, executionResult, }) {
30
30
  });
31
31
  }
32
32
  }
33
+ function setObjectKeyPath(obj, keyPath, value) {
34
+ let current = obj;
35
+ let i;
36
+ for (i = 0; i < keyPath.length - 1; i++) {
37
+ const key = keyPath[i];
38
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
39
+ return;
40
+ }
41
+ if (current[key] == null) {
42
+ // Determine if the next key is a number to create an array, otherwise create an object
43
+ current[key] = typeof keyPath[i + 1] === 'number' ? [] : {};
44
+ }
45
+ current = current[key];
46
+ }
47
+ const finalKey = keyPath[i];
48
+ if (finalKey === '__proto__' || finalKey === 'constructor' || finalKey === 'prototype') {
49
+ return;
50
+ }
51
+ const existingValue = current[finalKey];
52
+ current[finalKey] = existingValue != null ? (0, mergeDeep_js_1.mergeDeep)([existingValue, value]) : value;
53
+ }
@@ -123,7 +123,7 @@ function astFromSchema(schema, pathToDirectivesInExtensions) {
123
123
  return null;
124
124
  }
125
125
  const schemaNode = {
126
- kind: operationTypes != null ? graphql_1.Kind.SCHEMA_DEFINITION : graphql_1.Kind.SCHEMA_EXTENSION,
126
+ kind: operationTypes?.length ? graphql_1.Kind.SCHEMA_DEFINITION : graphql_1.Kind.SCHEMA_EXTENSION,
127
127
  operationTypes,
128
128
  // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
129
129
  directives: directives,
@@ -1,22 +1,22 @@
1
- import { dset } from 'dset/merge';
1
+ import { mergeDeep } from './mergeDeep.js';
2
2
  export function mergeIncrementalResult({ incrementalResult, executionResult, }) {
3
3
  const path = ['data', ...(incrementalResult.path ?? [])];
4
4
  if (incrementalResult.items) {
5
5
  for (const item of incrementalResult.items) {
6
- dset(executionResult, path, item);
6
+ setObjectKeyPath(executionResult, path, item);
7
7
  // Increment the last path segment (the array index) to merge the next item at the next index
8
8
  path[path.length - 1]++;
9
9
  }
10
10
  }
11
11
  if (incrementalResult.data) {
12
- dset(executionResult, path, incrementalResult.data);
12
+ setObjectKeyPath(executionResult, path, incrementalResult.data);
13
13
  }
14
14
  if (incrementalResult.errors) {
15
15
  executionResult.errors = executionResult.errors || [];
16
16
  executionResult.errors.push(...incrementalResult.errors);
17
17
  }
18
18
  if (incrementalResult.extensions) {
19
- dset(executionResult, 'extensions', incrementalResult.extensions);
19
+ setObjectKeyPath(executionResult, ['extensions'], incrementalResult.extensions);
20
20
  }
21
21
  if (incrementalResult.incremental) {
22
22
  incrementalResult.incremental.forEach(incrementalSubResult => {
@@ -27,3 +27,24 @@ export function mergeIncrementalResult({ incrementalResult, executionResult, })
27
27
  });
28
28
  }
29
29
  }
30
+ function setObjectKeyPath(obj, keyPath, value) {
31
+ let current = obj;
32
+ let i;
33
+ for (i = 0; i < keyPath.length - 1; i++) {
34
+ const key = keyPath[i];
35
+ if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
36
+ return;
37
+ }
38
+ if (current[key] == null) {
39
+ // Determine if the next key is a number to create an array, otherwise create an object
40
+ current[key] = typeof keyPath[i + 1] === 'number' ? [] : {};
41
+ }
42
+ current = current[key];
43
+ }
44
+ const finalKey = keyPath[i];
45
+ if (finalKey === '__proto__' || finalKey === 'constructor' || finalKey === 'prototype') {
46
+ return;
47
+ }
48
+ const existingValue = current[finalKey];
49
+ current[finalKey] = existingValue != null ? mergeDeep([existingValue, value]) : value;
50
+ }
@@ -103,7 +103,7 @@ export function astFromSchema(schema, pathToDirectivesInExtensions) {
103
103
  return null;
104
104
  }
105
105
  const schemaNode = {
106
- kind: operationTypes != null ? Kind.SCHEMA_DEFINITION : Kind.SCHEMA_EXTENSION,
106
+ kind: operationTypes?.length ? Kind.SCHEMA_DEFINITION : Kind.SCHEMA_EXTENSION,
107
107
  operationTypes,
108
108
  // ConstXNode has been introduced in v16 but it is not compatible with XNode so we do `as any` for backwards compatibility
109
109
  directives: directives,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "10.10.0",
3
+ "version": "10.10.2-alpha-20251111213942-9ac3293e7ae48505cbdeea7fb5e7ceaeb76a64ae",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -10,7 +10,6 @@
10
10
  "@graphql-typed-document-node/core": "^3.1.1",
11
11
  "@whatwg-node/promise-helpers": "^1.0.0",
12
12
  "cross-inspect": "1.0.1",
13
- "dset": "^3.1.4",
14
13
  "tslib": "^2.4.0"
15
14
  },
16
15
  "repository": {