Skip to content

Commit 2874ace

Browse files
authored
Merge pull request #32 from sioked/bugfix/fix-update-issue
Fix for calling update multiple times
2 parents cfd9673 + 2e715a4 commit 2874ace

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/jsonGraphqlExpress.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ describe('integration tests', () => {
9696
},
9797
},
9898
}));
99+
it('allows multiple mutations', () =>
100+
gqlAgent(
101+
'mutation{ updatePost(id:"2", title:"Foo bar", views: 200, user_id:"123") { id } }'
102+
).then(() =>
103+
gqlAgent(
104+
'mutation{ updatePost(id:"2", title:"Foo bar", views: 200, user_id:"123") { id } }'
105+
).expect({
106+
data: {
107+
updatePost: {
108+
id: 2,
109+
},
110+
},
111+
})
112+
));
99113
});

src/resolver/Mutation/update.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export default (entityData = []) => (_, params) => {
22
const parsedId = parseInt(params.id, 10); // FIXME fails for non-integer ids
3-
const indexOfEntity = entityData.findIndex(e => e.id === parsedId);
3+
const indexOfEntity = entityData.findIndex(
4+
e => parseInt(e.id, 10) === parsedId
5+
);
46
if (indexOfEntity !== -1) {
57
entityData[indexOfEntity] = Object.assign(
68
{},

0 commit comments

Comments
 (0)