我一直试图在 Prisma 网站上找到一些关于此的文档,但老实说,在那里找到非常详细的用例有点困难,尤其是当问题像这个一样难以描述时。
我有这样的情况,我的前端向createPosting
我的 GraphQL-Yoga 服务器上发送一个带有字段的突变请求positionTitle, employmentType, description, requirements, customId, expiresAt
(我已经彻底测试过它是否按预期工作)。我想createdAt
在 Prisma 服务上创建节点之前添加一个字段。
在我的 GraphQL-Yoga 服务器中,我有一个 datamodel.graphql,其中包括以下内容:
type Posting {
id: ID! @unique
customId: String! @unique
offeredBy: Employer!
postingTitle: String!
positionTitle: String!
employmentType: EmploymentType!
status: PostingStatus!
description: String
requirements: String
applications: [Application!]!
createdAt: DateTime!
expiresAt: DateTime!
}
我的 schema.graphql 在 Mutations 下有这个:
createPosting(postingTitle: String!,
positionTitle: String!,
employmentType: String!,
description: String!,
requirements: String!,
customId: String!,
expiresAt: DateTime!,
status: PostingStatus): Posting!
最后在我的 createPosting 解析器中,我尝试像这样改变 Prisma 后端:
const result = await context.prisma.mutation.createPosting({
data: {
offeredBy: { connect: { name: context.req.name} },
postingTitle: args.postingTitle,
positionTitle: args.positionTitle,
employmentType: args.employmentType,
description: args.description,
requirements: args.requirements,
customId: args.customId,
createdAt: new Date().toISOString(),
expiresAt: expiresAt,
status: args.status || 'UPCOMING'
}
})
当我尝试从前端运行它时,我在服务器上收到以下错误:
Error: Variable '$_v0_data' expected value of type 'PostingCreateInput!' but got: {"customId":"dwa","postingTitle":"da","positionTitle":"da","employmentType":"PART_TIME","status":"UPCOMING","description":"dada","requirements":"dadada","expiresAt":"2018-09-27T00:00:00.000Z","createdAt":"2018-09-04T20:29:10.745Z","offeredBy":{"connect":{"name":"NSB"}}}. Reason: 'createdAt' Field 'createdAt' is not defined in the input type 'PostingCreateInput'.
从这个错误消息中,我假设我的 Prisma 服务由于某种原因不知道 createdAt,因为我最近添加了这个字段,但是当我在 Prisma 主机上的 GraphQL 操场中检查类型 Posting 和 PostingCreateInput 时,我发现字段 createdAt !在这两个地方。
我尝试删除生成的 prisma.graphql 并再次部署新文件,但这不起作用。当我检查 prisma.graphql 时,PostingCreateInput 确实错过了 createdAt 字段,即使 Prisma 服务器似乎有它。
如果有人可以为我指出错误的正确方向,或者让我更好地了解如何设置应该存储在数据库中但在我的瑜伽服务器中而不是在前端创建的变量,我会非常感激:)
虽然这个问题可能看起来有点具体,但我相信在创建节点之前应该可以在服务器上为字段创建数据的想法,但目前我正在努力思考如何去做。
TLDR;createdAt:DateTime
在向我的 Prisma 服务发送创建请求之前,想要在解析器上的 GraphQL-Yoga 服务器上创建一个字段。