【发布时间】:2019-01-25 16:40:52
【问题描述】:
我在更新解析器中的数组时遇到了一些问题。我正在使用typescript 构建。
说明
我在datamodel.graphql 中有Prisma:
type Service @model {
id: ID! @unique
title: String
content: String
createdAt: DateTime!
updatedAt: DateTime!
comments: [Comment!]! // Line to be seen here
author: User!
offer: Offer
isPublished: Boolean! @default(value: "false")
type: [ServiceType!]!
}
type Comment @model {
id: ID! @unique
author: User! @relation(name: "WRITER")
service: Service!
message: String!
}
Prisma 连接到GraphQl 服务器,在这个服务器中,我定义了突变:
commentService(id: String!, comment: String!): Service!
现在是为给定突变实现解析器的时候了,我正在这样做:
async commentService(parent, {id, comment}, ctx: Context, info) {
const userId = getUserId(ctx);
const service = await ctx.db.query.service({
where: {id}
});
if (!service) {
throw new Error(`Service not found or you're not the author`)
}
const userComment = await ctx.db.mutation.createComment({
data: {
message: comment,
service: {
connect: {id}
},
author: {
connect: {id:userId}
},
}
});
return ctx.db.mutation.updateService({
where: {id},
data: {
comments: {
connect: {id: userComment.id}
}
}
})
}
问题:
查询游乐场时我收到的唯一信息是null,而不是我给出的评论。
感谢您到目前为止的阅读。
【问题讨论】:
标签: javascript typescript graphql prisma