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