@cran/gql.jm
Version:
Cran/GraphQL Join Monster Utilities
32 lines (31 loc) • 1.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendJunction = void 0;
const gql_core_1 = require("@cran/gql.core");
function extendJunctionInclude(includes) {
return function include(args, context) {
return Object.fromEntries(includes.map(function mapIncludes([field, { sqlColumn, sqlDeps, sqlExpr, },]) {
return [field, {
sqlColumn,
sqlDeps,
sqlExpr: sqlExpr instanceof Function
? sqlExpr(args, context) : undefined,
},];
}));
};
}
function extendJunction(field, args) {
// eslint-disable-next-line no-return-assign
return Object.assign((0, gql_core_1.getExtension)(field, "joinMonster", {}).junction = {
sqlTable: new gql_core_1.Executable("sqlTable", args.name),
}, {
include: extendJunctionInclude((0, gql_core_1.getExtension)(field, "joinMonsterIncludes", [])),
where: args.where
? new gql_core_1.Executable("where", args.where)
: undefined,
orderBy: args.order
? new gql_core_1.Executable("orderBy", args.order)
: undefined,
});
}
exports.extendJunction = extendJunction;