FaridSafi/react-native-gifted-chat

Can I use mysql to save the message?

tranvannhat opened this issue ยท 6 comments

Issue Description

Can I use mysql to save the message?
Can I customize the message object? Compulsory use of your format?

Yes you can use mysql to save messages.
Use the text generated by send button to insert into your mysql.
Also you can use any format just map it when populating the chats.

Hi, I add this question to readme/questions ;)

how do you connect giftedChat to mysql

thanks bro. Closed

a graphql example would be awesome

a graphql example would be awesome

This has worked for me (you have to use withApollo HOC and use prop 'client'):

....
const onSend = (newMessages: IMessage[] = []) => {
    newMessages.forEach(message => {
      client
        .mutate({
          variables: {
            ...
          },
          mutation: YOUR_MUTATION,
        })

        .then(response => {
          setMessagesHistory(prevMessages =>
            GiftedChat.append(prevMessages, message)
          )
        })
        .catch(error => {
          // error logic
        })
    })
  }
....
 return (

        <GiftedChat
          messages={yourMessagesFromState}
          onSend={messages => onSend(messages)}
          .....
        />
 )