Today, we want to tell you about one of the most exciting initiatives we’re working on in the coming months, and how we’re collaborating with teams at companies like Airbnb, New York Times, Shopify, and Coursera to make it happen: Unifying Apollo Client across all JavaScript and native platforms.

Read on to hear about why we think a cross-platform client is important, the use case for teams like Airbnb, and how you can get involved.

Everyone’s on mobile

Two big trends are currently happening in web application development:

Mobile is now the dominant platform. In fact, phone and tablet usage surpassed desktop computer usage in 2016. React Native is becoming an increasingly popular choice among mobile developers due to its simplicity, cross-platform compatibility, and code push capabilities.

This means more and more companies are now building apps for at least three platforms: Web, iOS, and Android. Even though the different platforms conceptually represent just one application, they usually end up with three separate codebases. Having multiple implementations of the same thing always leads to inconsistencies. That’s frustrating for users, and it’s a waste of time and source of bugs for developers.

React Native helps with the frontend part of that question, since it lets you share knowledge, code, and perhaps even entire UI components across platforms. But most mobile apps today are still built with native technologies, and sharing UI code only solves half of the problem. The other half is data loading and management.

GraphQL: Perfect for cross-platform apps

The Apollo community wouldn’t exist without GraphQL. We owe a great deal of gratitude to its creators at Facebook, and people in the decades before who worked on technologies that inspired it. Here are three things that make GraphQL a game changer:

GraphQL gives frontend teams the power to develop new products without waiting for backend changes. GraphQL enables great performance and caching on mobile with very little effort thanks to its simple query language and type system. The emerging ecosystem and tooling around GraphQL makes developers vastly more productive.

Looking at these advantages, GraphQL is a no-brainer for most teams starting new projects, and more and more teams are incrementally adding it to their existing infrastructure. Because every team is different and there is no one-size-fits-all solution, we work hard to make Apollo technologies easy to start with while being as flexible and modular as possible. Compatibility and flexibility have been in our design principles from day one.

Improving existing apps with GraphQL

One of the best parts of GraphQL is that it can be added incrementally on top of any API or backend data source. Companies that are already at the scale and complexity where you really start to feel the pain of REST or an ad-hoc API can add GraphQL a little bit at a time.

React Native can be the same way — most companies are currently writing one codebase each for web, iOS, and Android, but you can incrementally move your mobile apps over to React to start duplicating less and less logic. That’s exactly what Airbnb are doing with their mobile apps, but as they have started sharing more of their business logic and components, they’ve found that it still makes sense to implement some infrastructure in native code. Leland Richardson from Airbnb explained this concept in his talk earlier this year at React Conf, “React Native in the Brown Field”.

A diagram of native vs. JavaScript code in React Native from Leland’s talk.

Leland also announced one of Airbnb’s newest open source efforts, Native Navigation — a navigation package for React Native that allows both JS and native code to interact with navigation, enabling applications where views are mixed between React and native code to still have smooth transitions between these views.

Airbnb’s use-case in a nutshell

Airbnb has a desktop web application that uses React and mobile apps for iOS and Android. Parts of these apps are starting to migrate to React Native, which lets them develop much faster and share more code between platforms. That means that in their apps, React Native and native code live side by side and need to integrate seamlessly. This integration needs to extend to data loading and caching as well: If a React Native view loads data into the GraphQL cache, they need that data to be available in native views and vice versa.

Imagine, for example, a native view that displays apartment listings in a city, along with a picture, the price, and some preview text. When you click on a listing, it takes you to a detail view written in React Native. The app already loaded enough data to show you a nice preview (picture, price, title) while fetching the complete listing, but it can only do that if the React Native view has access to the data loaded in the native view.

Airbnb’s GraphQL client requirements (slide from Ben Schwab’s presentation on Apollo Android)

The best way to make this possible is to share the same GraphQL data store between all platforms. If, in addition to sharing the same store, those platforms also provide the same semantics for data fetching and cache policy, it becomes much easier to migrate views between platforms as necessary. You can use native UI code in one component, and React Native in another, wherever it makes sense.