user-graphql-server-mocked
v1.6.0
Published
GraphQL server with mocked data using Yoga
Downloads
124
Readme
User Management GraphQL Server (Mocked)
A fully functional GraphQL server with mocked data built using GraphQL Yoga and TypeScript. This server implements a comprehensive user management schema with authentication, profiles, and various social login methods.
Features
- Full GraphQL schema implementation based on introspection schema
- All resolvers return realistic mocked data
- Support for Queries, Mutations, and Subscriptions
- GraphiQL interface for testing
- TypeScript for type safety
- Hot reload during development
Schema Overview
The server implements a comprehensive user management system with:
- User authentication (password, OAuth, Web3 wallets, Telegram)
- Profile management
- 2FA (OTP and SMS)
- Email verification
- Password reset
- Social profiles (Steam, Facebook, Twitter)
- Country and localization support
- Device management
- Session management
Getting Started
Prerequisites
- Node.js (v18 or higher)
- pnpm (or npm/yarn)
Installation
pnpm installDevelopment
Start the development server with hot reload:
pnpm run devThe server will start at http://localhost:5000/graphql
Create admin users
npm run cli create-admin -- -e <email> -p <password> -n <name>Change admin password
npm run cli change-admin-password -- -e <email> -p <new_password>Build
Compile TypeScript to JavaScript:
pnpm run buildProduction
Run the compiled server:
pnpm startUsage
GraphiQL Interface
Visit http://localhost:5000/graphql in your browser to access the enhanced interactive GraphiQL interface where you can:
- Explore the schema - Browse all available types, queries, mutations, and subscriptions
- Test queries and mutations - Execute operations with syntax highlighting and auto-completion
- View documentation - Built-in documentation explorer for all GraphQL types and fields
- Run subscriptions - Test real-time subscription operations
- Pre-loaded examples - Ready-to-run example queries and mutations on page load
- Modern UI - Clean, responsive interface with custom styling
The GraphiQL interface comes pre-loaded with example queries including:
- Get current user and profile information
- Authentication configuration
- Login with password
- User registration
Example Queries
Get Current User
query {
userManagement {
id
currentUser {
id
username
email
hasWeakPassword
authMethods
}
currentProfile {
id
firstName
lastName
email
emailVerified
country
phone
isKycVerified
}
}
}Login with Password
mutation {
userManagementLoginViaPassword(
input: {
site: "main"
username: "testuser"
password: "password123"
}
) {
token
labToken
sessionId
userType {
id
username
email
}
profileType {
id
firstName
lastName
email
}
errors {
message
code
}
}
}Register New User
mutation {
userManagementRegisterAsUser(
input: {
site: "main"
username: "newuser"
email: "[email protected]"
password: "securepass123"
firstName: "John"
lastName: "Doe"
dateOfBirth: 946684800
country: "US"
language: "en"
}
) {
token
sessionId
userType {
id
username
email
}
profileType {
id
firstName
lastName
email
country
}
errors {
message
code
}
}
}Update Profile
mutation {
userManagementUpdateProfile(
input: {
firstName: "Jane"
lastName: "Smith"
phone: "+15551234567"
city: "New York"
language: "en"
}
) {
profileType {
id
firstName
lastName
phone
city
}
errors {
message
}
}
}Example Subscriptions
subscription {
userManagementWaitForLoginToken(
input: { loginSessionId: "session_123" }
) {
token
errors {
message
}
}
}Project Structure
.
├── src/
│ ├── index.ts # Server entry point
│ ├── resolvers.ts # GraphQL resolvers with mocked data
│ ├── mocks.ts # Mock data generators
│ └── types.ts # TypeScript type definitions
├── scripts/
│ └── introspection-to-sdl.js # Schema conversion utility
├── schema.json # Original introspection schema
├── schema.graphql # Generated SDL schema
├── package.json
├── tsconfig.json
└── README.mdMock Data
All resolvers return realistic mocked data including:
- Randomized user information
- Valid email addresses and usernames
- JWT tokens and session IDs
- Country and localization data
- Social profile information
- Error responses (empty arrays by default)
The mock data generators are located in src/mocks.ts and can be customized as needed.
Environment Variables
PORT- Server port (default: 5000)
Example:
PORT=5000 pnpm run devSchema Conversion
If you need to regenerate the SDL schema from the introspection result:
pnpm run generate-schemaThis will read schema.json and output schema.graphql.
Development Notes
- The server uses GraphQL Yoga for optimal performance and developer experience
- All mutations return success responses with mocked data
- Subscriptions simulate async operations with 2-second delays
- The Node interface is properly implemented for relay-style pagination support
License
ISC
