Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use mysql to save the message? #738

Closed
tranvannhat opened this issue Feb 1, 2018 · 6 comments
Closed

Can I use mysql to save the message? #738

tranvannhat opened this issue Feb 1, 2018 · 6 comments

Comments

@tranvannhat
Copy link

Issue Description

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

@xpsdeset
Copy link

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.

@xcarpentier
Copy link
Collaborator

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

@Simwenya
Copy link

Simwenya commented May 6, 2018

how do you connect giftedChat to mysql

@tranvannhat
Copy link
Author

thanks bro. Closed

@LesedimotaungNC
Copy link

LesedimotaungNC commented Dec 10, 2018

a graphql example would be awesome

@josemiguelo
Copy link

josemiguelo commented Jul 11, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants