We are building new GraphQL api using apollo server 2. Most of our data live in MongoDB and we are able to access easily with mongoose. But there are many data points which exists in our mySQL database. How can we connect to multiple database in GraphQL API to connect to mongodb and mySQL ?
Apollo server is not concerned with how many databases you use, so you should be able to setup as many database connections as your node process allows.
You will have to define resolving logic, probably utilizing dataloaders, where some fields are fetching data from the SQL database and some fields fetch data from the mongoDB.
Another strategy you might want to consider is to create separate (micro)services for these databases. Your GraphQL server would then fetch its data from these services, and dropping the database handling altogether.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With