A full-stack contacts management application built with React, Relay, GraphQL, TypeScript, and Express.
- GraphQL API with Relay-compliant schema
- React 18 with Relay for efficient data fetching
- TypeScript for type safety across the stack
- Real-time UI with optimistic updates
- CRUD Operations for contact management
- RESTful API alongside GraphQL endpoints
- Webpack Dev Server with hot module replacement
Contacts/
βββ contacts-client/ # React + Relay frontend
β βββ src/
β β βββ App.tsx # Main application component
β β βββ index.tsx # Entry point
β β βββ styles.css # Global styles
β β βββ components/ # React components
β β β βββ ContactDetail.tsx
β β β βββ ContactForm.tsx
β β β βββ ContactListItem.tsx
β β βββ graphql/ # GraphQL queries and mutations
β β β βββ ContactQueries.ts
β β β βββ ContactMutations.ts
β β β βββ __generated__/ # Relay compiled artifacts
β β βββ relay/ # Relay environment setup
β β β βββ Environment.ts
β β βββ services/ # Service layer
β β βββ contactService.ts
β βββ public/
β β βββ index.html
β βββ package.json
β βββ relay.config.json # Relay compiler configuration
β βββ schema.graphql # GraphQL schema (downloaded from server)
β βββ tsconfig.json
β βββ webpack.config.js
β
βββ contacts-server/ # Express + GraphQL backend
βββ server.ts # Main server file
βββ controllers/ # Business logic
β βββ contactController.ts
βββ graphql/ # GraphQL schema definition
β βββ schema.ts
βββ middlewares/ # Express middlewares
β βββ errorHandler.ts
βββ routes/ # REST API routes
β βββ contactRoutes.ts
βββ package.json
βββ schema.graphql # GraphQL schema
βββ tsconfig.json
- React 18 - UI library
- React Relay 20 - GraphQL client with normalized cache
- TypeScript 5 - Type safety
- Webpack 5 - Module bundler
- CSS - Styling
- Express.js - Web framework
- Apollo Server 3 - GraphQL server
- GraphQL - Query language
- graphql-relay - Relay specification utilities
- TypeScript 5 - Type safety
- ts-node - TypeScript execution
- Node.js (v16 or higher recommended)
- npm or yarn
- nvm (optional, for Node version management)
cd contacts-server
npm installcd contacts-client
npm installcd contacts-server
npm startThe server will start at:
- REST API:
http://localhost:4000 - GraphQL endpoint:
http://localhost:4000/graphql
If the schema needs to be updated:
cd contacts-client
npm run schemaGenerate TypeScript types from GraphQL operations:
cd contacts-client
npm run relaycd contacts-client
npm startThe client will start at http://localhost:3000
npm start- Start the Express + GraphQL server with ts-node
npm start- Start webpack dev servernpm run build- Build for productionnpm run relay- Compile Relay queries and mutationsnpm run schema- Download GraphQL schema from server
- Start the backend server first to ensure the GraphQL endpoint is available
- Download/update the schema if the backend schema changes
- Write GraphQL queries/mutations in the client
- Run Relay compiler to generate TypeScript types
- Start the frontend development server
- Endpoint:
http://localhost:4000/graphql - Operations:
- Queries:
contacts(with pagination support) - Mutations:
createContact,updateContact,deleteContact
- Queries:
- Base URL:
http://localhost:4000/contacts - Available as alternative to GraphQL
- β Contact list with Relay pagination
- β Create new contacts
- β Update existing contacts
- β Delete contacts
- β Optimistic UI updates with Relay
- β Connection-based mutations (@appendEdge, @deleteEdge)
- β TypeScript type safety throughout
- β GraphQL schema introspection
- β Error handling
This project uses Relay Modern with:
- Fragment Colocation - Components declare their data requirements
- Automatic Batching - Efficient query batching
- Normalized Cache - Automatic cache updates
- Optimistic Updates - Instant UI feedback
- Connection Protocol - Cursor-based pagination
The schema follows Relay specifications with:
- Node interface for global object identification
- Connection pattern for pagination
- Input types for mutations
- Edge and Node types for list queries
- React Relay Documentation
- GraphQL Documentation
- Apollo Server Documentation
- TypeScript Documentation
ISC
Yogesh Singh