Skip to content

[Backend] Implement GraphQL API endpoint as complement to REST #181

Description

@Penielka

Description

The REST API is comprehensive but GraphQL would allow frontend clients to request exactly the data they need, reducing over-fetching and under-fetching. Implement a GraphQL endpoint at /graphql using Apollo Server or express-graphql, with resolvers for the most-used data types: courses, credentials, user profiles, and enrollments.

Definition of Done

  • Apollo Server (or express-graphql) integrated with Express
  • GraphQL schema defined for: User, Course, Credential, Enrollment, Achievement, Analytics
  • Queries: user(id), courses(filter), credential(hash), enrollment(userId, courseId)
  • Mutations: enrollInCourse, issueCredential (wraps existing REST logic)
  • GraphQL Playground available at /graphql in development
  • Authentication/authorization via existing JWT middleware
  • Error handling follows GraphQL error spec
  • Rate limiting applied to GraphQL endpoint
  • Query complexity analysis to prevent expensive queries

Acceptance Criteria

  1. POST /graphql accepts queries and returns properly shaped JSON
  2. Playground at /graphql works in dev mode
  3. Existing REST endpoints continue to work unchanged
  4. Auth required for mutations, public queries allowed for course listing
  5. N+1 query problem addressed with DataLoader batching

Files to Modify

  • backend/package.json — add apollo-server-express, graphql, dataloader
  • New file: backend/src/graphql/schema.ts — GraphQL schema definition
  • New file: backend/src/graphql/resolvers.ts — resolvers
  • New file: backend/src/graphql/context.ts — auth context
  • backend/src/index.ts — mount Apollo middleware
  • backend/middleware/rateLimit.ts — add GraphQL rate limit tier

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions