graphql apollo变异字符串不能表示传入数组的值

093gszye  于 2021-09-23  发布在  Java
关注(0)|答案(1)|浏览(390)

我在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!
}

如何返回电子邮件,使其成为可以Map的阵列?
实际上我想返回sendinvite字段的数组,所以有多条成功消息、电子邮件和消息
提前谢谢

mcdcgff0

mcdcgff01#

我必须做以下几件事

type Invite {
  InviteArray: [InviteArray!]
}

type InviteArray {
  email: String!
  verified: Boolean!
  success: Boolean!
  message: String!
}
let items = args.email.map((item) =>{
        return {email: item}
      })
      console.log("test >>>> ", test)
      return {
        InviteArray:items
      }

相关问题