graphql-sequelize-crud-teselagen
Advanced tools
Comparing version
@@ -71,2 +71,24 @@ 'use strict'; | ||
const TodoNote = sequelize.define('TodoNote', { | ||
id: { | ||
type: Sequelize.INTEGER, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
allowNull: true | ||
}, | ||
dbId: { | ||
type: Sequelize.INTEGER, | ||
allowNull: true, | ||
get: function() { | ||
return this.getDataValue("id"); | ||
} | ||
}, | ||
text: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
}, { | ||
timestamps: true | ||
}); | ||
const TodoAssignee = sequelize.define('TodoAssignee', { | ||
@@ -81,2 +103,11 @@ primary: { | ||
Todo.hasMany(TodoNote, { | ||
as: 'todonotes', | ||
foreignKey: 'todoId' | ||
}); | ||
TodoNote.belongsTo(Todo, { | ||
as: 'todo', | ||
foreignKey: 'todoId' | ||
}); | ||
User.hasMany(Todo, { | ||
@@ -83,0 +114,0 @@ as: 'todos', |
@@ -5,2 +5,8 @@ "use strict"; | ||
var _condenseAssociations = require('./condenseAssociations'); | ||
var _condenseAssociations2 = _interopRequireDefault(_condenseAssociations); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
@@ -222,18 +228,18 @@ | ||
convertFieldsFromGlobalId(Model, data); | ||
var associationNames = {}; | ||
(0, _condenseAssociations2.default)(associationNames, undefined, Model.associations, data); | ||
function buildUpIncludes(associationsToInclude, associations, data) { | ||
function buildUpIncludes(associationsToInclude, associations, associationNames) { | ||
_.each(associations, function (association, akey) { | ||
if (data[akey]) { | ||
convertFieldsFromGlobalId(association.target, data[akey]); | ||
var relatedAssociationsToInclude = { | ||
association: association, | ||
include: [] | ||
}; | ||
var relatedAssociationsToInclude = { | ||
association: association, | ||
include: [] | ||
}; | ||
if (associationNames[akey]) { | ||
associationsToInclude.include.push(relatedAssociationsToInclude); | ||
buildUpIncludes(relatedAssociationsToInclude, association.target.associations, data[akey]); | ||
buildUpIncludes(relatedAssociationsToInclude, association.target.associations, associationNames[akey]); | ||
} | ||
}); | ||
} | ||
buildUpIncludes(associationsToInclude, Model.associations, data); | ||
buildUpIncludes(associationsToInclude, Model.associations, associationNames); | ||
var a = Model.create(data, associationsToInclude); | ||
@@ -240,0 +246,0 @@ return a; |
{ | ||
"name": "graphql-sequelize-crud-teselagen", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"description": "Automatically generate queries and mutations from Sequelize models", | ||
@@ -11,3 +11,3 @@ "main": "lib/index.js", | ||
"prepublish": "npm run build", | ||
"test": "mocha --compilers js:babel-core/register", | ||
"test": "jest --coverage", | ||
"build": "rm -rf lib/* && babel src --ignore test --out-dir lib", | ||
@@ -37,3 +37,3 @@ "start": "babel-watch demo/", | ||
], | ||
"author": "Glavin Wiechert (https://github.com/teselagen)", | ||
"author": "TeselaGen (https://github.com/teselagen)", | ||
"license": "MIT", | ||
@@ -58,2 +58,3 @@ "bugs": { | ||
"graphqlviz": "^1.1.0", | ||
"jest": "^20.0.4", | ||
"mocha": "^2.5.3", | ||
@@ -60,0 +61,0 @@ "mysql": "^2.11.1", |
# graphql-sequelize-crud | ||
[](https://circleci.com/gh/TeselaGen/graphql-sequelize-crud) | ||
[](https://nodei.co/npm/graphql-sequelize-crud/) | ||
[](https://nodei.co/npm/graphql-sequelize-crud/) | ||
[](https://codecov.io/gh/TeselaGen/graphql-sequelize-crud) | ||
[](https://travis-ci.org/Glavin001/graphql-sequelize-crud) | ||
> Automatically generate queries and mutations from Sequelize models | ||
@@ -9,0 +7,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
193346
20.86%14
7.69%1352
4.16%19
5.56%83
-2.35%