如何解决Apollo Server GraphQL Mutation从knex.js查询返回空
我试图使用Apollo Server(GraphQL)的变异逻辑取回刚插入的数据库行。这是我的突变代码:
Mutation: {
newPost: async (_,{ post_user_id,post_text,post_parent },{ dataSources }) => {
let id = await client.into("posts").insert({ post_text,post_user_id,post_parent });
console.log(`newPostID=${id}`);
// Not sure why this is returning all nulls?
return client.from("posts").where({ post_id: id });
}
},
...及其模式:
type Mutation {
newPost(post_text: String!,post_user_id: Int!,post_parent: Int): Post!
}
type Post {
post_id: ID!,post_created: Float,post_user: User,post_text: String,post_object_set: ObjectSet,post_edited: Float,post_views: Float,post_upvotes: Float,post_downvotes: Float,post_parent: Post
}
为发布定义的列与数据库表相同。
此突变查询:
mutation {
newPost(post_text: "Hi",post_user_id: 1) {
post_created
post_text
post_edited
post_views
post_upvotes
post_downvotes
}
}
返回:
{
"data": {
"newPost": {
"post_created": null,"post_text": null,"post_edited": null,"post_views": null,"post_upvotes": null,"post_downvotes": null
}
}
}
我想念什么?我引用的是阿波罗文件:https://www.apollographql.com/docs/tutorial/mutation-resolvers/
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。