Skip to content

gs-ysingh/Contacts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Contacts Application

A full-stack contacts management application built with React, Relay, GraphQL, TypeScript, and Express.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ› οΈ Tech Stack

Frontend

  • React 18 - UI library
  • React Relay 20 - GraphQL client with normalized cache
  • TypeScript 5 - Type safety
  • Webpack 5 - Module bundler
  • CSS - Styling

Backend

  • 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

πŸ“‹ Prerequisites

  • Node.js (v16 or higher recommended)
  • npm or yarn
  • nvm (optional, for Node version management)

πŸš€ Getting Started

1. Install Dependencies

Backend

cd contacts-server
npm install

Frontend

cd contacts-client
npm install

2. Start the Backend Server

cd contacts-server
npm start

The server will start at:

  • REST API: http://localhost:4000
  • GraphQL endpoint: http://localhost:4000/graphql

3. Download GraphQL Schema (if needed)

If the schema needs to be updated:

cd contacts-client
npm run schema

4. Compile Relay Queries

Generate TypeScript types from GraphQL operations:

cd contacts-client
npm run relay

5. Start the Frontend

cd contacts-client
npm start

The client will start at http://localhost:3000

πŸ“ Available Scripts

Backend (contacts-server)

  • npm start - Start the Express + GraphQL server with ts-node

Frontend (contacts-client)

  • npm start - Start webpack dev server
  • npm run build - Build for production
  • npm run relay - Compile Relay queries and mutations
  • npm run schema - Download GraphQL schema from server

πŸ”§ Development Workflow

  1. Start the backend server first to ensure the GraphQL endpoint is available
  2. Download/update the schema if the backend schema changes
  3. Write GraphQL queries/mutations in the client
  4. Run Relay compiler to generate TypeScript types
  5. Start the frontend development server

🌐 API Endpoints

GraphQL

  • Endpoint: http://localhost:4000/graphql
  • Operations:
    • Queries: contacts (with pagination support)
    • Mutations: createContact, updateContact, deleteContact

REST API

  • Base URL: http://localhost:4000/contacts
  • Available as alternative to GraphQL

🎨 Features Implemented

  • βœ… 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

πŸ”‘ Key Concepts

Relay Modern

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

GraphQL Schema

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

πŸ“š Learn More

πŸ“„ License

ISC

πŸ‘€ Author

Yogesh Singh

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors