vuejs / apollo

🚀 Apollo/GraphQL integration for VueJS
http://apollo.vuejs.org
MIT License
6.01k stars 521 forks source link

[BUG] Wicked! The Array in data from graphql response is the same. #434

Closed JimmyLv closed 5 years ago

JimmyLv commented 5 years ago

image

query statements and Schema:

query orderProductsById($orderId: String!) {
  orderDetail(orderId: $orderId) {
    orderProducts {
      amount
      attribute
      count
      customReqDesc
      customReqImage
      groupId
      id  <----------------- can't be null
      image
      isGift
      model
      returnableCount
      sellPrice
      skuId
      skuName
    }
  }
}

Actually the orderProducts is an array and these items should has different values.

orderProducts: [OrderProduct]!

the apollo query option in Vue components:

apollo: {
    orderProducts: {
      query: orderProductsById,
      variables() {
        return {
          orderId: this.orderId,
        }
      },
      update: data =>
        data.orderDetail.orderProducts.map(p => ({
          name: p.skuName,
          description: p.customReqDesc,
          skuCode: p.skuId,
          saleProperty: p.attribute,
          previewImage: p.image,
          quantity: p.count,
          price: p.amount,
        })),
      result({ data, loading, networkStatus }) {
        console.log('We got some result!', {
          data,
          loading,
          networkStatus,
        })
      },
    },
}
JimmyLv commented 5 years ago

Fixed by removed the null id, the idea of solution here: https://github.com/Akryum/vue-apollo/issues/373