@graphql-tools/utils 8.0.0-alpha-e6320b00.0 → 8.0.1

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,2 +1,3 @@
1
+ /// <reference lib="es2021.promise" />
1
2
  declare let AggregateErrorImpl: AggregateErrorConstructor;
2
3
  export { AggregateErrorImpl as AggregateError };
package/Interfaces.d.ts CHANGED
@@ -7,8 +7,8 @@ export interface ExecutionRequest<TArgs extends Record<string, any> = Record<str
7
7
  document: DocumentNode;
8
8
  operationType: OperationTypeNode;
9
9
  variables?: TArgs;
10
- extensions?: TExtensions;
11
10
  operationName?: string;
11
+ extensions?: TExtensions;
12
12
  rootValue?: TRootValue;
13
13
  context?: TContext;
14
14
  info?: GraphQLResolveInfo;
@@ -1,2 +1,3 @@
1
+ /// <reference lib="es2021.promise" />
1
2
  declare let AggregateErrorImpl: AggregateErrorConstructor;
2
3
  export { AggregateErrorImpl as AggregateError };
@@ -7,8 +7,8 @@ export interface ExecutionRequest<TArgs extends Record<string, any> = Record<str
7
7
  document: DocumentNode;
8
8
  operationType: OperationTypeNode;
9
9
  variables?: TArgs;
10
- extensions?: TExtensions;
11
10
  operationName?: string;
11
+ extensions?: TExtensions;
12
12
  rootValue?: TRootValue;
13
13
  context?: TContext;
14
14
  info?: GraphQLResolveInfo;
package/es5/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export * from './create-schema-definition';
14
14
  export * from './build-operation-for-field';
15
15
  export * from './types';
16
16
  export * from './filterSchema';
17
- export * from './clone';
18
17
  export * from './heal';
19
18
  export * from './getResolversFromSchema';
20
19
  export * from './forEachField';
package/es5/index.js CHANGED
@@ -113,13 +113,11 @@ function getArgumentValues(def, node, variableValues) {
113
113
  }, {});
114
114
  try {
115
115
  for (var _c = tslib.__values(def.args), _d = _c.next(); !_d.done; _d = _c.next()) {
116
- var argDef = _d.value;
117
- var name_1 = argDef.name;
118
- var argType = argDef.type;
116
+ var _e = _d.value, name_1 = _e.name, argType = _e.type, defaultValue = _e.defaultValue;
119
117
  var argumentNode = argNodeMap[name_1];
120
118
  if (!argumentNode) {
121
- if (argDef.defaultValue !== undefined) {
122
- coercedValues[name_1] = argDef.defaultValue;
119
+ if (defaultValue !== undefined) {
120
+ coercedValues[name_1] = defaultValue;
123
121
  }
124
122
  else if (graphql.isNonNullType(argType)) {
125
123
  throw new graphql.GraphQLError("Argument \"" + name_1 + "\" of required type \"" + util.inspect(argType) + "\" " + 'was not provided.', node);
@@ -130,9 +128,9 @@ function getArgumentValues(def, node, variableValues) {
130
128
  var isNull = valueNode.kind === graphql.Kind.NULL;
131
129
  if (valueNode.kind === graphql.Kind.VARIABLE) {
132
130
  var variableName = valueNode.name.value;
133
- if (variableValues == null || !(variableName in variableMap)) {
134
- if (argDef.defaultValue !== undefined) {
135
- coercedValues[name_1] = argDef.defaultValue;
131
+ if (variableValues == null || !variableMap[variableName]) {
132
+ if (defaultValue !== undefined) {
133
+ coercedValues[name_1] = defaultValue;
136
134
  }
137
135
  else if (graphql.isNonNullType(argType)) {
138
136
  throw new graphql.GraphQLError("Argument \"" + name_1 + "\" of required type \"" + util.inspect(argType) + "\" " +
@@ -1086,6 +1084,7 @@ function makeDirectiveNodes(schema, directiveValues) {
1086
1084
  return directiveNodes;
1087
1085
  }
1088
1086
 
1087
+ /// <reference lib="es2021.promise" />
1089
1088
  exports.AggregateError = globalThis.AggregateError;
1090
1089
  if (typeof exports.AggregateError === 'undefined') {
1091
1090
  var AggregateErrorClass_1 = /** @class */ (function (_super) {
@@ -2650,38 +2649,6 @@ function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilt
2650
2649
  }
2651
2650
  }
2652
2651
 
2653
- function cloneDirective(directive) {
2654
- return graphql.isSpecifiedDirective(directive) ? directive : new graphql.GraphQLDirective(directive.toConfig());
2655
- }
2656
- function cloneType(type) {
2657
- if (graphql.isObjectType(type)) {
2658
- var config = type.toConfig();
2659
- return new graphql.GraphQLObjectType(tslib.__assign(tslib.__assign({}, config), { interfaces: typeof config.interfaces === 'function' ? config.interfaces : config.interfaces.slice() }));
2660
- }
2661
- else if (graphql.isInterfaceType(type)) {
2662
- var config = type.toConfig();
2663
- var newConfig = tslib.__assign(tslib.__assign({}, config), { interfaces: tslib.__spreadArray([], tslib.__read(((typeof config.interfaces === 'function' ? config.interfaces() : config.interfaces) || []))) });
2664
- return new graphql.GraphQLInterfaceType(newConfig);
2665
- }
2666
- else if (graphql.isUnionType(type)) {
2667
- var config = type.toConfig();
2668
- return new graphql.GraphQLUnionType(tslib.__assign(tslib.__assign({}, config), { types: config.types.slice() }));
2669
- }
2670
- else if (graphql.isInputObjectType(type)) {
2671
- return new graphql.GraphQLInputObjectType(type.toConfig());
2672
- }
2673
- else if (graphql.isEnumType(type)) {
2674
- return new graphql.GraphQLEnumType(type.toConfig());
2675
- }
2676
- else if (graphql.isScalarType(type)) {
2677
- return graphql.isSpecifiedScalarType(type) ? type : new graphql.GraphQLScalarType(type.toConfig());
2678
- }
2679
- throw new Error("Invalid type " + type);
2680
- }
2681
- function cloneSchema(schema) {
2682
- return mapSchema(schema);
2683
- }
2684
-
2685
2652
  // Update any references to named schema types that disagree with the named
2686
2653
  // types found in schema.getTypeMap().
2687
2654
  //
@@ -3549,12 +3516,7 @@ function iteratorResult(value) {
3549
3516
  return { value: value, done: false };
3550
3517
  }
3551
3518
 
3552
- function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap, variableValues, newArg) {
3553
- var varName;
3554
- var numGeneratedVariables = 0;
3555
- do {
3556
- varName = "_v" + (numGeneratedVariables++).toString() + "_" + argName;
3557
- } while (varName in variableDefinitionsMap);
3519
+ function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
3558
3520
  argumentNodes[argName] = {
3559
3521
  kind: graphql.Kind.ARGUMENT,
3560
3522
  name: {
@@ -3578,15 +3540,29 @@ function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap,
3578
3540
  value: varName,
3579
3541
  },
3580
3542
  },
3581
- type: astFromType(argType),
3543
+ type: astFromType(type),
3582
3544
  };
3583
- if (newArg === undefined) {
3584
- delete variableValues[varName];
3545
+ if (value !== undefined) {
3546
+ variableValues[varName] = value;
3547
+ return;
3585
3548
  }
3586
- else {
3587
- variableValues[varName] = newArg;
3549
+ // including the variable in the map with value of `undefined`
3550
+ // will actually be translated by graphql-js into `null`
3551
+ // see https://github.com/graphql/graphql-js/issues/2533
3552
+ if (varName in variableValues) {
3553
+ delete variableValues[varName];
3588
3554
  }
3589
3555
  }
3556
+ function createVariableNameGenerator(variableDefinitionMap) {
3557
+ var varCounter = 0;
3558
+ return function (argName) {
3559
+ var varName;
3560
+ do {
3561
+ varName = "_v" + (varCounter++).toString() + "_" + argName;
3562
+ } while (varName in variableDefinitionMap);
3563
+ return varName;
3564
+ };
3565
+ }
3590
3566
 
3591
3567
  function implementsAbstractType(schema, typeA, typeB) {
3592
3568
  if (typeB == null || typeA == null) {
@@ -4039,15 +4015,13 @@ exports.astFromUnionType = astFromUnionType;
4039
4015
  exports.astFromValueUntyped = astFromValueUntyped;
4040
4016
  exports.buildOperationNodeForField = buildOperationNodeForField;
4041
4017
  exports.checkValidationErrors = checkValidationErrors;
4042
- exports.cloneDirective = cloneDirective;
4043
- exports.cloneSchema = cloneSchema;
4044
- exports.cloneType = cloneType;
4045
4018
  exports.compareNodes = compareNodes;
4046
4019
  exports.compareStrings = compareStrings;
4047
4020
  exports.correctASTNodes = correctASTNodes;
4048
4021
  exports.createNamedStub = createNamedStub;
4049
4022
  exports.createSchemaDefinition = createSchemaDefinition;
4050
4023
  exports.createStub = createStub;
4024
+ exports.createVariableNameGenerator = createVariableNameGenerator;
4051
4025
  exports.filterSchema = filterSchema;
4052
4026
  exports.fixSchemaAst = fixSchemaAst;
4053
4027
  exports.forEachDefaultValue = forEachDefaultValue;
package/es5/index.mjs CHANGED
@@ -109,13 +109,11 @@ function getArgumentValues(def, node, variableValues) {
109
109
  }, {});
110
110
  try {
111
111
  for (var _c = __values(def.args), _d = _c.next(); !_d.done; _d = _c.next()) {
112
- var argDef = _d.value;
113
- var name_1 = argDef.name;
114
- var argType = argDef.type;
112
+ var _e = _d.value, name_1 = _e.name, argType = _e.type, defaultValue = _e.defaultValue;
115
113
  var argumentNode = argNodeMap[name_1];
116
114
  if (!argumentNode) {
117
- if (argDef.defaultValue !== undefined) {
118
- coercedValues[name_1] = argDef.defaultValue;
115
+ if (defaultValue !== undefined) {
116
+ coercedValues[name_1] = defaultValue;
119
117
  }
120
118
  else if (isNonNullType(argType)) {
121
119
  throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " + 'was not provided.', node);
@@ -126,9 +124,9 @@ function getArgumentValues(def, node, variableValues) {
126
124
  var isNull = valueNode.kind === Kind.NULL;
127
125
  if (valueNode.kind === Kind.VARIABLE) {
128
126
  var variableName = valueNode.name.value;
129
- if (variableValues == null || !(variableName in variableMap)) {
130
- if (argDef.defaultValue !== undefined) {
131
- coercedValues[name_1] = argDef.defaultValue;
127
+ if (variableValues == null || !variableMap[variableName]) {
128
+ if (defaultValue !== undefined) {
129
+ coercedValues[name_1] = defaultValue;
132
130
  }
133
131
  else if (isNonNullType(argType)) {
134
132
  throw new GraphQLError("Argument \"" + name_1 + "\" of required type \"" + inspect(argType) + "\" " +
@@ -1082,6 +1080,7 @@ function makeDirectiveNodes(schema, directiveValues) {
1082
1080
  return directiveNodes;
1083
1081
  }
1084
1082
 
1083
+ /// <reference lib="es2021.promise" />
1085
1084
  var AggregateErrorImpl = globalThis.AggregateError;
1086
1085
  if (typeof AggregateErrorImpl === 'undefined') {
1087
1086
  var AggregateErrorClass_1 = /** @class */ (function (_super) {
@@ -2647,38 +2646,6 @@ function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilt
2647
2646
  }
2648
2647
  }
2649
2648
 
2650
- function cloneDirective(directive) {
2651
- return isSpecifiedDirective(directive) ? directive : new GraphQLDirective(directive.toConfig());
2652
- }
2653
- function cloneType(type) {
2654
- if (isObjectType(type)) {
2655
- var config = type.toConfig();
2656
- return new GraphQLObjectType(__assign(__assign({}, config), { interfaces: typeof config.interfaces === 'function' ? config.interfaces : config.interfaces.slice() }));
2657
- }
2658
- else if (isInterfaceType(type)) {
2659
- var config = type.toConfig();
2660
- var newConfig = __assign(__assign({}, config), { interfaces: __spreadArray([], __read(((typeof config.interfaces === 'function' ? config.interfaces() : config.interfaces) || []))) });
2661
- return new GraphQLInterfaceType(newConfig);
2662
- }
2663
- else if (isUnionType(type)) {
2664
- var config = type.toConfig();
2665
- return new GraphQLUnionType(__assign(__assign({}, config), { types: config.types.slice() }));
2666
- }
2667
- else if (isInputObjectType(type)) {
2668
- return new GraphQLInputObjectType(type.toConfig());
2669
- }
2670
- else if (isEnumType(type)) {
2671
- return new GraphQLEnumType(type.toConfig());
2672
- }
2673
- else if (isScalarType(type)) {
2674
- return isSpecifiedScalarType(type) ? type : new GraphQLScalarType(type.toConfig());
2675
- }
2676
- throw new Error("Invalid type " + type);
2677
- }
2678
- function cloneSchema(schema) {
2679
- return mapSchema(schema);
2680
- }
2681
-
2682
2649
  // Update any references to named schema types that disagree with the named
2683
2650
  // types found in schema.getTypeMap().
2684
2651
  //
@@ -3546,12 +3513,7 @@ function iteratorResult(value) {
3546
3513
  return { value: value, done: false };
3547
3514
  }
3548
3515
 
3549
- function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap, variableValues, newArg) {
3550
- var varName;
3551
- var numGeneratedVariables = 0;
3552
- do {
3553
- varName = "_v" + (numGeneratedVariables++).toString() + "_" + argName;
3554
- } while (varName in variableDefinitionsMap);
3516
+ function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
3555
3517
  argumentNodes[argName] = {
3556
3518
  kind: Kind.ARGUMENT,
3557
3519
  name: {
@@ -3575,15 +3537,29 @@ function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap,
3575
3537
  value: varName,
3576
3538
  },
3577
3539
  },
3578
- type: astFromType(argType),
3540
+ type: astFromType(type),
3579
3541
  };
3580
- if (newArg === undefined) {
3581
- delete variableValues[varName];
3542
+ if (value !== undefined) {
3543
+ variableValues[varName] = value;
3544
+ return;
3582
3545
  }
3583
- else {
3584
- variableValues[varName] = newArg;
3546
+ // including the variable in the map with value of `undefined`
3547
+ // will actually be translated by graphql-js into `null`
3548
+ // see https://github.com/graphql/graphql-js/issues/2533
3549
+ if (varName in variableValues) {
3550
+ delete variableValues[varName];
3585
3551
  }
3586
3552
  }
3553
+ function createVariableNameGenerator(variableDefinitionMap) {
3554
+ var varCounter = 0;
3555
+ return function (argName) {
3556
+ var varName;
3557
+ do {
3558
+ varName = "_v" + (varCounter++).toString() + "_" + argName;
3559
+ } while (varName in variableDefinitionMap);
3560
+ return varName;
3561
+ };
3562
+ }
3587
3563
 
3588
3564
  function implementsAbstractType(schema, typeA, typeB) {
3589
3565
  if (typeB == null || typeA == null) {
@@ -4017,4 +3993,4 @@ function withCancel(asyncIteratorLike, onCancel) {
4017
3993
  return asyncIterator;
4018
3994
  }
4019
3995
 
4020
- export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, cloneDirective, cloneSchema, cloneType, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
3996
+ export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
package/es5/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils/es5",
3
- "version": "8.0.0-alpha-e6320b00.0",
3
+ "version": "8.0.1",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,2 +1,3 @@
1
1
  import { GraphQLInputType, ArgumentNode, VariableDefinitionNode } from 'graphql';
2
- export declare function updateArgument(argName: string, argType: GraphQLInputType, argumentNodes: Record<string, ArgumentNode>, variableDefinitionsMap: Record<string, VariableDefinitionNode>, variableValues: Record<string, any>, newArg: any): void;
2
+ export declare function updateArgument(argumentNodes: Record<string, ArgumentNode>, variableDefinitionsMap: Record<string, VariableDefinitionNode>, variableValues: Record<string, any>, argName: string, varName: string, type: GraphQLInputType, value: any): void;
3
+ export declare function createVariableNameGenerator(variableDefinitionMap: Record<string, VariableDefinitionNode>): (argName: string) => string;
package/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export * from './create-schema-definition';
14
14
  export * from './build-operation-for-field';
15
15
  export * from './types';
16
16
  export * from './filterSchema';
17
- export * from './clone';
18
17
  export * from './heal';
19
18
  export * from './getResolversFromSchema';
20
19
  export * from './forEachField';
package/index.js CHANGED
@@ -106,13 +106,11 @@ function getArgumentValues(def, node, variableValues = {}) {
106
106
  ...prev,
107
107
  [arg.name.value]: arg,
108
108
  }), {});
109
- for (const argDef of def.args) {
110
- const name = argDef.name;
111
- const argType = argDef.type;
109
+ for (const { name, type: argType, defaultValue } of def.args) {
112
110
  const argumentNode = argNodeMap[name];
113
111
  if (!argumentNode) {
114
- if (argDef.defaultValue !== undefined) {
115
- coercedValues[name] = argDef.defaultValue;
112
+ if (defaultValue !== undefined) {
113
+ coercedValues[name] = defaultValue;
116
114
  }
117
115
  else if (graphql.isNonNullType(argType)) {
118
116
  throw new graphql.GraphQLError(`Argument "${name}" of required type "${util.inspect(argType)}" ` + 'was not provided.', node);
@@ -123,9 +121,9 @@ function getArgumentValues(def, node, variableValues = {}) {
123
121
  let isNull = valueNode.kind === graphql.Kind.NULL;
124
122
  if (valueNode.kind === graphql.Kind.VARIABLE) {
125
123
  const variableName = valueNode.name.value;
126
- if (variableValues == null || !(variableName in variableMap)) {
127
- if (argDef.defaultValue !== undefined) {
128
- coercedValues[name] = argDef.defaultValue;
124
+ if (variableValues == null || !variableMap[variableName]) {
125
+ if (defaultValue !== undefined) {
126
+ coercedValues[name] = defaultValue;
129
127
  }
130
128
  else if (graphql.isNonNullType(argType)) {
131
129
  throw new graphql.GraphQLError(`Argument "${name}" of required type "${util.inspect(argType)}" ` +
@@ -886,6 +884,7 @@ function makeDirectiveNodes(schema, directiveValues) {
886
884
  return directiveNodes;
887
885
  }
888
886
 
887
+ /// <reference lib="es2021.promise" />
889
888
  exports.AggregateError = globalThis.AggregateError;
890
889
  if (typeof exports.AggregateError === 'undefined') {
891
890
  class AggregateErrorClass extends Error {
@@ -2390,47 +2389,6 @@ function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilt
2390
2389
  }
2391
2390
  }
2392
2391
 
2393
- function cloneDirective(directive) {
2394
- return graphql.isSpecifiedDirective(directive) ? directive : new graphql.GraphQLDirective(directive.toConfig());
2395
- }
2396
- function cloneType(type) {
2397
- if (graphql.isObjectType(type)) {
2398
- const config = type.toConfig();
2399
- return new graphql.GraphQLObjectType({
2400
- ...config,
2401
- interfaces: typeof config.interfaces === 'function' ? config.interfaces : config.interfaces.slice(),
2402
- });
2403
- }
2404
- else if (graphql.isInterfaceType(type)) {
2405
- const config = type.toConfig();
2406
- const newConfig = {
2407
- ...config,
2408
- interfaces: [...((typeof config.interfaces === 'function' ? config.interfaces() : config.interfaces) || [])],
2409
- };
2410
- return new graphql.GraphQLInterfaceType(newConfig);
2411
- }
2412
- else if (graphql.isUnionType(type)) {
2413
- const config = type.toConfig();
2414
- return new graphql.GraphQLUnionType({
2415
- ...config,
2416
- types: config.types.slice(),
2417
- });
2418
- }
2419
- else if (graphql.isInputObjectType(type)) {
2420
- return new graphql.GraphQLInputObjectType(type.toConfig());
2421
- }
2422
- else if (graphql.isEnumType(type)) {
2423
- return new graphql.GraphQLEnumType(type.toConfig());
2424
- }
2425
- else if (graphql.isScalarType(type)) {
2426
- return graphql.isSpecifiedScalarType(type) ? type : new graphql.GraphQLScalarType(type.toConfig());
2427
- }
2428
- throw new Error(`Invalid type ${type}`);
2429
- }
2430
- function cloneSchema(schema) {
2431
- return mapSchema(schema);
2432
- }
2433
-
2434
2392
  // Update any references to named schema types that disagree with the named
2435
2393
  // types found in schema.getTypeMap().
2436
2394
  //
@@ -3228,12 +3186,7 @@ function iteratorResult(value) {
3228
3186
  return { value, done: false };
3229
3187
  }
3230
3188
 
3231
- function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap, variableValues, newArg) {
3232
- let varName;
3233
- let numGeneratedVariables = 0;
3234
- do {
3235
- varName = `_v${(numGeneratedVariables++).toString()}_${argName}`;
3236
- } while (varName in variableDefinitionsMap);
3189
+ function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
3237
3190
  argumentNodes[argName] = {
3238
3191
  kind: graphql.Kind.ARGUMENT,
3239
3192
  name: {
@@ -3257,15 +3210,29 @@ function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap,
3257
3210
  value: varName,
3258
3211
  },
3259
3212
  },
3260
- type: astFromType(argType),
3213
+ type: astFromType(type),
3261
3214
  };
3262
- if (newArg === undefined) {
3263
- delete variableValues[varName];
3215
+ if (value !== undefined) {
3216
+ variableValues[varName] = value;
3217
+ return;
3264
3218
  }
3265
- else {
3266
- variableValues[varName] = newArg;
3219
+ // including the variable in the map with value of `undefined`
3220
+ // will actually be translated by graphql-js into `null`
3221
+ // see https://github.com/graphql/graphql-js/issues/2533
3222
+ if (varName in variableValues) {
3223
+ delete variableValues[varName];
3267
3224
  }
3268
3225
  }
3226
+ function createVariableNameGenerator(variableDefinitionMap) {
3227
+ let varCounter = 0;
3228
+ return (argName) => {
3229
+ let varName;
3230
+ do {
3231
+ varName = `_v${(varCounter++).toString()}_${argName}`;
3232
+ } while (varName in variableDefinitionMap);
3233
+ return varName;
3234
+ };
3235
+ }
3269
3236
 
3270
3237
  function implementsAbstractType(schema, typeA, typeB) {
3271
3238
  if (typeB == null || typeA == null) {
@@ -3635,15 +3602,13 @@ exports.astFromUnionType = astFromUnionType;
3635
3602
  exports.astFromValueUntyped = astFromValueUntyped;
3636
3603
  exports.buildOperationNodeForField = buildOperationNodeForField;
3637
3604
  exports.checkValidationErrors = checkValidationErrors;
3638
- exports.cloneDirective = cloneDirective;
3639
- exports.cloneSchema = cloneSchema;
3640
- exports.cloneType = cloneType;
3641
3605
  exports.compareNodes = compareNodes;
3642
3606
  exports.compareStrings = compareStrings;
3643
3607
  exports.correctASTNodes = correctASTNodes;
3644
3608
  exports.createNamedStub = createNamedStub;
3645
3609
  exports.createSchemaDefinition = createSchemaDefinition;
3646
3610
  exports.createStub = createStub;
3611
+ exports.createVariableNameGenerator = createVariableNameGenerator;
3647
3612
  exports.filterSchema = filterSchema;
3648
3613
  exports.fixSchemaAst = fixSchemaAst;
3649
3614
  exports.forEachDefaultValue = forEachDefaultValue;
package/index.mjs CHANGED
@@ -102,13 +102,11 @@ function getArgumentValues(def, node, variableValues = {}) {
102
102
  ...prev,
103
103
  [arg.name.value]: arg,
104
104
  }), {});
105
- for (const argDef of def.args) {
106
- const name = argDef.name;
107
- const argType = argDef.type;
105
+ for (const { name, type: argType, defaultValue } of def.args) {
108
106
  const argumentNode = argNodeMap[name];
109
107
  if (!argumentNode) {
110
- if (argDef.defaultValue !== undefined) {
111
- coercedValues[name] = argDef.defaultValue;
108
+ if (defaultValue !== undefined) {
109
+ coercedValues[name] = defaultValue;
112
110
  }
113
111
  else if (isNonNullType(argType)) {
114
112
  throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` + 'was not provided.', node);
@@ -119,9 +117,9 @@ function getArgumentValues(def, node, variableValues = {}) {
119
117
  let isNull = valueNode.kind === Kind.NULL;
120
118
  if (valueNode.kind === Kind.VARIABLE) {
121
119
  const variableName = valueNode.name.value;
122
- if (variableValues == null || !(variableName in variableMap)) {
123
- if (argDef.defaultValue !== undefined) {
124
- coercedValues[name] = argDef.defaultValue;
120
+ if (variableValues == null || !variableMap[variableName]) {
121
+ if (defaultValue !== undefined) {
122
+ coercedValues[name] = defaultValue;
125
123
  }
126
124
  else if (isNonNullType(argType)) {
127
125
  throw new GraphQLError(`Argument "${name}" of required type "${inspect(argType)}" ` +
@@ -882,6 +880,7 @@ function makeDirectiveNodes(schema, directiveValues) {
882
880
  return directiveNodes;
883
881
  }
884
882
 
883
+ /// <reference lib="es2021.promise" />
885
884
  let AggregateErrorImpl = globalThis.AggregateError;
886
885
  if (typeof AggregateErrorImpl === 'undefined') {
887
886
  class AggregateErrorClass extends Error {
@@ -2387,47 +2386,6 @@ function filterElementFields(ElementConstructor, type, fieldFilter, argumentFilt
2387
2386
  }
2388
2387
  }
2389
2388
 
2390
- function cloneDirective(directive) {
2391
- return isSpecifiedDirective(directive) ? directive : new GraphQLDirective(directive.toConfig());
2392
- }
2393
- function cloneType(type) {
2394
- if (isObjectType(type)) {
2395
- const config = type.toConfig();
2396
- return new GraphQLObjectType({
2397
- ...config,
2398
- interfaces: typeof config.interfaces === 'function' ? config.interfaces : config.interfaces.slice(),
2399
- });
2400
- }
2401
- else if (isInterfaceType(type)) {
2402
- const config = type.toConfig();
2403
- const newConfig = {
2404
- ...config,
2405
- interfaces: [...((typeof config.interfaces === 'function' ? config.interfaces() : config.interfaces) || [])],
2406
- };
2407
- return new GraphQLInterfaceType(newConfig);
2408
- }
2409
- else if (isUnionType(type)) {
2410
- const config = type.toConfig();
2411
- return new GraphQLUnionType({
2412
- ...config,
2413
- types: config.types.slice(),
2414
- });
2415
- }
2416
- else if (isInputObjectType(type)) {
2417
- return new GraphQLInputObjectType(type.toConfig());
2418
- }
2419
- else if (isEnumType(type)) {
2420
- return new GraphQLEnumType(type.toConfig());
2421
- }
2422
- else if (isScalarType(type)) {
2423
- return isSpecifiedScalarType(type) ? type : new GraphQLScalarType(type.toConfig());
2424
- }
2425
- throw new Error(`Invalid type ${type}`);
2426
- }
2427
- function cloneSchema(schema) {
2428
- return mapSchema(schema);
2429
- }
2430
-
2431
2389
  // Update any references to named schema types that disagree with the named
2432
2390
  // types found in schema.getTypeMap().
2433
2391
  //
@@ -3225,12 +3183,7 @@ function iteratorResult(value) {
3225
3183
  return { value, done: false };
3226
3184
  }
3227
3185
 
3228
- function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap, variableValues, newArg) {
3229
- let varName;
3230
- let numGeneratedVariables = 0;
3231
- do {
3232
- varName = `_v${(numGeneratedVariables++).toString()}_${argName}`;
3233
- } while (varName in variableDefinitionsMap);
3186
+ function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
3234
3187
  argumentNodes[argName] = {
3235
3188
  kind: Kind.ARGUMENT,
3236
3189
  name: {
@@ -3254,15 +3207,29 @@ function updateArgument(argName, argType, argumentNodes, variableDefinitionsMap,
3254
3207
  value: varName,
3255
3208
  },
3256
3209
  },
3257
- type: astFromType(argType),
3210
+ type: astFromType(type),
3258
3211
  };
3259
- if (newArg === undefined) {
3260
- delete variableValues[varName];
3212
+ if (value !== undefined) {
3213
+ variableValues[varName] = value;
3214
+ return;
3261
3215
  }
3262
- else {
3263
- variableValues[varName] = newArg;
3216
+ // including the variable in the map with value of `undefined`
3217
+ // will actually be translated by graphql-js into `null`
3218
+ // see https://github.com/graphql/graphql-js/issues/2533
3219
+ if (varName in variableValues) {
3220
+ delete variableValues[varName];
3264
3221
  }
3265
3222
  }
3223
+ function createVariableNameGenerator(variableDefinitionMap) {
3224
+ let varCounter = 0;
3225
+ return (argName) => {
3226
+ let varName;
3227
+ do {
3228
+ varName = `_v${(varCounter++).toString()}_${argName}`;
3229
+ } while (varName in variableDefinitionMap);
3230
+ return varName;
3231
+ };
3232
+ }
3266
3233
 
3267
3234
  function implementsAbstractType(schema, typeA, typeB) {
3268
3235
  if (typeB == null || typeA == null) {
@@ -3613,4 +3580,4 @@ function withCancel(asyncIteratorLike, onCancel) {
3613
3580
  return asyncIterator;
3614
3581
  }
3615
3582
 
3616
- export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, cloneDirective, cloneSchema, cloneType, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
3583
+ export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printSchemaWithDirectives, pruneSchema, relocatedError, removeObjectFields, renameType, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "8.0.0-alpha-e6320b00.0",
3
+ "version": "8.0.1",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,2 +1,3 @@
1
1
  import { GraphQLInputType, ArgumentNode, VariableDefinitionNode } from 'graphql';
2
- export declare function updateArgument(argName: string, argType: GraphQLInputType, argumentNodes: Record<string, ArgumentNode>, variableDefinitionsMap: Record<string, VariableDefinitionNode>, variableValues: Record<string, any>, newArg: any): void;
2
+ export declare function updateArgument(argumentNodes: Record<string, ArgumentNode>, variableDefinitionsMap: Record<string, VariableDefinitionNode>, variableValues: Record<string, any>, argName: string, varName: string, type: GraphQLInputType, value: any): void;
3
+ export declare function createVariableNameGenerator(variableDefinitionMap: Record<string, VariableDefinitionNode>): (argName: string) => string;
package/clone.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { GraphQLDirective, GraphQLNamedType, GraphQLSchema } from 'graphql';
2
- export declare function cloneDirective(directive: GraphQLDirective): GraphQLDirective;
3
- export declare function cloneType(type: GraphQLNamedType): GraphQLNamedType;
4
- export declare function cloneSchema(schema: GraphQLSchema): GraphQLSchema;
package/es5/clone.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { GraphQLDirective, GraphQLNamedType, GraphQLSchema } from 'graphql';
2
- export declare function cloneDirective(directive: GraphQLDirective): GraphQLDirective;
3
- export declare function cloneType(type: GraphQLNamedType): GraphQLNamedType;
4
- export declare function cloneSchema(schema: GraphQLSchema): GraphQLSchema;