@zuu/owl
Version:
Zuu's Experimental GraphQL Implementation
46 lines • 1.63 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const returnTypes_1 = require("./returnTypes");
const errors_1 = require("../errors");
function findType({ metadataKey, prototype, propertyKey, returnTypeFunc, typeOptions = {}, parameterIndex, }) {
const options = Object.assign({}, typeOptions);
let metadataDesignType;
const reflectedType = Reflect.getMetadata(metadataKey, prototype, propertyKey);
if (metadataKey === "design:paramtypes") {
metadataDesignType = reflectedType[parameterIndex];
}
else {
metadataDesignType = reflectedType;
}
if (metadataDesignType && returnTypes_1.bannedTypes.includes(metadataDesignType)) {
if (!returnTypeFunc) {
throw new errors_1.NoExplicitTypeError(prototype.constructor.name, propertyKey, parameterIndex);
}
if (metadataDesignType === Array) {
options.array = true;
}
}
if (returnTypeFunc && Array.isArray(returnTypeFunc())) {
options.array = true;
}
if (returnTypeFunc) {
const getType = Array.isArray(returnTypeFunc())
? () => returnTypeFunc()[0]
: returnTypeFunc;
return {
getType,
typeOptions: options,
};
}
else if (metadataDesignType) {
return {
getType: () => metadataDesignType,
typeOptions: options,
};
}
else {
throw new errors_1.CannotDetermineTypeError(prototype.constructor.name, propertyKey, parameterIndex);
}
}
exports.findType = findType;
//# sourceMappingURL=findType.js.map