How to understand a Apollo Server (GraphQL) codebase
A GraphQL server is a schema plus resolvers. The schema (SDL) declares types and operations; resolvers are functions keyed by type and field. A single query can call many resolvers, so reading the code means mapping fields to functions.
How to tell it's Apollo Server (GraphQL)
@apollo/serverandgraphqlinpackage.jsontypeDefswritten withgqlor in.graphqlfiles, and aresolversobjectstartStandaloneServerorexpressMiddlewaresetup
Where things usually live
- src/schema/ or *.graphql
- Type definitions: types, queries, mutations, subscriptions.
- src/resolvers/
- Resolver maps:
Query,Mutationand field resolvers per type. - src/context.ts
- Builds per-request context: user, loaders, data sources.
- src/dataSources/ or loaders/
- Database and API access, often with DataLoader for batching.
- codegen.ts
- GraphQL Code Generator config for typed resolvers.
- src/index.ts
- Server setup and plugins.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
- The schema, to see every operation
QueryandMutationresolvers- The context function, for auth
How a request moves through the code
- A query arrives and is parsed and validated against the schema.
- The context function runs once for the request.
- Root resolvers in
QueryorMutationrun. - For each field in the response, its resolver runs, using the parent object; missing resolvers default to reading the property.
- DataLoaders batch repeated lookups to avoid N+1 queries.
Questions to ask about the repository
- Which fields have custom resolvers rather than default property access?
- Where is authorization checked: in context, in resolvers or in directives?
- Which resolvers could cause N+1 queries?
What trips people up
- A field with no resolver silently returns the parent's property of the same name, so behaviour exists without code.
- Authorization on a root query doesn't protect nested fields reached through other types.