【发布时间】:2021-09-20 03:26:23
【问题描述】:
我在 Apollo 设置中有一个解析器突变,代码如下
Mutation: {
sendInvite: async (parent, args: MutationSendInviteArgs, context) => {
console.log('args email >>>>> ', args);
// create invite code
// add to invite container
// send email with invite
const emailSent = true;
const emailMessage = 'sent invite';
// is the record added by the api connector? ---> look into this
return {
success: emailSent,
message: emailMessage,
email:args.email
}
}
}
我在操场上运行以下突变
mutation{
sendInvite(email:["anders@email.org","anders@email.com"]){
email
success
message
}
}
我得到以下响应
"message": "String cannot represent value: [\"anders@email.org\", \"anders@email.com\"]",
哦,这是我的变异模式
type Mutation {
sendInvite(email: [String]): Invite
}
type Invite {
email: String!
success: Boolean!
message: String!
}
如何返回电子邮件,使其成为可以映射的数组?
其实我想返回 sendInvite 字段的数组,所以有多个成功消息、电子邮件和消息
提前感谢
【问题讨论】:
-
一如既往...使用变量,而不是硬编码值...graphql.org/learn/queries/#variables
-
谢谢,我还得改变其他的东西,所以有一个解决方案
标签: javascript graphql apollo resolver