When using GraphQL mutations to create records, it expects the full object in return, e.g.:
mutation {
createPost(title: "Good morning") {
id
title
}
}
How do I reliably get MySQL to return the newly inserted item? I'm currently doing this:
INSERT INTO posts(title) VALUES('Good morning');
SELECT * FROM posts WHERE id = LAST_INSERT_ID();
But I'm not sure if this is the best way. What if another user happens to perform an INSERT
immediately after my own? Would LAST_INSERT_ID()
refer to their primary key ID instead of mine?