MySQL最后插入ID Graphql

时间:2019-03-17 13:21:46

标签: mysql node.js graphql

我正在使用GraphQL和节点来操纵MySQL数据库。 但是,对于在使用前者的最后插入ID成功插入到前一个表中之后如何将记录插入到表中,我感到困惑。

const Mutation = new GraphQLObjectType({
        AddAuthor: {
            type: AuthorType,
            args: {
                name: { type: new GraphQLNonNull(GraphQLString) },
                age: { type: new GraphQLNonNull(GraphQLInt) },
            },
            async resolve(parent, args){
                let data = {
                    name: args.name,
                    age: args.age
                };

                const saveAuthor = await knex.insert(data).returning('id').into('authors');

                if(saveAuthor){
                    const insert_id = saveAuthor[0]; //from previous insertion
                    **//Perform a mutation to add the ID into another table which already has a mutation field.**
                }
            }
        },
}); 

这怎么可能?预先感谢

0 个答案:

没有答案