simple-graphql
Version:
The simple way to generates GraphQL schemas and Sequelize models from your models definition.
51 lines • 1.98 kB
JavaScript
;
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const crypto_1 = __importDefault(require("crypto"));
function md5(source) {
return crypto_1.default.createHash('md5').update(source).digest('hex');
}
exports.default = (dbModel, options) => {
options = options || {};
const formatInclude = (include) => {
if (include) {
const { parent, association } = include, other = __rest(include, ["parent", "association"]);
if (other.include && Array.isArray(other.include)) {
other.include = other.include.map((i) => formatInclude(i));
}
return {
as: other.as,
attributes: other.attributes,
include: other.include
};
}
return include;
};
const getInclude = () => {
if (Array.isArray(options.include)) {
return options.include;
}
else if (options.include != null) {
return [options.include];
}
else {
return [];
}
};
const include = getInclude().map((i) => formatInclude(i));
return md5(JSON.stringify(Object.assign(Object.assign({}, options), { include: include, where: dbModel.queryGenerator.whereQuery(options.where) })));
};
//# sourceMappingURL=getFindOptionsKey.js.map