@graphql-tools/wrap 7.0.5-alpha-bacafb47.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/index.esm.js CHANGED
@@ -1,5 +1,5 @@
1
- import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, isObjectType, isInterfaceType, isLeafType, valueFromAST, getNullableType, BREAK, buildSchema, parse, getIntrospectionQuery, buildClientSchema } from 'graphql';
2
- import { getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, visitResult, updateArgument, transformInputValue, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields } from '@graphql-tools/utils';
1
+ import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, isObjectType, isInterfaceType, typeFromAST, isLeafType, valueFromAST, getNullableType, BREAK, buildSchema, parse, getIntrospectionQuery, buildClientSchema } from 'graphql';
2
+ import { getResponseKeyFromInfo, mapSchema, MapperKind, renameType, visitData, transformInputValue, visitResult, updateArgument, relocatedError, getArgumentValues, valueMatchesCriteria, getDirectives, pruneSchema, selectObjectFields, appendObjectFields, modifyObjectFields, removeObjectFields } from '@graphql-tools/utils';
3
3
  import { applySchemaTransforms, delegateToSchema, isExternalObject, getUnpathedErrors, getSubschema, resolveExternalValue, defaultMergedResolver } from '@graphql-tools/delegate';
4
4
  import { __extends } from 'tslib';
5
5
  import isPromise from 'is-promise';
@@ -559,8 +559,46 @@ class TransformInputObjectFields {
559
559
  });
560
560
  return this.transformedSchema;
561
561
  }
562
- transformRequest(originalRequest, delegationContext, _transformationContextד) {
562
+ transformRequest(originalRequest, delegationContext, _transformationContext) {
563
+ const variableValues = originalRequest.variables;
563
564
  const fragments = Object.create(null);
565
+ const operations = [];
566
+ originalRequest.document.definitions.forEach(def => {
567
+ if (def.kind === Kind.OPERATION_DEFINITION) {
568
+ operations.push(def);
569
+ }
570
+ else {
571
+ fragments[def.name.value] = def;
572
+ }
573
+ });
574
+ operations.forEach(def => {
575
+ const variableDefs = def.variableDefinitions;
576
+ if (variableDefs != null) {
577
+ variableDefs.forEach(variableDef => {
578
+ const varName = variableDef.variable.name.value;
579
+ // requirement for 'as NamedTypeNode' appears to be a bug within types, as function should take any TypeNode
580
+ const varType = typeFromAST(delegationContext.transformedSchema, variableDef.type);
581
+ variableValues[varName] = transformInputValue(varType, variableValues[varName], undefined, (type, originalValue) => {
582
+ const newValue = Object.create(null);
583
+ const fields = type.getFields();
584
+ Object.keys(originalValue).forEach(key => {
585
+ var _a;
586
+ const field = fields[key];
587
+ if (field != null) {
588
+ const newFieldName = (_a = this.mapping[type.name]) === null || _a === void 0 ? void 0 : _a[field.name];
589
+ if (newFieldName != null) {
590
+ newValue[newFieldName] = originalValue[field.name];
591
+ }
592
+ else {
593
+ newValue[field.name] = originalValue[field.name];
594
+ }
595
+ }
596
+ });
597
+ return newValue;
598
+ });
599
+ });
600
+ }
601
+ });
564
602
  originalRequest.document.definitions
565
603
  .filter(def => def.kind === Kind.FRAGMENT_DEFINITION)
566
604
  .forEach(def => {
@@ -570,6 +608,7 @@ class TransformInputObjectFields {
570
608
  return {
571
609
  ...originalRequest,
572
610
  document,
611
+ variables: variableValues,
573
612
  };
574
613
  }
575
614
  transformDocument(document, mapping, inputFieldNodeTransformer, inputObjectNodeTransformer, request, delegationContext) {