Skip to content

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/server and graphql in package.json
  • typeDefs written with gql or in .graphql files, and a resolvers object
  • startStandaloneServer or expressMiddleware setup

Where things usually live

src/schema/ or *.graphql
Type definitions: types, queries, mutations, subscriptions.
src/resolvers/
Resolver maps: Query, Mutation and 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

  1. The schema, to see every operation
  2. Query and Mutation resolvers
  3. The context function, for auth

How a request moves through the code

  1. 1A query arrives and is parsed and validated against the schema.
  2. 2The context function runs once for the request.
  3. 3Root resolvers in Query or Mutation run.
  4. 4For each field in the response, its resolver runs, using the parent object; missing resolvers default to reading the property.
  5. 5DataLoaders 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.