@cran/gql.jm
Version:
Cran/GraphQL Join Monster Utilities
28 lines (27 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withSqlTable = void 0;
const withSqlComposite_1 = require("./withSqlComposite");
const gql_core_1 = require("@cran/gql.core");
function withSqlTable(name = "sqlTable") {
return (0, gql_core_1.createDirective)(name, {
name: "text!",
key: "[text!]",
fetch: "[text!]",
}, {
[gql_core_1.MapperKind.COMPOSITE_TYPE]([directive,], composite) {
Object.assign((0, gql_core_1.getExtension)(composite, "joinMonster", {}), {
sqlTable: directive.name,
uniqueKey: directive.key || "id",
alwaysFetch: directive.fetch,
});
if ("getFields" in composite) {
const fields = composite.getFields();
for (const fieldName in fields) {
(0, withSqlComposite_1.markComposite)(fields[fieldName], fieldName);
}
}
},
});
}
exports.withSqlTable = withSqlTable;