simple-graphql
Version:
The simple way to generates GraphQL schemas and Sequelize models from your models definition.
69 lines • 2.31 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SGSchema = void 0;
const lodash_1 = __importDefault(require("lodash"));
const BaseSGSchema_1 = require("./BaseSGSchema");
class SGSchema extends BaseSGSchema_1.BaseSGSchema {
constructor(name, options = {}) {
super(name, options);
this.config = {
fields: {},
links: {},
associations: {
hasOne: {},
belongsTo: {},
hasMany: {},
belongsToMany: {}
},
queries: {},
subscriptions: {},
mutations: {},
methods: {},
statics: {}
};
}
/**
* Add {@link http://docs.sequelizejs.com/en/latest/docs/associations/#hasone|HasOne} relations to current Schema.
*/
hasOne(config) {
lodash_1.default.forOwn(config, (value, key) => {
this.config.associations.hasOne[key] = value;
});
return this;
}
/**
* Add {@link http://docs.sequelizejs.com/en/latest/docs/associations/#belongsto|BelongsTo} relations to current Schema.
*/
belongsTo(config) {
lodash_1.default.forOwn(config, (value, key) => {
this.config.associations.belongsTo[key] = value;
});
return this;
}
/**
* Add {@link http://docs.sequelizejs.com/en/latest/docs/associations/#one-to-many-associations|HasMany} relations to current Schema.
*/
hasMany(config) {
lodash_1.default.forOwn(config, (value, key) => {
this.config.associations.hasMany[key] = value;
});
return this;
}
/**
* Add {@link http://docs.sequelizejs.com/en/latest/docs/associations/#belongs-to-many-associations|BelongsToMany} relations to current Schema.
*/
belongsToMany(config) {
lodash_1.default.forOwn(config, (value, key) => {
this.config.associations.belongsToMany[key] = value;
});
return this;
}
plugin(plugin, options) {
plugin(this, options);
}
}
exports.SGSchema = SGSchema;
//# sourceMappingURL=SGSchema.js.map