Altair Todescatto F
Altair Todescatto F

Reputation: 133

Graphcool Mutation changing fields that are not supose to change

i'm having a problem with mutation using graphcool and apollo client, on my application, i had a soft delete type of funcionality, where the user clicks on delete and the app runs a mutation to change only one field on database named deletedAt, with came null for default, but when had some data on it, its only got to another tab on my app. The problem is, the mutation get the current time when the button was clicked, apply that, field but set all other to null, causing a bunch of problems on the rest of my app. But, i dont see where the problem would be, someone can help me?

here i call my function

  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)
  }

and here is my mutation

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",
  }
);

Upvotes: 0

Views: 37

Answers (1)

Rigin Oommen
Rigin Oommen

Reputation: 3366

Try to deep clone the response from your server at services

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;
  });}

Through deep cloning, you can resolve this

Upvotes: 0

Related Questions