GraphQL Resolvers Documentation
Overview
This documentation covers the GraphQL resolvers implementation for a location-based group tracking application. The system allows users to create groups, beacons (tracking sessions), and landmarks while providing real-time location updates through subscriptions.
Dependencies
- apollo-server-express: For GraphQL server functionality
- bcryptjs: Password hashing
- jsonwebtoken: JWT authentication
- nanoid: Unique ID generation
- geolib: Geolocation utilities
- nodemailer: Email services
- MongoDB/Mongoose: Database operations
Core Features
Authentication
- User registration with email/password
- OAuth support
- JWT-based authentication
- Email verification system
Query Resolvers
me
Returns the currently authenticated user's profile.
beacon(id: ID!)
Returns a specific beacon by ID. User must be either the leader or a follower of the beacon.
group(id: ID!)
Returns a specific group by ID. User must be either the leader or a member of the group.
groups(page: Int!, pageSize: Int!)
Returns paginated list of groups the user belongs to.
beacons(groupId: ID!, page: Int!, pageSize: Int!)
Returns paginated list of beacons in a group, sorted by:
- Active beacons
- Upcoming beacons
- Inactive beacons
filterBeacons(id: ID!, type: String!)
Filters beacons by type:
- ACTIVE: Currently running
- INACTIVE: Expired
- UPCOMING: Not yet started
nearbyBeacons(location: LocationInput!, id: ID!, radius: Float!)
Returns beacons within specified radius of given location.
Mutation Resolvers
User Management
register(user: UserInput!): Register new useroAuth(userInput: OAuthInput!): Handle OAuth loginlogin(id: ID, credentials: CredentialsInput): User loginsendVerificationCode(email: String!): Send email verificationcompleteVerification(userId: ID!): Complete email verification
Group Management
createGroup(group: GroupInput!): Create new groupjoinGroup(shortcode: String!): Join existing groupremoveMember(groupId: ID!, memberId: ID!): Remove group memberchangeShortcode(groupId: ID!): Generate new group shortcode
Beacon Management
createBeacon(beacon: BeaconInput!, groupID: ID!): Create new beaconjoinBeacon(shortcode: String!): Join existing beacondeleteBeacon(id: ID!): Delete beaconrescheduleHike(newStartsAt: DateTime!, newExpiresAt: DateTime!, beaconID: ID!): Update beacon schedule
Location & Safety
createLandmark(landmark: LandmarkInput!, beaconID: ID!): Create location landmarkupdateUserLocation(id: ID!, location: LocationInput!): Update user locationsos(id: ID!): Trigger SOS alert
Subscriptions
beaconLocations
Real-time updates for:
- User locations
- SOS alerts
- Route changes
- New landmarks
JoinLeaveBeacon
Notifications when users:
- Join beacon
- Leave beacon
groupUpdate
Updates for:
- New members
- New beacons
- Deleted beacons
- Updated beacons
Security Features
- JWT-based authentication
- Password hashing using bcrypt
- Permission checks for all operations
- Group membership validation
- Beacon access control
Real-time Features
- Location tracking
- SOS alerts
- Group activity monitoring
- Beacon status updates
Error Handling
- Custom error types for different scenarios
- Proper error messages for invalid operations
- Duplicate shortcode handling
- Invalid access attempts
Best Practices
- Populated references for efficient data access
- Pagination for large data sets
- Proper permission checks before operations
- Data validation before database operations
- Proper error handling and user feedback