@graphql-tools/wrap 9.3.0 → 9.3.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.
@@ -15,6 +15,18 @@ class TransformEnumValues {
15
15
  const mappingSchema = this.transformer.transformSchema(originalWrappingSchema, subschemaConfig);
16
16
  this.transformedSchema = (0, utils_1.mapSchema)(mappingSchema, {
17
17
  [utils_1.MapperKind.ENUM_VALUE]: (valueConfig, typeName, _schema, externalValue) => this.transformEnumValue(typeName, externalValue, valueConfig),
18
+ [utils_1.MapperKind.ARGUMENT]: argConfig => {
19
+ if (argConfig.defaultValue != null) {
20
+ const newValue = (0, utils_1.transformInputValue)(argConfig.type, argConfig.defaultValue, (type, value) => {
21
+ var _a, _b;
22
+ return (_b = (_a = this.mapping[type.name]) === null || _a === void 0 ? void 0 : _a[value]) !== null && _b !== void 0 ? _b : value;
23
+ });
24
+ return {
25
+ ...argConfig,
26
+ defaultValue: newValue,
27
+ };
28
+ }
29
+ },
18
30
  });
19
31
  return this.transformedSchema;
20
32
  }
@@ -43,8 +55,18 @@ class TransformEnumValues {
43
55
  this.reverseMapping[typeName][newExternalValue] = externalValue;
44
56
  this.noTransformation = false;
45
57
  }
58
+ return [
59
+ newExternalValue,
60
+ {
61
+ ...transformedEnumValue[1],
62
+ value: undefined,
63
+ },
64
+ ];
46
65
  }
47
- return transformedEnumValue;
66
+ return {
67
+ ...transformedEnumValue,
68
+ value: undefined,
69
+ };
48
70
  }
49
71
  }
50
72
  exports.default = TransformEnumValues;
package/cjs/wrapSchema.js CHANGED
@@ -9,53 +9,50 @@ exports.wrapSchema = (0, utils_1.memoize1)(function wrapSchema(subschemaConfig)
9
9
  const targetSchema = subschemaConfig.schema;
10
10
  const proxyingResolvers = (0, generateProxyingResolvers_js_1.generateProxyingResolvers)(subschemaConfig);
11
11
  const schema = createWrappingSchema(targetSchema, proxyingResolvers);
12
- return (0, delegate_1.applySchemaTransforms)(schema, subschemaConfig);
12
+ const transformed = (0, delegate_1.applySchemaTransforms)(schema, subschemaConfig);
13
+ return transformed;
13
14
  });
14
15
  function createWrappingSchema(schema, proxyingResolvers) {
15
16
  return (0, utils_1.mapSchema)(schema, {
16
- [utils_1.MapperKind.ROOT_OBJECT]: type => {
17
+ [utils_1.MapperKind.ROOT_FIELD]: (fieldConfig, fieldName, typeName) => {
17
18
  var _a;
18
- const config = type.toConfig();
19
- const fieldConfigMap = config.fields;
20
- for (const fieldName in fieldConfigMap) {
21
- const field = fieldConfigMap[fieldName];
22
- if (field == null) {
23
- continue;
24
- }
25
- fieldConfigMap[fieldName] = {
26
- ...field,
27
- ...(_a = proxyingResolvers[type.name]) === null || _a === void 0 ? void 0 : _a[fieldName],
28
- };
29
- }
30
- return new graphql_1.GraphQLObjectType(config);
19
+ return {
20
+ ...fieldConfig,
21
+ ...(_a = proxyingResolvers[typeName]) === null || _a === void 0 ? void 0 : _a[fieldName],
22
+ };
23
+ },
24
+ [utils_1.MapperKind.OBJECT_FIELD]: fieldConfig => {
25
+ return {
26
+ ...fieldConfig,
27
+ resolve: delegate_1.defaultMergedResolver,
28
+ subscribe: undefined,
29
+ };
31
30
  },
32
31
  [utils_1.MapperKind.OBJECT_TYPE]: type => {
33
32
  const config = type.toConfig();
34
- config.isTypeOf = undefined;
35
- for (const fieldName in config.fields) {
36
- const field = config.fields[fieldName];
37
- if (field == null) {
38
- continue;
39
- }
40
- field.resolve = delegate_1.defaultMergedResolver;
41
- field.subscribe = undefined;
42
- }
43
- return new graphql_1.GraphQLObjectType(config);
33
+ return new graphql_1.GraphQLObjectType({
34
+ ...config,
35
+ isTypeOf: undefined,
36
+ });
44
37
  },
45
38
  [utils_1.MapperKind.INTERFACE_TYPE]: type => {
46
39
  const config = type.toConfig();
47
- delete config.resolveType;
48
- return new graphql_1.GraphQLInterfaceType(config);
40
+ return new graphql_1.GraphQLInterfaceType({
41
+ ...config,
42
+ resolveType: undefined,
43
+ });
49
44
  },
50
45
  [utils_1.MapperKind.UNION_TYPE]: type => {
51
46
  const config = type.toConfig();
52
- delete config.resolveType;
53
- return new graphql_1.GraphQLUnionType(config);
47
+ return new graphql_1.GraphQLUnionType({
48
+ ...config,
49
+ resolveType: undefined,
50
+ });
54
51
  },
55
- [utils_1.MapperKind.ENUM_VALUE]: (valueConfig, _typeName, _schema, externalValue) => {
52
+ [utils_1.MapperKind.ENUM_VALUE]: valueConfig => {
56
53
  return {
57
54
  ...valueConfig,
58
- value: externalValue,
55
+ value: undefined,
59
56
  };
60
57
  },
61
58
  });
@@ -1,4 +1,4 @@
1
- import { MapperKind, mapSchema } from '@graphql-tools/utils';
1
+ import { MapperKind, mapSchema, transformInputValue, } from '@graphql-tools/utils';
2
2
  import MapLeafValues from './MapLeafValues.js';
3
3
  export default class TransformEnumValues {
4
4
  constructor(enumValueTransformer, inputValueTransformer, outputValueTransformer) {
@@ -12,6 +12,18 @@ export default class TransformEnumValues {
12
12
  const mappingSchema = this.transformer.transformSchema(originalWrappingSchema, subschemaConfig);
13
13
  this.transformedSchema = mapSchema(mappingSchema, {
14
14
  [MapperKind.ENUM_VALUE]: (valueConfig, typeName, _schema, externalValue) => this.transformEnumValue(typeName, externalValue, valueConfig),
15
+ [MapperKind.ARGUMENT]: argConfig => {
16
+ if (argConfig.defaultValue != null) {
17
+ const newValue = transformInputValue(argConfig.type, argConfig.defaultValue, (type, value) => {
18
+ var _a, _b;
19
+ return (_b = (_a = this.mapping[type.name]) === null || _a === void 0 ? void 0 : _a[value]) !== null && _b !== void 0 ? _b : value;
20
+ });
21
+ return {
22
+ ...argConfig,
23
+ defaultValue: newValue,
24
+ };
25
+ }
26
+ },
15
27
  });
16
28
  return this.transformedSchema;
17
29
  }
@@ -40,8 +52,18 @@ export default class TransformEnumValues {
40
52
  this.reverseMapping[typeName][newExternalValue] = externalValue;
41
53
  this.noTransformation = false;
42
54
  }
55
+ return [
56
+ newExternalValue,
57
+ {
58
+ ...transformedEnumValue[1],
59
+ value: undefined,
60
+ },
61
+ ];
43
62
  }
44
- return transformedEnumValue;
63
+ return {
64
+ ...transformedEnumValue,
65
+ value: undefined,
66
+ };
45
67
  }
46
68
  }
47
69
  function mapEnumValues(typeName, value, mapping) {
package/esm/wrapSchema.js CHANGED
@@ -6,53 +6,50 @@ export const wrapSchema = memoize1(function wrapSchema(subschemaConfig) {
6
6
  const targetSchema = subschemaConfig.schema;
7
7
  const proxyingResolvers = generateProxyingResolvers(subschemaConfig);
8
8
  const schema = createWrappingSchema(targetSchema, proxyingResolvers);
9
- return applySchemaTransforms(schema, subschemaConfig);
9
+ const transformed = applySchemaTransforms(schema, subschemaConfig);
10
+ return transformed;
10
11
  });
11
12
  function createWrappingSchema(schema, proxyingResolvers) {
12
13
  return mapSchema(schema, {
13
- [MapperKind.ROOT_OBJECT]: type => {
14
+ [MapperKind.ROOT_FIELD]: (fieldConfig, fieldName, typeName) => {
14
15
  var _a;
15
- const config = type.toConfig();
16
- const fieldConfigMap = config.fields;
17
- for (const fieldName in fieldConfigMap) {
18
- const field = fieldConfigMap[fieldName];
19
- if (field == null) {
20
- continue;
21
- }
22
- fieldConfigMap[fieldName] = {
23
- ...field,
24
- ...(_a = proxyingResolvers[type.name]) === null || _a === void 0 ? void 0 : _a[fieldName],
25
- };
26
- }
27
- return new GraphQLObjectType(config);
16
+ return {
17
+ ...fieldConfig,
18
+ ...(_a = proxyingResolvers[typeName]) === null || _a === void 0 ? void 0 : _a[fieldName],
19
+ };
20
+ },
21
+ [MapperKind.OBJECT_FIELD]: fieldConfig => {
22
+ return {
23
+ ...fieldConfig,
24
+ resolve: defaultMergedResolver,
25
+ subscribe: undefined,
26
+ };
28
27
  },
29
28
  [MapperKind.OBJECT_TYPE]: type => {
30
29
  const config = type.toConfig();
31
- config.isTypeOf = undefined;
32
- for (const fieldName in config.fields) {
33
- const field = config.fields[fieldName];
34
- if (field == null) {
35
- continue;
36
- }
37
- field.resolve = defaultMergedResolver;
38
- field.subscribe = undefined;
39
- }
40
- return new GraphQLObjectType(config);
30
+ return new GraphQLObjectType({
31
+ ...config,
32
+ isTypeOf: undefined,
33
+ });
41
34
  },
42
35
  [MapperKind.INTERFACE_TYPE]: type => {
43
36
  const config = type.toConfig();
44
- delete config.resolveType;
45
- return new GraphQLInterfaceType(config);
37
+ return new GraphQLInterfaceType({
38
+ ...config,
39
+ resolveType: undefined,
40
+ });
46
41
  },
47
42
  [MapperKind.UNION_TYPE]: type => {
48
43
  const config = type.toConfig();
49
- delete config.resolveType;
50
- return new GraphQLUnionType(config);
44
+ return new GraphQLUnionType({
45
+ ...config,
46
+ resolveType: undefined,
47
+ });
51
48
  },
52
- [MapperKind.ENUM_VALUE]: (valueConfig, _typeName, _schema, externalValue) => {
49
+ [MapperKind.ENUM_VALUE]: valueConfig => {
53
50
  return {
54
51
  ...valueConfig,
55
- value: externalValue,
52
+ value: undefined,
56
53
  };
57
54
  },
58
55
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/wrap",
3
- "version": "9.3.0",
3
+ "version": "9.3.1",
4
4
  "description": "A set of utils for faster development of GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {