UNPKG

@grapi/server

Version:

Grapi Schema Generator For GraphQL Server

61 lines (60 loc) 1.75 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lodash_1 = require("../lodash"); const field_1 = __importDefault(require("./field")); const type_1 = require("./type"); class RelationField extends field_1.default { relationTo; relationConfig; relationName; relationType; relation; constructor({ relationTo, relationConfig, nonNull, list, nonNullItem, readOnly, }) { super({ type: type_1.DataModelType.RELATION, nonNull, list, nonNullItem, readOnly, }); this.relationTo = relationTo; this.relationConfig = relationConfig; } getTypename() { return this.getRelationTo().getTypename(); } getRelationTo() { return (0, lodash_1.isFunction)(this.relationTo) ? this.relationTo() : this.relationTo; } getRelationConfig() { if (!this.relationConfig) { return {}; } return (0, lodash_1.isFunction)(this.relationConfig) ? this.relationConfig() : this.relationConfig; } getFields() { return this.getRelationTo().getFields(); } getRelationName() { return this.relationName; } setRelationName(name) { this.relationName = name; } getRelationType() { return this.relationType; } setRelationType(relationType) { this.relationType = relationType; } getRelation() { return this.relation; } setRelation(relationShip) { this.relation = relationShip; } } exports.default = RelationField;