@graphql-tools/utils 12.0.1 → 12.0.2-alpha-20260916134337-40efa53cfd526d3944a85c9f8cd8d00a16f052dd

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,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractExtensionsFromSchema = extractExtensionsFromSchema;
4
+ const graphql_1 = require("graphql");
4
5
  const helpers_js_1 = require("./helpers.js");
5
6
  const Interfaces_js_1 = require("./Interfaces.js");
6
7
  const mapSchema_js_1 = require("./mapSchema.js");
@@ -10,6 +11,13 @@ function handleDirectiveExtensions(extensions, removeDirectives) {
10
11
  const finalExtensions = {
11
12
  ...rest,
12
13
  };
14
+ // GraphQL v17+ preserves symbol-keyed extensions (toObjMapWithSymbols); copy them
15
+ // explicitly because object rest/spread only keeps enumerable string keys.
16
+ if (graphql_1.versionInfo.major >= 17) {
17
+ for (const sym of Object.getOwnPropertySymbols(extensions)) {
18
+ finalExtensions[sym] = extensions[sym];
19
+ }
20
+ }
13
21
  if (!removeDirectives) {
14
22
  if (existingDirectives != null) {
15
23
  const directives = {};
package/cjs/mergeDeep.js CHANGED
@@ -2,7 +2,45 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mergeDeep = mergeDeep;
4
4
  const helpers_js_1 = require("./helpers.js");
5
- function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
5
+ function isMergeDeepOptions(value) {
6
+ return value != null && typeof value === 'object' && !Array.isArray(value);
7
+ }
8
+ function resolveRespectSymbols(respectSymbols) {
9
+ switch (respectSymbols) {
10
+ case 'all':
11
+ return { enumerable: true, nonEnumerable: true };
12
+ case 'enumerable':
13
+ return { enumerable: true, nonEnumerable: false };
14
+ case 'nonenumerable':
15
+ return { enumerable: false, nonEnumerable: true };
16
+ default:
17
+ return { enumerable: false, nonEnumerable: false };
18
+ }
19
+ }
20
+ function normalizeMergeDeepOptions(respectPrototypeOrOptions, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
21
+ if (isMergeDeepOptions(respectPrototypeOrOptions)) {
22
+ return {
23
+ respectPrototype: respectPrototypeOrOptions.respectPrototype ?? false,
24
+ respectArrays: respectPrototypeOrOptions.respectArrays ?? false,
25
+ respectArrayLength: respectPrototypeOrOptions.respectArrayLength ?? false,
26
+ respectSymbols: respectPrototypeOrOptions.respectSymbols ?? false,
27
+ };
28
+ }
29
+ return {
30
+ respectPrototype: respectPrototypeOrOptions ?? false,
31
+ respectArrays,
32
+ respectArrayLength,
33
+ // Legacy 5th positional arg maps to non-enumerable-only symbol handling.
34
+ respectSymbols: respectNonEnumerableSymbols ? 'nonenumerable' : false,
35
+ };
36
+ }
37
+ function mergeDeep(sources, respectPrototypeOrOptions = false, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
38
+ const options = normalizeMergeDeepOptions(respectPrototypeOrOptions, respectArrays, respectArrayLength, respectNonEnumerableSymbols);
39
+ return mergeDeepWithOptions(sources, options);
40
+ }
41
+ function mergeDeepWithOptions(sources, options) {
42
+ const { respectPrototype, respectArrayLength, respectSymbols } = options;
43
+ const { enumerable: respectEnumerableSymbols, nonEnumerable: respectNonEnumerableSymbols } = resolveRespectSymbols(respectSymbols);
6
44
  if (sources.length === 0) {
7
45
  return;
8
46
  }
@@ -27,7 +65,7 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
27
65
  return false;
28
66
  });
29
67
  if (respectArrayLength && areArraysInTheSameLength) {
30
- return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols));
68
+ return new Array(expectedLength).fill(null).map((_, index) => mergeDeepWithOptions(sources.map(source => source[index]), options));
31
69
  }
32
70
  if (allArrays) {
33
71
  return sources.flat(1);
@@ -74,17 +112,29 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
74
112
  // skip above, which would otherwise silently discard this override and keep the prior
75
113
  // value.
76
114
  if (Object.prototype.hasOwnProperty.call(output, key) && source[key] !== undefined) {
77
- output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols);
115
+ output[key] = mergeDeepWithOptions([output[key], source[key]], options);
78
116
  }
79
117
  else {
80
118
  output[key] = source[key];
81
119
  }
82
120
  }
83
- if (respectNonEnumerableSymbols && output != null) {
121
+ if (output != null && (respectEnumerableSymbols || respectNonEnumerableSymbols)) {
84
122
  for (const sym of Object.getOwnPropertySymbols(source)) {
85
123
  const descriptor = Object.getOwnPropertyDescriptor(source, sym);
86
124
  if (!descriptor.enumerable) {
87
- Object.defineProperty(output, sym, descriptor);
125
+ if (respectNonEnumerableSymbols) {
126
+ Object.defineProperty(output, sym, descriptor);
127
+ }
128
+ continue;
129
+ }
130
+ if (!respectEnumerableSymbols) {
131
+ continue;
132
+ }
133
+ if (Object.prototype.hasOwnProperty.call(output, sym) && source[sym] !== undefined) {
134
+ output[sym] = mergeDeepWithOptions([output[sym], source[sym]], options);
135
+ }
136
+ else {
137
+ output[sym] = source[sym];
88
138
  }
89
139
  }
90
140
  }
@@ -94,7 +144,7 @@ function mergeDeep(sources, respectPrototype = false, respectArrays = false, res
94
144
  output = source;
95
145
  }
96
146
  else {
97
- output = mergeDeep([output, source], respectPrototype, respectArrays, respectArrayLength);
147
+ output = mergeDeepWithOptions([output, source], options);
98
148
  }
99
149
  }
100
150
  else {
@@ -1,3 +1,4 @@
1
+ import { versionInfo } from 'graphql';
1
2
  import { asArray } from './helpers.js';
2
3
  import { MapperKind } from './Interfaces.js';
3
4
  import { mapSchema } from './mapSchema.js';
@@ -7,6 +8,13 @@ function handleDirectiveExtensions(extensions, removeDirectives) {
7
8
  const finalExtensions = {
8
9
  ...rest,
9
10
  };
11
+ // GraphQL v17+ preserves symbol-keyed extensions (toObjMapWithSymbols); copy them
12
+ // explicitly because object rest/spread only keeps enumerable string keys.
13
+ if (versionInfo.major >= 17) {
14
+ for (const sym of Object.getOwnPropertySymbols(extensions)) {
15
+ finalExtensions[sym] = extensions[sym];
16
+ }
17
+ }
10
18
  if (!removeDirectives) {
11
19
  if (existingDirectives != null) {
12
20
  const directives = {};
package/esm/mergeDeep.js CHANGED
@@ -1,5 +1,43 @@
1
1
  import { isSome } from './helpers.js';
2
- export function mergeDeep(sources, respectPrototype = false, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
2
+ function isMergeDeepOptions(value) {
3
+ return value != null && typeof value === 'object' && !Array.isArray(value);
4
+ }
5
+ function resolveRespectSymbols(respectSymbols) {
6
+ switch (respectSymbols) {
7
+ case 'all':
8
+ return { enumerable: true, nonEnumerable: true };
9
+ case 'enumerable':
10
+ return { enumerable: true, nonEnumerable: false };
11
+ case 'nonenumerable':
12
+ return { enumerable: false, nonEnumerable: true };
13
+ default:
14
+ return { enumerable: false, nonEnumerable: false };
15
+ }
16
+ }
17
+ function normalizeMergeDeepOptions(respectPrototypeOrOptions, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
18
+ if (isMergeDeepOptions(respectPrototypeOrOptions)) {
19
+ return {
20
+ respectPrototype: respectPrototypeOrOptions.respectPrototype ?? false,
21
+ respectArrays: respectPrototypeOrOptions.respectArrays ?? false,
22
+ respectArrayLength: respectPrototypeOrOptions.respectArrayLength ?? false,
23
+ respectSymbols: respectPrototypeOrOptions.respectSymbols ?? false,
24
+ };
25
+ }
26
+ return {
27
+ respectPrototype: respectPrototypeOrOptions ?? false,
28
+ respectArrays,
29
+ respectArrayLength,
30
+ // Legacy 5th positional arg maps to non-enumerable-only symbol handling.
31
+ respectSymbols: respectNonEnumerableSymbols ? 'nonenumerable' : false,
32
+ };
33
+ }
34
+ export function mergeDeep(sources, respectPrototypeOrOptions = false, respectArrays = false, respectArrayLength = false, respectNonEnumerableSymbols = false) {
35
+ const options = normalizeMergeDeepOptions(respectPrototypeOrOptions, respectArrays, respectArrayLength, respectNonEnumerableSymbols);
36
+ return mergeDeepWithOptions(sources, options);
37
+ }
38
+ function mergeDeepWithOptions(sources, options) {
39
+ const { respectPrototype, respectArrayLength, respectSymbols } = options;
40
+ const { enumerable: respectEnumerableSymbols, nonEnumerable: respectNonEnumerableSymbols } = resolveRespectSymbols(respectSymbols);
3
41
  if (sources.length === 0) {
4
42
  return;
5
43
  }
@@ -24,7 +62,7 @@ export function mergeDeep(sources, respectPrototype = false, respectArrays = fal
24
62
  return false;
25
63
  });
26
64
  if (respectArrayLength && areArraysInTheSameLength) {
27
- return new Array(expectedLength).fill(null).map((_, index) => mergeDeep(sources.map(source => source[index]), respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols));
65
+ return new Array(expectedLength).fill(null).map((_, index) => mergeDeepWithOptions(sources.map(source => source[index]), options));
28
66
  }
29
67
  if (allArrays) {
30
68
  return sources.flat(1);
@@ -71,17 +109,29 @@ export function mergeDeep(sources, respectPrototype = false, respectArrays = fal
71
109
  // skip above, which would otherwise silently discard this override and keep the prior
72
110
  // value.
73
111
  if (Object.prototype.hasOwnProperty.call(output, key) && source[key] !== undefined) {
74
- output[key] = mergeDeep([output[key], source[key]], respectPrototype, respectArrays, respectArrayLength, respectNonEnumerableSymbols);
112
+ output[key] = mergeDeepWithOptions([output[key], source[key]], options);
75
113
  }
76
114
  else {
77
115
  output[key] = source[key];
78
116
  }
79
117
  }
80
- if (respectNonEnumerableSymbols && output != null) {
118
+ if (output != null && (respectEnumerableSymbols || respectNonEnumerableSymbols)) {
81
119
  for (const sym of Object.getOwnPropertySymbols(source)) {
82
120
  const descriptor = Object.getOwnPropertyDescriptor(source, sym);
83
121
  if (!descriptor.enumerable) {
84
- Object.defineProperty(output, sym, descriptor);
122
+ if (respectNonEnumerableSymbols) {
123
+ Object.defineProperty(output, sym, descriptor);
124
+ }
125
+ continue;
126
+ }
127
+ if (!respectEnumerableSymbols) {
128
+ continue;
129
+ }
130
+ if (Object.prototype.hasOwnProperty.call(output, sym) && source[sym] !== undefined) {
131
+ output[sym] = mergeDeepWithOptions([output[sym], source[sym]], options);
132
+ }
133
+ else {
134
+ output[sym] = source[sym];
85
135
  }
86
136
  }
87
137
  }
@@ -91,7 +141,7 @@ export function mergeDeep(sources, respectPrototype = false, respectArrays = fal
91
141
  output = source;
92
142
  }
93
143
  else {
94
- output = mergeDeep([output, source], respectPrototype, respectArrays, respectArrayLength);
144
+ output = mergeDeepWithOptions([output, source], options);
95
145
  }
96
146
  }
97
147
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "12.0.1",
3
+ "version": "12.0.2-alpha-20260916134337-40efa53cfd526d3944a85c9f8cd8d00a16f052dd",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -5,5 +5,20 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
5
5
  type UnboxIntersection<T> = T extends {
6
6
  0: infer U;
7
7
  } ? U : never;
8
+ export type MergeDeepRespectSymbols = false | 'enumerable' | 'nonenumerable' | 'all';
9
+ export interface MergeDeepOptions {
10
+ respectPrototype?: boolean;
11
+ respectArrays?: boolean;
12
+ respectArrayLength?: boolean;
13
+ /**
14
+ * How to handle own symbol keys while merging.
15
+ * - `false` / omitted: drop symbols (historical default)
16
+ * - `'enumerable'`: merge enumerable symbols like string keys
17
+ * - `'nonenumerable'`: copy non-enumerable symbols via property descriptors
18
+ * - `'all'`: both
19
+ */
20
+ respectSymbols?: MergeDeepRespectSymbols;
21
+ }
22
+ export declare function mergeDeep<S extends any[]>(sources: S, options?: MergeDeepOptions): UnboxIntersection<UnionToIntersection<BoxedTupleTypes<S>>> & any;
8
23
  export declare function mergeDeep<S extends any[]>(sources: S, respectPrototype?: boolean, respectArrays?: boolean, respectArrayLength?: boolean, respectNonEnumerableSymbols?: boolean): UnboxIntersection<UnionToIntersection<BoxedTupleTypes<S>>> & any;
9
24
  export {};
@@ -5,5 +5,20 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
5
5
  type UnboxIntersection<T> = T extends {
6
6
  0: infer U;
7
7
  } ? U : never;
8
+ export type MergeDeepRespectSymbols = false | 'enumerable' | 'nonenumerable' | 'all';
9
+ export interface MergeDeepOptions {
10
+ respectPrototype?: boolean;
11
+ respectArrays?: boolean;
12
+ respectArrayLength?: boolean;
13
+ /**
14
+ * How to handle own symbol keys while merging.
15
+ * - `false` / omitted: drop symbols (historical default)
16
+ * - `'enumerable'`: merge enumerable symbols like string keys
17
+ * - `'nonenumerable'`: copy non-enumerable symbols via property descriptors
18
+ * - `'all'`: both
19
+ */
20
+ respectSymbols?: MergeDeepRespectSymbols;
21
+ }
22
+ export declare function mergeDeep<S extends any[]>(sources: S, options?: MergeDeepOptions): UnboxIntersection<UnionToIntersection<BoxedTupleTypes<S>>> & any;
8
23
  export declare function mergeDeep<S extends any[]>(sources: S, respectPrototype?: boolean, respectArrays?: boolean, respectArrayLength?: boolean, respectNonEnumerableSymbols?: boolean): UnboxIntersection<UnionToIntersection<BoxedTupleTypes<S>>> & any;
9
24
  export {};
@@ -72,7 +72,7 @@ export declare enum DirectiveLocation {
72
72
  INPUT_OBJECT = "INPUT_OBJECT",
73
73
  INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION"
74
74
  }
75
- export type ExtensionsObject = Record<string, any>;
75
+ export type ExtensionsObject = Record<string | symbol, any>;
76
76
  export type ObjectTypeExtensions = {
77
77
  type: 'object';
78
78
  fields: Record<string, {
@@ -72,7 +72,7 @@ export declare enum DirectiveLocation {
72
72
  INPUT_OBJECT = "INPUT_OBJECT",
73
73
  INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION"
74
74
  }
75
- export type ExtensionsObject = Record<string, any>;
75
+ export type ExtensionsObject = Record<string | symbol, any>;
76
76
  export type ObjectTypeExtensions = {
77
77
  type: 'object';
78
78
  fields: Record<string, {