我在更新解析器中的数组时遇到了一些问题。我正在与typescript
.
描述
我在datamodel.graphql
for 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
我给出的评论。
感谢您阅读到目前为止。