Skip to content

Commit

Permalink
Merge branch 'hotfix/doubleprecision' into release/v0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
skoch-tf committed Apr 30, 2020
2 parents 7ec5e5d + c41371d commit 1399868
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 5,391 deletions.
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 @@ -135,6 +135,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 () {
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(parent, args, context, info) {
var associations, include, instance;
Expand Down Expand Up @@ -197,7 +200,7 @@ function resolvers(sequelize, pubsub) {
});
}

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

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

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

case 9:
case "end":
Expand Down
18 changes: 11 additions & 7 deletions lib/schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
function assertNotEmpty(obj, msg) {
if (obj === undefined || obj === null) 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 All @@ -43,7 +47,7 @@ function generateInputOperators(sequelize) {
if (model.options.gqIgnore) return acc;
Object.values(model.rawAttributes).forEach(function (attribute) {
if (attribute.gqIgnore) return acc;
var type = attribute.type.key;
var type = getTypeFromAttribute(attribute);

if (attribute.primaryKey) {
type = 'ID';
Expand Down Expand Up @@ -75,7 +79,7 @@ function generateInputWhere(sequelize) {
Object.values(model.rawAttributes).forEach(function (attribute) {
if (attribute.gqIgnore) return;
if (attribute.type instanceof _sequelize["default"].VIRTUAL) return;
var type = (0, _lodash["default"])((0, _types.mapTypes)(attribute.type.key));
var type = (0, _lodash["default"])((0, _types.mapTypes)(getTypeFromAttribute(attribute)));

if (attribute.primaryKey) {
type = 'ID';
Expand Down Expand Up @@ -107,7 +111,7 @@ function generateInputCreate(sequelize) {
return;
}

var type = (0, _lodash["default"])((0, _types.mapTypes)(attribute.type.key));
var type = (0, _lodash["default"])((0, _types.mapTypes)(getTypeFromAttribute(attribute)));

if (attribute.references && attribute.references.model && model.sequelize.models[attribute.references.model] && model.sequelize.models[attribute.references.model].primaryKeys && model.sequelize.models[attribute.references.model].primaryKeys[[attribute.references.key]].primaryKey) {
type = 'ID';
Expand Down Expand Up @@ -157,7 +161,7 @@ function generateInputUpdate(sequelize) {
return;
}

var type = (0, _lodash["default"])((0, _types.mapTypes)(attribute.type.key));
var type = (0, _lodash["default"])((0, _types.mapTypes)(getTypeFromAttribute(attribute)));

if (attribute.primaryKey) {
type = 'ID';
Expand All @@ -182,7 +186,7 @@ function generateTypeModels(sequelize) {
if (!acc[modelName]) acc[modelName] = {};
Object.values(model.rawAttributes).forEach(function (attribute) {
if (attribute.gqIgnore === true) return;
var type = (0, _lodash["default"])((0, _types.mapTypes)(attribute.type.key));
var type = (0, _lodash["default"])((0, _types.mapTypes)(getTypeFromAttribute(attribute)));

if (attribute.primaryKey) {
type = 'ID';
Expand Down Expand Up @@ -287,13 +291,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
2 changes: 1 addition & 1 deletion package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"name": "graphqlizejs",
"description": "Generate DataTypes and Resolvers from your ORM Sequilize models",
"version": "0.3.6",
"version": "0.3.7",
"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
29 changes: 21 additions & 8 deletions test/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,15 @@ describe('Resolvers', function() {

const gqResult = await queryClient({
query: gql`
mutation UpdateProudt($id: ID, $product: _inputUpdateProduct) {
mutation UpdateProducts($id: ID, $product: _inputUpdateProduct) {
product: updateProduct(
where: { id: { eq: $id } }
input: $product
)
) {
id
description
price
}
}
`,
variables: {
Expand All @@ -238,16 +242,18 @@ describe('Resolvers', function() {
});

const expectedGqResult = gqResult.data.product;
expectedGqResult.id = String(expectedGqResult.id);
const dbResult = await db.sequelize.models.product.findByPk(10);
const expectedDbResult = pick(dbResult.toJSON(), [
'id',
'description',
'price',
]);
expectedDbResult.id = String(expectedDbResult.id);

expect(expectedDbResult).to.not.be.null;
expect(expectedGqResult).to.not.be.null;
expect(expectedGqResult).to.be.eql(1);
expect(expectedGqResult).to.be.eql([expectedDbResult]);
expect(newPrice).to.equal(expectedDbResult.price);
expect(newDescription).to.be.eql(expectedDbResult.description);
});
Expand All @@ -259,16 +265,18 @@ describe('Resolvers', function() {

const deleteProduct = await queryClient({
query: gql`
mutation DeleteProudt($id: ID) {
product: deleteProduct(where: { id: { eq: $id } })
mutation DeleteProducts($id: ID) {
product: deleteProduct(where: { id: { eq: $id } }) {
id
}
}
`,
variables: {
id: createdProductId,
},
});

const quantityDeletedProduts = deleteProduct.data.product;
const quantityDeletedProduts = deleteProduct.data.product.length;

const shouldNotExist = await db.sequelize.models.product.findByPk(
createdProductId
Expand Down Expand Up @@ -372,15 +380,20 @@ describe('Resolvers', function() {
productId: { eq: $productId }
orderId: { eq: $orderId }
}
)
) {
productId
orderId
}
}
`,
variables: {
productId: String(productId),
orderId: String(orderId),
},
});
expect(gqDeleteOrderProduct.data.deleteOrderproduct).to.be.equal(1);


expect(gqDeleteOrderProduct.data.deleteOrderproduct.length).to.be.equal(1);
});
});
});
Expand Down

0 comments on commit 1399868

Please sign in to comment.