How advantys/react-native-react-query-demo works
Project Type & Purpose
• This is a full-stack demo application showcasing how to wire up a React Native (Expo) frontend with a Hasura-powered GraphQL backend. It highlights React Query features (caching, infinite queries, subscriptions, optimistic updates), GraphQL code generation, and local cache persistence.
High-Level File Structure Analysis
• Top-level “hasura/” folder: Docker Compose setup, metadata, and SQL migrations for Hasura + Postgres.
• App root: Expo config (app.json/app.config.ts), App.tsx.
• src/: split into components/, screens/, navigation/, hooks/, providers/, services/, styles/.
• Testing infra under __tests__, src/**/*/__tests__, and src/test/.
• Config files: .graphqlrc.yml, babel.config.js, jest.config.js, TypeScript config.
Key README Insights
• Frontend: Expo + TypeScript, React Query + graphql-request + GraphQL code generator, React Native Paper UI, React Navigation, Suspense/Error boundaries.
• Backend: Hasura + Postgres, run via Docker Compose, with metadata & migrations auto-applied.
• Demonstrates queries, infinite scrolling, subscriptions, cache persistence (AsyncStorage), optimistic updates, and various auto-refetch triggers.
Main Components & Interactions
a. Frontend Layers
• UI Layer: React Native screens (MoviesList, MovieDetails), shared components/.
• Navigation Layer: React Navigation (src/navigation/MainStack).
• State & Data Layer:
• React Query client (in providers/GraphQLClientProvider.tsx) handles queries, mutations, subscriptions.
• Persistence: React Query’s AsyncStorage persister (services/persister).
• Network & Theme Contexts: NetworkStatusProvider, ThemeModeProvider.
• GraphQL Codegen: generates hooks/types under src/graphql + custom hooks in src/hooks/.
b. Backend
• Hasura GraphQL Engine container, exposes HTTP & WebSocket endpoints (/v1/graphql).
• Postgres container storing movies tables.
• Migrations & Metadata: define tables, seed data, actions, cron triggers, allow-list, subscriptions config.
c. Data Flow
1. User taps UI → React Query hook calls graphql-request client
2. HTTP request to Hasura → Postgres → JSON response
3. React Query caches result → UI renders, persists to AsyncStorage
4. On subscriptions, WebSocket connection kept open → real-time updates flow back into React Query cache
Architectural Patterns & Principles
• Single Responsibility: UI vs data-fetching vs persistence vs context providers.
• Hook-first: Custom hooks (useInfiniteMovies, useMovieDetails, etc.) encapsulate queries/mutations.
• Context Providers: centralize client, network, theme state.
• Code Generation: ensures type safety between frontend and GraphQL schema.
• Containerization: backend stacks run in isolated Docker services.