EQuimper / twitter-clone-with-graphql-reactnative

164 stars 71 forks source link

Optimistic UI #51

Closed gHashTag closed 6 years ago

gHashTag commented 6 years ago

Why do I get this error and how do I fix it? 2017-12-04 0 02 59

mutate

  _onMasterCreate = async () => {
    const { name, profession, img, imgSmall, info } = this.state
    await this.props.mutate({
      variables: {
        name,
        profession,
        img,
        imgSmall,
        info
      },
      optimisticResponse: {
        __typename: 'Mutation',
        createTweet: {
          __typename: 'Tweet',
          name,
          profession,
          img,
          imgSmall,
          info,
          _id: Math.round(Math.random() * -1000000)
        }
      },
      update: (store, { data: { createMaster } }) => {
        const data = store.readQuery({ query: GET_STUDIO_MASTERS })
        console.log('date', data)
        if (!data.getStudioMasters.find(t => t._id === createMaster._id)) {
          store.writeQuery({ query: GET_STUDIO_MASTERS, data: { getStudioMasters: [{ ...createMaster }, ...data.getStudioMasters] } })
        }
      }
    })

    Keyboard.dismiss()
    this.props.navigation.goBack(null)
  }

createMaster

export default gql`
  mutation createMaster($name: String!, $profession: String!, $img: String!, $imgSmall: String!, $info: String!) {
    createMaster( name: $name, profession: $profession, img: $img, imgSmall: $imgSmall, info: $info) {
      _id
      name
      profession
      img
      imgSmall
      info
    }
  }
`

getStudioMasters

export default gql`
{
  getStudioMasters {
    _id
    name
    profession
    img
    imgSmall
    info
  }
}
`
gHashTag commented 6 years ago

Sorry =) Fix type name createMaster