dqef7931 2018-10-08 07:41
浏览 132

尝试使用graphql发送输入对象时,该对象的属性之一接收到空值

I'm using go on the server side with graphql, and angular6 with apollo on client side.

I'm trying to send the following object in mutation:

{
  "deliveryId": 1,
  "products": [{
    "id": 3,
    "quantity": 1
  }],
  "payment": {
    "name": "kfir ozer",
    "number": "4580 0307 6696 9445",
    "expiry": "02 / 122",
    "cvc": "332"
  }
}

I paste this object to the following function to send it to the server:

addOrderInfo(order) {
  return this.apollo.mutate({
    mutation: gql `
      mutation AddOrderInfo($order: Order!) {
        addOrderInfo(order: $order) {
          id
        }
      }
    `,
    variables: {
      order
    }
  });
}

and now the server side..

this is how I configure the relevant types:

cartProduct: = graphql.NewInputObject(
  graphql.InputObjectConfig {
    Name: "CartProduct",
    Fields: graphql.InputObjectConfigFieldMap {
      "id": & graphql.InputObjectFieldConfig {
        Type: graphql.Int,
      },
      "quantity": & graphql.InputObjectFieldConfig {
        Type: graphql.Int,
      },
    },
  },
)
payment: = graphql.NewInputObject(
  graphql.InputObjectConfig {
    Name: "CreditCardPayment",
    Fields: graphql.InputObjectConfigFieldMap {
      "name": & graphql.InputObjectFieldConfig {
        Type: graphql.String,
      },
      "number": & graphql.InputObjectFieldConfig {
        Type: graphql.String,
      },
      "expiry": & graphql.InputObjectFieldConfig {
        Type: graphql.String,
      },
      "cvc": & graphql.InputObjectFieldConfig {
        Type: graphql.String,
      },
    },
  },
)
order: = graphql.NewInputObject(
  graphql.InputObjectConfig {
    Name: "Order",
    Fields: graphql.InputObjectConfigFieldMap {
      "deliveryId": & graphql.InputObjectFieldConfig {
        Type: graphql.Int,
      },
      "payment": & graphql.InputObjectFieldConfig {
        Type: payment,
      },
      "products": & graphql.InputObjectFieldConfig {
        Type: graphql.NewList(cartProduct),
      },
    },
  },
)

and this is how I set the mutation:

RootMutation: = graphql.NewObject(graphql.ObjectConfig {
  Name: "Mutation",
  Fields: graphql.Fields {
      "addOrderInfo": & graphql.Field {
        Type: ContactUsType,
        Args: graphql.FieldConfigArgument {
          "order": & graphql.ArgumentConfig {
            Type: order,
          },
        },
        Resolve: func(params graphql.ResolveParams)(interface {}, error) {
          ### here I created a breakpoint with intellij
          ### and noticed that the payment related values
          ### are empty strings
        },
      },
    }
    ...
  }
}

and on the server side... the params returns the proper data but the payment property contains the expiry, cvc, name and number properties but they are an empty string instead of the actual values.

what am I missing?

thanks

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集