const mutationType = new graphql.GraphQLObjectType({
name: "Mutation",
fields: {
createPost: {
type: PostType,
args: {
title: {
type: new graphql.GraphQLNonNull(graphql.GraphQLString),
},
body: {
type: new graphql.GraphQLNonNull(graphql.GraphQLString),
},
author_id: { type: new graphql.GraphQLNonNull(graphql.GraphQLID) },
},
resolve: (root, { title, body, author_id }) => {
return new Promise((resolve, reject) => {
database.run(
"INSERT INTO Posts (title, body, author_id) VALUES (?,?,?);",
[title, body, author_id],
(err) => {
if (err) {
reject(null);
}
database.get("SELECT last_insert_rowid() as id", (err, row) => {
resolve({
id: row["id"],
title: title,
body: body,
author_id: author_id,
});
});
}
);
});
},
},
},
});