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

How to use Realm DB with Relay, React Native? #1059

Closed
wieseljonas opened this issue Apr 18, 2016 · 2 comments
Closed

How to use Realm DB with Relay, React Native? #1059

wieseljonas opened this issue Apr 18, 2016 · 2 comments
Labels

Comments

@wieseljonas
Copy link

I have a native app which works well with Realm DB. I use the realm DB as "fallback" when no network connection is available.

I've started rewriting the app with react-native. I wondered how could I achieve something similar with Relay, GraphQL and React-Native. I'm to use something an alternative for the local DB like lokijs.

Do I need to write a local GraphQL server on the device which connect to Realm?

I'm really not sure how to make this work and which architecture to go for, thank you in advance.

@NevilleS
Copy link
Contributor

Think of GraphQL as a "wrapper" for your database (e.g. Realm). In order to store GraphQL data, you'll need some kind of persistence layer for it. So yes, you'll need a GraphQL server.

Relay doesn't really have a "solution" for doing things like local storage. You could implement your own network layer that switches between a remote and local GraphQL server, if that works for you - maybe Realm can do something to help sync those systems back together, I'm not sure? But you'll need to also put a GraphQL server in front of the local Realm db - see graphql-js for that.

TL;DR: yes, you could probably do this, and you'll need a GraphQL server. No, it's not going to be easy. If you really want Realm and offline persistence, I'd probably recommend using something other than Relay for the data - I don't see these two paradigms playing super well together...

@wincent
Copy link
Contributor

wincent commented Apr 19, 2016

Thanks for the question, @wieseljonas. I think @NevilleS's answer is on point.

Right now you can do pretty much anything via a network layer, but depending on the complexity of your integration it may be a non-trivial amount of work.

We've extensively discussed making it easier to use Relay for this use case, but we're not actively working on it right now. We are, however, taking steps towards making Relay more modular (splitting the low-level core from the high-level React integration); this will make building arbitrary integrations more straightforward. We're definitely open to facilitating community contributions on these fronts if you are interested in helping out.

See #114 and #559 for more context on local data and the core split, respectively.

@wincent wincent closed this as completed Apr 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants