graphql-compose-mongoose
Version:
Plugin for `graphql-compose` which derive a graphql types from a mongoose model.
35 lines • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeFieldsRecursiveNullable = makeFieldsRecursiveNullable;
const graphql_compose_1 = require("graphql-compose");
function makeFieldsRecursiveNullable(itc, opts) {
itc.getFieldNames().forEach((fieldName) => {
itc.makeFieldNullable(fieldName);
let fieldTC = itc.getFieldTC(fieldName);
if (fieldTC instanceof graphql_compose_1.InputTypeComposer) {
if ((opts === null || opts === void 0 ? void 0 : opts.prefix) || (opts === null || opts === void 0 ? void 0 : opts.suffix)) {
const newName = dedupedName(fieldTC.getTypeName(), opts);
fieldTC = fieldTC.clone(newName);
itc.getField(fieldName).type = (0, graphql_compose_1.replaceTC)(itc.getField(fieldName).type, fieldTC);
}
if (!opts.skipTypes)
opts.skipTypes = [];
if (!opts.skipTypes.includes(fieldTC)) {
opts.skipTypes.push(fieldTC);
makeFieldsRecursiveNullable(fieldTC, opts);
}
}
});
}
function dedupedName(name, opts) {
let newName = name;
const { prefix, suffix } = opts;
if (prefix && !newName.startsWith(prefix)) {
newName = `${prefix}${newName}`;
}
if (suffix && !newName.endsWith(suffix)) {
newName = `${newName}${suffix}`;
}
return newName;
}
//# sourceMappingURL=makeFieldsRecursiveNullable.js.map