无需更改的Graphcool变异更改字段

时间:2019-03-25 13:45:04

标签: reactjs graphql graphcool

我在使用graphcool和apollo客户端进行突变时遇到问题,在我的应用程序上,我使用了软删除功能,在该函数中,用户单击delete,然后应用程序运行突变以仅更改名为DeletedAt,默认情况下为null,但是当其中包含一些数据时,它仅到达我应用程序的另一个选项卡。问题是,该突变获得了单击按钮时的当前时间,将其应用于字段,但将所有其他字段设置为null,这在我的应用程序的其余部分上引起了很多问题。但是,我不知道问题出在哪里,有人可以帮助我吗?

在这里我调用函数

  const handleConfirm = async () => {
    setDeleting(true)

    try {
     await updateEvent({ variables: { id: eventId, deletedAt: moment()}})
      await dataList.refetch()
     sendNotification(t({ id: 'deleted-event'}))
    } catch (err) {
      sendNotification(t({ id: 'failed-delete-event'}), 'error', err)
    }

    setDeleting(false)
    setOpen(false)
  }

这是我的突变

export default graphql(
  gql`
    mutation updateEvent(
      $id: ID!
      $canceled: Boolean
      $offreId: ID
      $vehiclesIds: [ID!]
      $employeesIds: [ID!]
      $deletedAt: DateTime
    ) {
      updateEvent(
        id: $id
        canceled: $canceled
        offreId: $offreId
        vehiclesIds: $vehiclesIds
        employeesIds: $employeesIds
        deletedAt: $deletedAt
      ) {
        id
        canceled
        vehicles {
          id
          name
          plate
        }
        eventStuffs {
          id
          quantity
          stuff {
            id
            name
          }
        }
        deletedAt
        offre {
          id
          showTotalBudgetsPdf
          rev
          version
          name
          maxPersons
          minPersons
          startTime
          endTime
          status
          gmtOffset
          client {
            id
            name
            email
            phone
            address
            clientContacts {
              id
              name
              email
            }
          }
          clientContact {
            id
            name
            email
            mobilePhone
            phoneNumber
          }
          language
          eventType {
            id
            name
          }
          place {
            id
            name
          }
          address
          city
          postalCode
          sectionItems {
            content
            h
            i
            id
            isDraggable
            isResizable
            maxH
            maxW
            minH
            minW
            moved
            static
            type
            w
            x
            y
            menu {
              id
              name
              price
              people
              startDate
              endDate
              hasItemsCold
              hasItemsHot
              hasItemsZHot
              hasItemsZCold
              hasItemsDessert
              kitchenNotes
              comment
              sections {
                id
                name
                showPdf
                itemProposals {
                  id
                  status
                  plats {
                    id
                    platTranslations {
                      id
                      name
                      language
                      description
                      internalDescription
                    }
                  }
                }
              }
            }
          }
          budgetLines {
            id
            description
            quantity
            unitPrice
            value
            total
            tax {
              id
              name
              value
            }
          }
          employeeEstimations {
            id
            estimatedEndAt
            estimatedStartAt
            number
            pricePerHour
            total
            job {
              id
              name
            }
          }
        }
      }
    }
  `,
  {
    name: "updateEvent",
  }
);

1 个答案:

答案 0 :(得分:0)

尝试从服务中的服务器深度克隆响应

getdatabyTeam(teamID: string): Promise<ITeam[]> {
return this.apollo.watchQuery<TeamResponse | any>({ variables: { _id: teamID }, query: listTeamID })
  .result()
  .then(response => _.cloneDeep(response.data.listTeamID))
  .catch(err => {
    console.log(err);
    return err;
  });}

通过深度克隆,您可以解决此问题