Skip to content
This repository was archived by the owner on May 24, 2020. It is now read-only.

fixed tests failed #6

Merged
merged 4 commits into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions dist/graphql-sequelize-schema-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ var generateMutationRootType = function generateMutationRootType(models, inputTy
var _Object$assign2;

var inputType = inputTypes[inputTypeName];
var key = models[inputTypeName].primaryKeyAttributes[0];
var toReturn = Object.assign(fields, (_Object$assign2 = {}, _defineProperty(_Object$assign2, inputTypeName + 'Create', {
type: outputTypes[inputTypeName], // what is returned by resolve, must be of type GraphQLObjectType
description: 'Create a ' + inputTypeName,
Expand All @@ -129,22 +130,20 @@ var generateMutationRootType = function generateMutationRootType(models, inputTy
description: 'Update a ' + inputTypeName,
args: _defineProperty({}, inputTypeName, { type: inputType }),
resolve: function resolve(source, args, context, info) {
var where = _defineProperty({}, key, args[inputTypeName][key]);
return models[inputTypeName].update(args[inputTypeName], {
where: { id: args[inputTypeName].id }
where: where
}).then(function (boolean) {
// `boolean` equals the number of rows affected (0 or 1)
return resolver(models[inputTypeName])(source, { id: args[inputTypeName].id }, context, info);
return resolver(models[inputTypeName])(source, where, context, info);
});
}
}), _defineProperty(_Object$assign2, inputTypeName + 'Delete', {
type: GraphQLInt,
description: 'Delete a ' + inputTypeName,
args: {
id: { type: new GraphQLNonNull(GraphQLInt) }
},
resolve: function resolve(value, _ref) {
var id = _ref.id;
return models[inputTypeName].destroy({ where: { id: id } });
args: _defineProperty({}, key, { type: new GraphQLNonNull(GraphQLInt) }),
resolve: function resolve(value, where) {
return models[inputTypeName].destroy({ where: where });
} // Returns the number of rows affected (0 or 1)
}), _Object$assign2));
return toReturn;
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
},
"homepage": "https://github.com/rpellerin/graphql-sequelize-schema-generator#readme",
"dependencies": {
"graphql": "^0.9.1",
"graphql-relay": "^0.5.1",
"graphql-sequelize": "^5.3.1",
"sequelize": "^3.30.2"
"graphql": "^0.10.3",
"graphql-relay": "^0.5.2",
"graphql-sequelize": "^5.3.3",
"sequelize": "^4.2.1"
},
"devDependencies": {
"babel-cli": "^6.24.0",
Expand All @@ -50,8 +50,8 @@
"stringifier": "^1.3.0"
},
"peerDependencies": {
"graphql": "^0.9.1",
"sequelize": "^3.30.2"
"graphql": "^0.10.3",
"sequelize": "^4.2.1"
},
"jest": {
"testEnvironment": "node",
Expand Down
12 changes: 7 additions & 5 deletions src/graphql-sequelize-schema-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const generateMutationRootType = (models, inputTypes, outputTypes) => {
fields: Object.keys(inputTypes).reduce(
(fields, inputTypeName) => {
const inputType = inputTypes[inputTypeName]
const key = models[inputTypeName].primaryKeyAttributes[0]
const toReturn = Object.assign(fields, {
[inputTypeName + 'Create']: {
type: outputTypes[inputTypeName], // what is returned by resolve, must be of type GraphQLObjectType
Expand All @@ -145,15 +146,16 @@ const generateMutationRootType = (models, inputTypes, outputTypes) => {
[inputTypeName]: {type: inputType}
},
resolve: (source, args, context, info) => {
const where = { [key]: args[inputTypeName][key] }
return models[inputTypeName]
.update(args[inputTypeName], {
where: {id: args[inputTypeName].id}
where
})
.then(boolean => {
// `boolean` equals the number of rows affected (0 or 1)
return resolver(models[inputTypeName])(
source,
{id: args[inputTypeName].id},
where,
context,
info
)
Expand All @@ -164,10 +166,10 @@ const generateMutationRootType = (models, inputTypes, outputTypes) => {
type: GraphQLInt,
description: 'Delete a ' + inputTypeName,
args: {
id: {type: new GraphQLNonNull(GraphQLInt)}
[key]: {type: new GraphQLNonNull(GraphQLInt)}
},
resolve: (value, {id}) =>
models[inputTypeName].destroy({where: {id}}) // Returns the number of rows affected (0 or 1)
resolve: (value, where) =>
models[inputTypeName].destroy({ where }) // Returns the number of rows affected (0 or 1)
}
})
return toReturn
Expand Down
Loading