@cran/gql.jm
Version:
Cran/GraphQL Join Monster Utilities
47 lines (46 loc) • 1.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withSqlColumn = void 0;
const withSqlComposite_1 = require("./withSqlComposite");
const gql_core_1 = require("@cran/gql.core");
// sqlWhere(column: "", op: "=" (ctx,args)=>, value: (ctx,args)=>)
const fields = {
name: "sqlColumn",
deps: "sqlDeps",
expr: "sqlExpr",
join: "sqlJoin",
where: "where",
orderBy: "orderBy",
limit: "limit",
paginate: "sqlPaginate",
};
const nonFunction = {
name: true,
deps: true,
};
// eslint-disable-next-line max-lines-per-function
function withSqlColumn(name = "sqlColumn") {
return (0, gql_core_1.createDirective)(name, {
name: "text",
deps: "[text!]",
expr: "text",
join: "text",
where: "text",
orderBy: "text",
limit: "text",
paginate: "bool",
}, {
[gql_core_1.MapperKind.COMPOSITE_FIELD]([directive,], field, fieldName) {
const ext = (0, gql_core_1.getExtension)(field, "joinMonster", {});
for (const key in fields) {
if (key in directive) {
ext[fields[key]] = nonFunction[key]
? directive[key]
: new gql_core_1.Executable(fields[key], directive[key]);
}
}
(0, withSqlComposite_1.markComposite)(field, fieldName);
},
});
}
exports.withSqlColumn = withSqlColumn;