Skip to content

Commit

Permalink
Merge pull request #10 from Nickolasmv/patch-1
Browse files Browse the repository at this point in the history
Update schemas.js
  • Loading branch information
stvkoch authored Apr 30, 2020
2 parents c6b3729 + 8f045cf commit c41371d
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 10,836 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,4 @@ typings/

# DynamoDB Local files
.dynamodb/
database.sqlite
5,363 changes: 0 additions & 5,363 deletions example/yarn.lock

This file was deleted.

7 changes: 5 additions & 2 deletions lib/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ function resolvers(sequelize, pubsub) {
modelName = getModelName(model);
var singular = modelName;
var singularUF = (0, _lodash.default)(singular);

var plural = _sequelize.default.Utils.pluralize(modelName).toLowerCase();

if (model.gqCreate !== false) acc['create' + singularUF] = model.options.gqMiddleware.create(
/*#__PURE__*/
function () {
Expand Down Expand Up @@ -203,7 +206,7 @@ function resolvers(sequelize, pubsub) {
});
}

return _context2.abrupt("return", result);
return _context2.abrupt("return", instances);

case 11:
case "end":
Expand Down Expand Up @@ -246,7 +249,7 @@ function resolvers(sequelize, pubsub) {
});
}

return _context3.abrupt("return", result);
return _context3.abrupt("return", instances);

case 9:
case "end":
Expand Down
4 changes: 2 additions & 2 deletions lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ function generateMutations(sequelize) {
acc[operation] = {
name: operation,
arguments: "where: _inputWhere".concat(name, ", input: _inputUpdate").concat(name),
type: "Int!"
type: "[".concat(name, "]")
};
operation = "delete".concat(name);
acc[operation] = {
name: operation,
arguments: "where: _inputWhere".concat(name),
type: "Int!"
type: "[".concat(name, "]")
};
return acc;
}, {});
Expand Down
41 changes: 11 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"description": "Generate DataTypes and Resolvers from your ORM Sequilize models",
"version": "0.3.5",
"main": "./lib/index.js",
"engines": {
"node": "10.x"
},
"keywords": [
"sequelizejs",
"sequelize",
Expand Down
5 changes: 3 additions & 2 deletions src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export function resolvers(

const singular = modelName;
const singularUF = upperFirst(singular);
const plural = Sequelize.Utils.pluralize(modelName).toLowerCase();

if (model.gqCreate !== false)
acc['create' + singularUF] = model.options.gqMiddleware.create(
Expand Down Expand Up @@ -189,7 +190,7 @@ export function resolvers(
})
);
}
return result;
return instances;
}
);

Expand All @@ -206,7 +207,7 @@ export function resolvers(
})
);
}
return result;
return instances;
}
);

Expand Down
18 changes: 11 additions & 7 deletions src/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ function assertNotEmpty(obj, msg) {
throw Error(msg || 'Object should be not a undefined or null');
}

function getTypeFromAttribute(attribute){
return attribute.type.key.split(' ')[0]; // TODO: use common approach
}

/*
Create your dataTypes from your models
*/
Expand Down Expand Up @@ -47,7 +51,7 @@ function generateInputOperators(sequelize) {
Object.values(model.rawAttributes).forEach(attribute => {
if (attribute.gqIgnore) return acc;

let type = attribute.type.key;
let type = getTypeFromAttribute(attribute)
if (attribute.primaryKey) {
type = 'ID';
}
Expand Down Expand Up @@ -98,7 +102,7 @@ function generateInputWhere(sequelize) {
if (attribute.gqIgnore) return;
if (attribute.type instanceof Sequelize.VIRTUAL) return;

let type = upperFirst(mapTypes(attribute.type.key));
let type = upperFirst(mapTypes(getTypeFromAttribute(attribute)));
if (attribute.primaryKey) {
type = 'ID';
}
Expand Down Expand Up @@ -142,7 +146,7 @@ function generateInputCreate(sequelize) {
return;
}

let type = upperFirst(mapTypes(attribute.type.key));
let type = upperFirst(mapTypes(getTypeFromAttribute(attribute)));

if (
attribute.references &&
Expand Down Expand Up @@ -218,7 +222,7 @@ function generateInputUpdate(sequelize) {
if (attribute.primaryKey && !model.options.gqInputUpdateWithPrimaryKeys) {
return;
}
let type = upperFirst(mapTypes(attribute.type.key));
let type = upperFirst(mapTypes(getTypeFromAttribute(attribute)));
if (attribute.primaryKey) {
type = 'ID';
}
Expand Down Expand Up @@ -249,7 +253,7 @@ function generateTypeModels(sequelize) {
Object.values(model.rawAttributes).forEach(attribute => {
if (attribute.gqIgnore === true) return;

let type = upperFirst(mapTypes(attribute.type.key));
let type = upperFirst(mapTypes(getTypeFromAttribute(attribute)));
if (attribute.primaryKey) {
type = 'ID';
}
Expand Down Expand Up @@ -376,13 +380,13 @@ function generateMutations(sequelize) {
acc[operation] = {
name: operation,
arguments: `where: _inputWhere${name}, input: _inputUpdate${name}`,
type: `Int!`,
type: `[${name}]`,
};
operation = `delete${name}`;
acc[operation] = {
name: operation,
arguments: `where: _inputWhere${name}`,
type: `Int!`,
type: `[${name}]`,
};

return acc;
Expand Down
Loading

0 comments on commit c41371d

Please sign in to comment.