@graphql-mesh/transport-rest
Version:
55 lines (54 loc) • 2.13 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.addExecutionLogicToScalar = exports.processScalarType = void 0;
const graphql_scalars_1 = require("graphql-scalars");
const transport_common_1 = require("@graphql-mesh/transport-common");
const length_js_1 = require("./length.js");
const regexp_js_1 = require("./regexp.js");
const typescriptAnnotations_js_1 = require("./typescriptAnnotations.js");
const utils_js_1 = require("./utils.js");
function processScalarType(type) {
if (type.name in graphql_scalars_1.resolvers) {
const actualScalar = graphql_scalars_1.resolvers[type.name];
addExecutionLogicToScalar(type, actualScalar);
}
if (type.name === 'ObjMap') {
addExecutionLogicToScalar(type, transport_common_1.ObjMapScalar);
}
const directiveAnnotations = (0, utils_js_1.getDirectiveAnnotations)(type);
for (const directiveAnnotation of directiveAnnotations) {
switch (directiveAnnotation.name) {
case 'length':
(0, length_js_1.processLengthAnnotations)(type, directiveAnnotation.args);
break;
case 'regexp':
(0, regexp_js_1.processRegExpAnnotations)(type, directiveAnnotation.args.pattern);
break;
case 'typescript':
(0, typescriptAnnotations_js_1.processTypeScriptAnnotations)(type, directiveAnnotation.args.type);
break;
}
}
return type;
}
exports.processScalarType = processScalarType;
function addExecutionLogicToScalar(nonExecutableScalar, actualScalar) {
Object.defineProperties(nonExecutableScalar, {
serialize: {
value: actualScalar.serialize,
},
parseValue: {
value: actualScalar.parseValue,
},
parseLiteral: {
value: actualScalar.parseLiteral,
},
extensions: {
value: {
...actualScalar.extensions,
...nonExecutableScalar.extensions,
},
},
});
}
exports.addExecutionLogicToScalar = addExecutionLogicToScalar;
;