@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.
- package/cjs/transforms/TransformEnumValues.js +23 -1
- package/cjs/wrapSchema.js +28 -31
- package/esm/transforms/TransformEnumValues.js +24 -2
- package/esm/wrapSchema.js +28 -31
- package/package.json +1 -1
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
17
|
+
[utils_1.MapperKind.ROOT_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
17
18
|
var _a;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
47
|
+
return new graphql_1.GraphQLUnionType({
|
|
48
|
+
...config,
|
|
49
|
+
resolveType: undefined,
|
|
50
|
+
});
|
|
54
51
|
},
|
|
55
|
-
[utils_1.MapperKind.ENUM_VALUE]:
|
|
52
|
+
[utils_1.MapperKind.ENUM_VALUE]: valueConfig => {
|
|
56
53
|
return {
|
|
57
54
|
...valueConfig,
|
|
58
|
-
value:
|
|
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
|
|
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
|
-
|
|
9
|
+
const transformed = applySchemaTransforms(schema, subschemaConfig);
|
|
10
|
+
return transformed;
|
|
10
11
|
});
|
|
11
12
|
function createWrappingSchema(schema, proxyingResolvers) {
|
|
12
13
|
return mapSchema(schema, {
|
|
13
|
-
[MapperKind.
|
|
14
|
+
[MapperKind.ROOT_FIELD]: (fieldConfig, fieldName, typeName) => {
|
|
14
15
|
var _a;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
44
|
+
return new GraphQLUnionType({
|
|
45
|
+
...config,
|
|
46
|
+
resolveType: undefined,
|
|
47
|
+
});
|
|
51
48
|
},
|
|
52
|
-
[MapperKind.ENUM_VALUE]:
|
|
49
|
+
[MapperKind.ENUM_VALUE]: valueConfig => {
|
|
53
50
|
return {
|
|
54
51
|
...valueConfig,
|
|
55
|
-
value:
|
|
52
|
+
value: undefined,
|
|
56
53
|
};
|
|
57
54
|
},
|
|
58
55
|
});
|