首页 > 解决方案 > Graphql 突变正在覆盖现有数据

问题描述

我正在使用 React.js 构建看板,而对于后端,我正在使用 Canonic 低代码平台

我的突变代码是

const UPDATE_SECTION = gql`
  mutation UpdateSection($_id: ID!, $label: String!, $cardId: [ID!]!) {
    updateSection(_id: $_id, input: { label: $label, cardId: $cardId }) {
      label
      _id
      cardId {
        title
      }
    }
  }
`;

而且,我正在像这样触发它

let createId = data.createCard._id;
updateSection({
            variables: {
              _id: item._id,
              label: item.label,
              cardId: `${createId}`,
            },
          });

我想要的是当cardId:${createId}作为突变发送到graphql时,它应该附加到现有数据,目前正在发生的是,上述代码正在用通过突变推送的最新数据替换“卡片”数组中的所有内容。

graphql 的类型定义如下所示

type Section {
_id: String
createdAt: Date
updatedAt: Date
title: String
label: String!
description: String
pos: Float
cardId: [Card]
}

有谁知道如何解决这个问题?谢谢你。

标签: javascriptreactjsgraphql

解决方案


推荐阅读