WhoBuilt

Building Reactive React Native apps with GraphQL

Feb 18, 2020· 18 min· 501 views·Watch on YouTube

Speaker

Wojciech Trocki, a Red Hat technologist working on React Native and GraphQL, explains data-driven mobile app patterns at the React Native Wrocław Meetup #2, hosted by Callstack.

Why mobile apps need resilient data flows

Trocki describes how backend latency and failures create loading states and other challenges in mobile apps. He says unreliable backends were identified as a cause of cross-platform project failures in a 2016 Gartner survey, and uses custom APIs as an example of integration work that varies from project to project.

Use GraphQL on the client

Trocki presents client-side GraphQL as a way to add typed queries and resolvers without rebuilding the server. Apollo Link REST can route a GraphQL query to a REST endpoint; local resolvers offer more control over formatting and can work with app state, REST, or the cache.

Make cache updates reactive

GraphQL clients use normalized caches to map returned data into entities that can be reused across views. Fetch policies control when the client reads from cache or requests the network, while optimistic responses let the UI render expected data before the server responds. Apollo watch queries can observe cache changes and update components as mutations, polling, or subscriptions refill the cache.

Generate the data layer

Trocki describes GraphQL CLI and Graphback as tools for generating typed code and CRUD queries from data models. The generated queries and server can be connected to a React Native client and a Node backend, reducing repeated setup so teams can focus on business logic. Schemas can also support generated forms and deployment templates.

Add live updates and synchronization

For more advanced setups, Trocki discusses GraphQL subscriptions and delta queries. Subscriptions provide real-time updates but typically need a reactive backend; Graphback can generate subscriptions that filter updates for specific entities. Delta queries combine with pagination to retrieve changes for entities currently in view while limiting data transfer.

Takeaways

  • Use client-side GraphQL to bring typed queries and cache patterns to existing REST APIs.
  • Choose fetch policies deliberately to balance cache reads and network requests.
  • Use optimistic responses when the client can predict the result of a mutation.
  • Generate repetitive CRUD queries from data models to reduce boilerplate.
  • Use subscriptions for live updates and delta queries to fetch changes efficiently across paginated data.

Mentioned in this talk

Search inside this talk

What was claimed 9

Related talks