@graphql-tools/wrap 7.0.5-alpha-9e1fc254.0 → 7.0.5

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.
package/es5/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { __assign, __spread, __read, __extends } from 'tslib';
2
- import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, isObjectType, isInterfaceType, isLeafType, valueFromAST, getNullableType, BREAK, buildSchema, parse, getIntrospectionQuery, buildClientSchema } from 'graphql';
3
- import { getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, visitResult, updateArgument, transformInputValue, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields } from '@graphql-tools/utils/es5';
2
+ import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, isObjectType, isInterfaceType, typeFromAST, isLeafType, valueFromAST, getNullableType, BREAK, buildSchema, parse, getIntrospectionQuery, buildClientSchema } from 'graphql';
3
+ import { getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, transformInputValue, visitResult, updateArgument, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields } from '@graphql-tools/utils/es5';
4
4
  import { applySchemaTransforms, delegateToSchema, isExternalObject, getUnpathedErrors, getSubschema, resolveExternalValue, defaultMergedResolver } from '@graphql-tools/delegate/es5';
5
5
  import isPromise from 'is-promise';
6
6
 
@@ -577,15 +577,54 @@ var TransformInputObjectFields = /** @class */ (function () {
577
577
  _a));
578
578
  return this.transformedSchema;
579
579
  };
580
- TransformInputObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, _transformationContextד) {
580
+ TransformInputObjectFields.prototype.transformRequest = function (originalRequest, delegationContext, _transformationContext) {
581
+ var _this = this;
582
+ var variableValues = originalRequest.variables;
581
583
  var fragments = Object.create(null);
584
+ var operations = [];
585
+ originalRequest.document.definitions.forEach(function (def) {
586
+ if (def.kind === Kind.OPERATION_DEFINITION) {
587
+ operations.push(def);
588
+ }
589
+ else {
590
+ fragments[def.name.value] = def;
591
+ }
592
+ });
593
+ operations.forEach(function (def) {
594
+ var variableDefs = def.variableDefinitions;
595
+ if (variableDefs != null) {
596
+ variableDefs.forEach(function (variableDef) {
597
+ var varName = variableDef.variable.name.value;
598
+ // requirement for 'as NamedTypeNode' appears to be a bug within types, as function should take any TypeNode
599
+ var varType = typeFromAST(delegationContext.transformedSchema, variableDef.type);
600
+ variableValues[varName] = transformInputValue(varType, variableValues[varName], undefined, function (type, originalValue) {
601
+ var newValue = Object.create(null);
602
+ var fields = type.getFields();
603
+ Object.keys(originalValue).forEach(function (key) {
604
+ var _a;
605
+ var field = fields[key];
606
+ if (field != null) {
607
+ var newFieldName = (_a = _this.mapping[type.name]) === null || _a === void 0 ? void 0 : _a[field.name];
608
+ if (newFieldName != null) {
609
+ newValue[newFieldName] = originalValue[field.name];
610
+ }
611
+ else {
612
+ newValue[field.name] = originalValue[field.name];
613
+ }
614
+ }
615
+ });
616
+ return newValue;
617
+ });
618
+ });
619
+ }
620
+ });
582
621
  originalRequest.document.definitions
583
622
  .filter(function (def) { return def.kind === Kind.FRAGMENT_DEFINITION; })
584
623
  .forEach(function (def) {
585
624
  fragments[def.name.value] = def;
586
625
  });
587
626
  var document = this.transformDocument(originalRequest.document, this.mapping, this.inputFieldNodeTransformer, this.inputObjectNodeTransformer, originalRequest, delegationContext);
588
- return __assign(__assign({}, originalRequest), { document: document });
627
+ return __assign(__assign({}, originalRequest), { document: document, variables: variableValues });
589
628
  };
590
629
  TransformInputObjectFields.prototype.transformDocument = function (document, mapping, inputFieldNodeTransformer, inputObjectNodeTransformer, request, delegationContext) {
591
630
  var _a;