Search code examples
mongodbreact-nativemongooserealmapollo-server

Realm with Apollo GraphQl API


I am looking to build a React Native app and I'd like to use Realm so it can be used offline and then synced once the connection is restored. However, I'd like to use the same API I use for the web app built on NextJs, powered by a serverless (AWS Lambda) Apollo GraphQl API built using MongoDB and Mongoose. It'll be my first time using Realm and I'm wondering if I can use it with this same API. Some additional questions:

  • Are there downsides to this approach?
  • Would it be better to create a Realm database?
  • Would that be more expensive?

When I search online all I can find are guides showing how to use Realm and Apollo Client.


Solution

  • If you have an existing API connected with a regular MongoDB database, like in my case, you can use Atlas Device Sync. As they put it, it is "Realm in the Front, MongoDB in the Back". It creates a bridge between your existing MongoDB database and Realm. From what I understood, it kind of makes a copy of your database on Realm and the bridge makes sure both are always updated with the same data.

    If you make changes to MongoDB, it'll update the Realm db that feeds the mobile app, and vice-versa.

    The downside is that it is an extra cost, so if you're starting from scratch, it's probably better to create a Realm db and use that one.