Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 37 ยท Practice and Review

GraphQL Interview Questions

35 GraphQL interview questions with concise answers: concepts, schema, resolvers, N+1, security, caching, federation and REST, plus runnable stand-ins.

Interviews about GraphQL rarely ask for syntax trivia. They check whether you understand the ideas: why a typed schema helps, how execution works, where performance and security problems come from, and when GraphQL is the wrong tool. This lesson collects 35 questions you are likely to meet, each with a short answer you could say out loud in under a minute.

Every answer links to the lesson that teaches the topic in depth. The snippets are read-only unless a TryIt is shown; the runnable ones are stand-ins (small hand-written JavaScript programs that behave like the real server logic), because the site cannot run a real GraphQL server.

What interviewers look for

Concepts Schema, types, resolvers.
Performance N+1, batching, caching.
Security Limits, auth, introspection.
Trade-offs When REST is better.

Explain why, not only what.

1 / 2

Concepts and basics

1. What is GraphQL? A query language for APIs and a runtime that executes those queries against a typed schema. The client states exactly which fields it wants, and the response mirrors that shape. See What Is GraphQL?.

2. What problems does it solve? Over-fetching (more fields than needed), under-fetching (several round trips to assemble one screen) and slow coordination between frontend and backend teams, because the schema is a shared, self-documenting contract.

3. Is GraphQL a database technology? No. It sits in front of any data source: SQL, a REST service, a cache. Resolvers decide where data comes from.

4. Name the three operation types. query (read), mutation (write, run serially) and subscription (a stream of events). See Mutations and Subscriptions.

5. How does GraphQL differ from REST? REST has many endpoints with fixed responses; GraphQL usually has one endpoint and client-shaped responses. REST gets HTTP caching for free; GraphQL needs more care. See GraphQL vs REST.

6. When is REST the better choice? Simple resource APIs, file downloads, public APIs that benefit from CDN caching by URL, and teams without the capacity to run a schema layer.

7. Does GraphQL require a single endpoint and HTTP POST? Convention, not a rule. Most servers use one URL (often /graphql) and accept POST with a JSON body; GET is common for persisted queries. See GraphQL over HTTP.

8. What does the response of an operation look like? A JSON object with data (the result, shaped like the query), and errors only if something went wrong. See Your First Query.

Queries and operations

9. What are fields, arguments and selection sets? A selection set is the { ... } list of fields; fields may take arguments such as book(id: "7"). See Fields, Arguments and Nested Selections.

10. What are aliases for? Renaming a field in the response, mainly so you can request the same field twice with different arguments: small: image(size: 50) and large: image(size: 500).

11. What is a fragment, and what is an inline fragment? A named fragment is a reusable set of fields on a type. An inline fragment (... on Book { pages }) selects fields only when the runtime type matches, which you need for interfaces and unions. See Aliases and Fragments.

12. Why use variables instead of building the query string? Variables keep values out of the query text: no string-concatenation injection, one parsed query reused with many values, and better caching and logging. See Variables and Directives.

13. What do @include and @skip do? They conditionally include a field based on a Boolean variable: name @include(if: $withName).

14. Why do mutations run serially but query fields in parallel? Query fields are side-effect free, so the server may resolve siblings concurrently. Top-level mutation fields may depend on each other's effects, so the spec runs them one after another.

Schema

15. What is SDL? The Schema Definition Language: a readable syntax for describing types, fields, arguments and relationships. See SDL: Types and Scalars.

16. List the built-in scalars. Int, Float, String, Boolean and ID. Everything else is an object, enum, or a custom scalar such as DateTime.

17. What does [Int!]! mean? A non-null list of non-null integers. The inner ! is for the items, the outer for the list. See Lists and Non-Null Types.

18. Why are fields nullable by default, and what happens when a non-null field fails? Nullable fields let a failure hide only that field. When a non-null field errors, the server nulls the nearest nullable parent (or all of data), and adds an entry to errors. This is called null bubbling.

19. Interface versus union? An interface requires shared fields across implementing types (Node { id }). A union lists possible types with no shared fields required. Both need inline fragments or __typename on the client. See Enums, Interfaces and Unions.

20. Input type versus object type? Object types are outputs; input types (input) are for arguments. Inputs cannot have arguments on fields, cannot reference object types, and cannot implement interfaces. See Input Types, Custom Scalars and Introspection.

21. What is introspection? Queries such as __schema and __type(name: "Book") let a client ask the server about its own schema. GraphiQL, code generators and editors depend on it.

22. How do you deprecate a field? @deprecated(reason: "Use fullName") on the field. Clients keep working and tools warn. Remove it only when usage reaches zero. See Schema Evolution, Federation and Tooling.

Schema design

23. Give some schema design rules. Model the domain rather than tables, use specific mutations (publishPost, not updatePost with flags), return payload types, name things consistently, and design for the client's screens. See Schema Design Best Practices.

24. How should you paginate? Prefer cursor pagination. The Relay connection shape (edges { node cursor } and pageInfo { hasNextPage endCursor }) is the common convention because offsets skip or repeat rows when data changes. See Pagination: Offset, Cursor and Connections.

25. How do you model expected errors, like "email already taken"? Put them in the data: a payload with userErrors, or a result union (CreateUserResult = User | EmailTaken). Keep top-level errors for unexpected failures. See Modeling Errors.

Resolvers and execution

26. What is a resolver and what are its arguments? A function that produces one field's value: (parent, args, context, info). parent is the object above, args the field arguments, context is per-request shared state (current user, loaders) and info describes the query. See Resolvers.

27. What is a default resolver? If you do not define one, the server returns parent[fieldName] (calling it if it is a function). That is why plain objects work as data.

28. What are the phases of executing a request? Parse the text into a document, validate it against the schema, then execute: resolve fields breadth-first by level, complete values, and collect errors. See How Execution Works and How Errors Behave.

29. Does a resolver error fail the whole request? Not necessarily. The field becomes null (subject to non-null rules) and the error is added with a path. The HTTP status is often still 200 for such partial results.

Performance, caching and N+1

30. Explain the N+1 problem and how to fix it. A list resolver issues one query, then each item's nested field issues another (1 + N). The fix is batching with a per-request DataLoader: collect keys during one tick, fetch them in one call, and cache results for the request. See The N+1 Problem and DataLoader.

JS Stand-in: N+1 versus a tiny DataLoader

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The stand-in is a hand-written loader. The real dataloader package (and the equivalents in Python libraries) adds batch-size limits and error handling, but the idea is the same.

31. Why must a DataLoader be created per request? Its cache would otherwise leak data between users (a security bug) and serve stale values.

32. Why is HTTP caching harder with GraphQL, and what helps? POST bodies are not cached by CDNs by default, and every client can ask for different fields. Persisted queries sent by GET, response and field caches on the server, and normalized caches on the client (keyed by __typename and id) help. See Caching and Performance and Clients, Apollo and Code Generation.

Security

33. How do you protect a GraphQL API from expensive queries? Limit depth and cost, set timeouts, use persisted-query allow-lists for first-party clients, rate limit by cost rather than by request count, and cap aliases and batch size. See Query Depth, Complexity and Other Attacks.

JS Stand-in: a depth limit

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Real servers count depth on the parsed document (so fragments and braces inside strings are handled correctly); counting braces is only a teaching shortcut.

34. Where should authentication and authorization live? Authenticate once at the HTTP layer and put the user in context. Enforce authorization in the business layer that every resolver calls, not scattered per resolver, so other entry points get the same rules. See Authentication and Authorization.

Ecosystem and architecture

35. What is federation and how does it differ from schema stitching? Federation (for example Apollo Federation) lets teams own subgraphs that declare entities with @key; a gateway or router composes them into one supergraph and plans queries across them. Stitching merges schemas at the gateway with hand-written glue. See Schema Evolution, Federation and Tooling.

How to answer well

  • Start with the idea in one sentence, then give one concrete example.
  • Mention a trade-off every time. "It depends" followed by on what is a strong answer.
  • If asked about something you have not used, say what you would check, rather than guessing.
  • Practice by explaining the answers aloud, then try the Practice Exercises.

If you can explain null bubbling, N+1 and persisted queries without notes, you are ahead of most candidates.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A list resolver returns 20 posts and each post's author is loaded with its own query. How many queries run?

    One query for the list plus one per post: 1 + N = 21. A per-request DataLoader would batch the author lookups into one.
  2. 2. Where should expected business failures such as 'email already taken' usually be modeled?

    Expected failures are part of the domain, so typed payloads or unions let clients handle them. Top-level errors are for unexpected problems.
  3. 3. Why is a DataLoader created for every request?

    Its cache would otherwise hold one user's data and could return it to someone else.
  4. 4. Which approach helps a CDN cache GraphQL responses?

    A GET with a stable query identifier gives the CDN a cacheable URL.

Summary

  • Interviews test ideas: schema as contract, execution, null bubbling, N+1, caching, security and trade-offs.
  • Expected failures belong in the schema; unexpected ones go in errors.
  • Batch with a per-request loader, limit depth and cost, authorize in the business layer.
  • Be ready to say when REST is the better answer.

Next: GraphQL Cheat Sheet.