- Add logic to the graphql endpoint at: ./src/routes/graphql.
Constraints and logic for GQL queries should align with the existing RESTful implementation.
The resulting GQL schema should match the required structure.
1.1. Test queries: npm run test-queries
1.2. Test mutations: npm run test-mutations - Limit GraphQL query complexity by depth using the graphql-depth-limit package.
Set the depth limit to 5.
2.1. Test depth rule: npm run test-rule - Solve the n+1 GraphQL problem using DataLoader.
Use only one findMany call per loader.
3.1. Test dataloader: npm run test-loader
3.2. Test dataloader-cache: npm run test-loader-prime
When querying all users, preload them into the DataLoader cache to avoid redundant database calls for subs.
Determine if a user is a sub by performing a join (via include), but only when the query requires subs. Use graphql-parse-resolve-info to parse GraphQLResolveInfo and conditionally apply the join.
Do not add new npm dependencies.
Modify/add code only in ./src/routes/graphql.
Use a code-first approach for the GQL server.
Avoid creating index.ts files (reserved for Fastify plugins).
Adhere to the repository’s style configurations.
Ensure critical files remain unchanged: npm run test-integrity.
A test ([test-name].test.js) is considered failed if it is partially completed.
Subsequent tests are considered failed if any previous test is failed.
Steps to get started:
- Install dependencies: npm ci
- Create .env file (copy from .env.example): cp .env.example .env
- Create database.db file: touch ./prisma/database.db
- Apply database migrations: npx prisma migrate deploy
- Seed database: npx prisma db seed
- Start server: npm run start
Useful things:
- Database GUI: npx prisma studio
- Reset database: npx prisma migrate reset (includes seeding)
- Test REST API (Swagger): [::1]:8000/docs
- Use a GraphQL client with introspection support for testing.