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

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

我在apollo设置中有一个解析器突变,代码如下

  1. Mutation: {
  2. sendInvite: async (parent, args: MutationSendInviteArgs, context) => {
  3. console.log('args email >>>>> ', args);
  4. // create invite code
  5. // add to invite container
  6. // send email with invite
  7. const emailSent = true;
  8. const emailMessage = 'sent invite';
  9. // is the record added by the api connector? ---> look into this
  10. return {
  11. success: emailSent,
  12. message: emailMessage,
  13. email:args.email
  14. }
  15. }
  16. }

我在操场上跑步

  1. mutation{
  2. sendInvite(email:["anders@email.org","anders@email.com"]){
  3. email
  4. success
  5. message
  6. }
  7. }

我得到以下回应

  1. "message": "String cannot represent value: [\"anders@email.org\", \"anders@email.com\"]",

哦,这是我的突变模式

  1. type Mutation {
  2. sendInvite(email: [String]): Invite
  3. }
  1. type Invite {
  2. email: String!
  3. success: Boolean!
  4. message: String!
  5. }

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

mcdcgff0

mcdcgff01#

我必须做以下几件事

  1. type Invite {
  2. InviteArray: [InviteArray!]
  3. }
  4. type InviteArray {
  5. email: String!
  6. verified: Boolean!
  7. success: Boolean!
  8. message: String!
  9. }
  1. let items = args.email.map((item) =>{
  2. return {email: item}
  3. })
  4. console.log("test >>>> ", test)
  5. return {
  6. InviteArray:items
  7. }
展开查看全部

相关问题