Debugging GraphQL APIs

1. Using GraphQL Playground

NoteDetail
StatusDeprecated — use Apollo Sandbox or GraphiQL 4
SuccessorApollo Sandbox at studio.apollographql.com/sandbox

2. Using GraphiQL

FeatureDetail
Schema explorerDoc explorer with search
AutocompleteField/arg/type suggestions
Plugins (v4+)Custom panels, history, codegen
Auth headersSet via headers tab

3. Inspecting Query Execution

Example: Print execution path

plugins: [{
  onExecute() {
    return {
      onResolverCalled({ info }) {
        console.log("resolve", info.path);
      }
    };
  }
}]

4. Using Debug Logging

LibraryDetail
debugDEBUG=app:* node server.js
pinoStructured JSON, fast
Levelstrace/debug/info/warn/error/fatal

5. Analyzing Query Performance

ToolUse
Apollo Studio tracesPer-resolver timing
EXPLAIN ANALYZESQL plan beneath resolver
DataLoader statsBatch coverage

6. Tracing Resolver Execution

Example: Per-resolver span

const tracer = trace.getTracer("graphql");
const wrapped = (resolver) => (parent, args, ctx, info) =>
  tracer.startActiveSpan(info.fieldName, async (span) => {
    try { return await resolver(parent, args, ctx, info); }
    catch (e) { span.recordException(e); throw e; }
    finally { span.end(); }
  });

7. Debugging N+1 Queries

SymptomDiagnosis
Many identical SQL queriesMissing DataLoader
High latency on list fieldsPer-row child fetch
ToolPrisma metrics, pg_stat_statements, Apollo trace tree

8. Profiling Memory Usage

ToolDetail
node --inspect + Chrome DevToolsHeap snapshot, allocation sampling
clinic.jsDoctor / heap profiler
--max-old-space-sizeAdjust V8 heap

9. Testing with Mock Data

StrategyDetail
addMocksToSchemaAuto-mock all types
MSWMock HTTP at network boundary
FakerGenerate realistic fixtures

10. Using Browser DevTools

ToolDetail
Apollo Client DevtoolsCache inspector, query log
Relay DevToolsStore + network log
Network panelFilter by /graphql