EQuimper / twitter-clone-with-graphql-reactnative

164 stars 71 forks source link

Part:14 / Optimistic UI #48

Closed gHashTag closed 6 years ago

gHashTag commented 6 years ago

The mutation was created, but I'm trying to make it customize Optimistic UI but the error crashes

Missing field typename in { "record": { "typename": "Master", "studioID": "5a1819e8504bd80f145228c3", "name": YellowBox.js:76 Missing field _id in { "record": { "__typename": "Master", "studioID": "5a1819e8504bd80f145228c3", "name":

  _onMasterCreate = async () => {
    const { studioID, name, profession, img, imgSmall, info } = this.state

    await this.props.mutate({
      variables: {
        record: {
          studioID,
          name,
          profession,
          img,
          imgSmall,
          info
        }
      },
      optimisticResponse: {
        __typename: 'Mutation',
        masterCreate: {
          record: {
            __typename: 'Master',
            studioID,
            name,
            profession,
            img,
            imgSmall,
            info,
            _id: Math.round(Math.random() * -1000000)
          }
        }
      },
      update: (store, { data: { masterCreate } }) => {
        const data = store.readQuery({ query: MASTER_MANY })
        if (!data.masterMany.find(t => t._id === masterCreate._id)) {
          store.writeQuery({ query: MASTER_MANY, data: { masterMany: [{ ...masterCreate }, ...data.masterMany] } })
        }
      }
    })
mutation masterCreate($record: CreateOneMasterInput!) {
    masterCreate(record: $record
    ) {
    record {
      studioID
      name
      profession
      img
      imgSmall
      info
      _id
    }
  }
  }

What's wrong?

gHashTag commented 6 years ago

It was a bug related to the specifics of the library https://github.com/nodkz/graphql-compose