微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

GraphQL Apollo Mutation String不能用传入的数组表示值

如何解决GraphQL Apollo Mutation String不能用传入的数组表示值

我在 Apollo 设置中有一个解析器 Mutation,代码如下

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字段的数组,所以有多个成功消息,电子邮件和消息

提前致谢

解决方法

必须做以下事情

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
      }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。