Moh*_*ajr 5 node.js express graphql graphql-js prisma
我有这个简单的突变,效果很好
type Mutation {
addJob(
url: String!
description: String!
position: String!
company: String!
date: DateTime!
tags: [String!]!
): Job
}
Run Code Online (Sandbox Code Playgroud)
突变解析器
function addJob(parent, args, context, info) {
console.log('Tags => ', args.tags)
// const userId = getUserId(context)
return context.db.mutation.createJob(
{
data: {
position: args.position,
componay: args.company,
date: args.date,
url: args.url,
description: args.description,
tags: args.tags
}
},
info
)
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我尝试放置一组字符串(标签),如您在上面看到的那样,II 无法使其正常工作,并且出现此错误
Error: Variable "$_v0_data" got invalid value { ... , tags: ["devops", "aws"] }; Field "0" is not defined by type JobCreatetagsInput at value.tags.
Run Code Online (Sandbox Code Playgroud)
如果我为突变中的标签分配了一个空数组,则没有问题,但是,例如,如果我放置一个字符串值 ["DevOps"],则会出现错误
问题显然出在解析器函数中,正如我在这里发现的那样,我必须在 set 参数中的对象内分配标签列表,如下面的代码
function addJob(parent, args, context, info) {
return context.db.mutation.createJob(
{
data: {
position: args.position,
componay: args.company,
date: args.date,
url: args.url,
description: args.description,
tags: { set: args.tags }
}
},
info
)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |