Autocoder

GraphQL Interview Questions and Answers

Last updated 2026-11-19

GraphQL interviews separate people who have used a client from people who have built a server. The first group can write a query. The second can explain why a naive resolver tree issues a hundred database queries, how to paginate with connections, how errors are reported when the HTTP status is 200 and how to stop a client from running an expensive query that takes the service down.

This page covers schema design, resolvers, performance, security and tooling. If you are choosing between API styles, the REST API interview questions page covers the alternative, and the backend developer questions cover shared topics such as caching and authentication.

Core topicsSchema, resolvers, DataLoader, pagination, errors, security, federation
Compared withREST and gRPC
Questions here17

GraphQL versus REST, honestly

GraphQL lets clients ask for exactly the fields they need in one round trip, with a typed schema as the contract. The costs are server complexity, harder HTTP caching because most requests are POSTs to one URL, and new classes of problem such as query cost and N+1 resolvers. It pays off for clients with varied data needs, such as mobile and web apps sharing one backend, and is less compelling for simple, cache-friendly resource APIs.

What strong answers include

GraphQL Interview Questions and Answers: questions with worked answers

  1. 1

    What is GraphQL and what are its core operations?

    easy

    GraphQL is a query language and runtime for APIs, defined by a strongly typed schema. A client sends an operation and gets back JSON in the same shape. Query reads data, mutation changes data and executes top-level fields serially, and subscription streams events, typically over WebSocket. The server exposes a single endpoint, and introspection lets tools discover the schema.

    graphql
    query GetUser($id: ID!) {
      user(id: $id) {
        name
        posts(first: 3) { title }
      }
    }
  2. 2

    What are scalars, object types, enums, input types, interfaces and unions?

    easy

    Built-in scalars are Int, Float, String, Boolean and ID, and you can define custom ones such as DateTime. Object types have fields, enums restrict to fixed values, and input types are used for arguments, since output types cannot be arguments. An interface defines fields several types share, and a union is one of several types with no shared fields, resolved with inline fragments.

    graphql
    interface Node { id: ID! }
    type User implements Node { id: ID!  name: String!  email: String }
    union SearchResult = User | Post
    input CreateUserInput { name: String!  email: String! }
  3. 3

    What does the exclamation mark mean, and how does nullability affect results?

    medium

    A trailing ! makes a field non-null. If a non-null field resolves to null or throws, the null propagates to the nearest nullable parent, and if the parent is also non-null it continues upwards, possibly to the whole data object. So make a field non-null only when you can guarantee it, and prefer nullable for fields backed by services that can fail, so one failure does not blank out the response.

  4. 4

    What is a resolver, and what are its four arguments?

    medium

    A resolver is a function that returns the value for one field. It receives the parent object, the arguments, a context shared across the request, such as the authenticated user and data loaders, and info about the query. Fields with no resolver use a default that reads the property of the same name from the parent. Keep resolvers thin and put business logic in services.

    javascript
    const resolvers = {
      Query: {
        user: (_parent, { id }, ctx) => ctx.services.users.byId(id),
      },
      User: {
        posts: (user, { first }, ctx) => ctx.loaders.postsByUser.load(user.id),
      },
    };
  5. 5

    What is the N+1 problem in GraphQL and how does DataLoader solve it?

    medium

    Resolving a list of 50 users and then each user's posts makes one query for users and 50 for posts. DataLoader collects all keys requested in the same tick of the event loop, calls your batch function once with the array of keys, for example one SQL query using WHERE user_id IN (...), and caches results per request. Create loaders per request, not globally, so caching does not leak data between users.

    javascript
    import DataLoader from 'dataloader';
    
    const postsByUser = new DataLoader(async (userIds) => {
      const rows = await db.query('SELECT * FROM posts WHERE user_id = ANY($1)', [userIds]);
      return userIds.map((id) => rows.filter((r) => r.user_id === id)); // same order as keys
    });
  6. 6

    How do you paginate in GraphQL?

    medium

    Offset arguments are simple but unstable when data changes. Cursor-based pagination following the Relay connection specification is the standard: a field returns a connection with edges, each having a node and an opaque cursor, plus pageInfo with hasNextPage and endCursor. Arguments are first and after. Cursors should be opaque, usually an encoded sort key, and the query must use an index that matches the order.

    graphql
    type Query { posts(first: Int = 10, after: String): PostConnection! }
    type PostConnection { edges: [PostEdge!]!  pageInfo: PageInfo! }
    type PostEdge { cursor: String!  node: Post! }
    type PageInfo { hasNextPage: Boolean!  endCursor: String }
  7. 7

    How are errors returned in GraphQL?

    medium

    A request that reaches the executor usually returns HTTP 200 with a JSON body that may contain both data and an errors array, each error with message, path and extensions. Partial data is possible. Syntax or validation errors return no data. For expected business failures, model them in the schema, for example a mutation payload with a union of success and error types, and keep the errors array for unexpected failures. Use extensions.code for machine-readable codes and hide internals.

  8. 8

    How do you design a mutation?

    medium

    Name it as a verb, take a single input object argument, and return a payload type containing the changed object and any user-facing errors. This lets you add fields later without breaking clients, and gives the client what it needs to update its cache. Make mutations as idempotent as practical, since clients may retry, and keep each one a single business operation.

    graphql
    type Mutation { createPost(input: CreatePostInput!): CreatePostPayload! }
    type CreatePostPayload { post: Post  userErrors: [UserError!]! }
    type UserError { field: [String!]  message: String! }
  9. 9

    How do fragments, variables and directives work?

    medium

    Variables parameterise operations, declared in the operation signature and sent as separate JSON, which avoids string building and allows caching and persisted queries. Fragments reuse a field selection, and inline fragments handle interfaces and unions by type. The built-in directives @include(if:) and @skip(if:) conditionally include fields, and @deprecated marks schema fields. Servers can define custom directives for things such as authorisation.

    graphql
    fragment UserBits on User { id name avatarUrl }
    query Feed($withEmail: Boolean!) {
      me { ...UserBits  email @include(if: $withEmail) }
    }
  10. 10

    How do you handle authentication and authorisation?

    medium

    Authenticate at the transport layer, for example a bearer token or session cookie verified before execution, and put the user in the context. Authorise in the business layer or in field-level logic, not only at the top-level query, because every path to an object must be protected. Check ownership for each object returned, and never rely on the client hiding fields. A directive or helper wrapper keeps checks consistent.

  11. 11

    How do you protect a GraphQL API from expensive or abusive queries?

    hard

    Limit query depth and compute a cost per field and multiplier for list sizes, rejecting queries above a budget. Cap page sizes, set timeouts, rate limit by cost not only by request count, and prefer persisted queries or an allow-list so only known operations run in production. Disable introspection and field suggestions for public production APIs if you do not need them, and limit batching of operations.

  12. 12

    What are persisted queries?

    hard

    The client sends a hash of a query, or a pre-registered ID, instead of the query text. The server looks up the full query, which cuts request size, allows GET requests that CDNs can cache, and when set to allow-list mode, rejects unknown arbitrary queries, a strong security gain. Automatic persisted queries register hashes on first use, while build-time registration enables a strict allow-list.

  13. 13

    How does caching work, given everything goes through one endpoint?

    hard

    HTTP caching is harder because requests are usually POSTs to one URL, so caching moves to other layers. Clients such as Apollo and Relay keep a normalised cache keyed by type and ID, so updating one object updates every query showing it. On the server, cache at the resolver or data source level, cache whole responses for public data with persisted queries over GET, and use CDN caching hints with cache-control directives.

  14. 14

    What is schema federation?

    hard

    Federation composes several GraphQL services, called subgraphs, into one supergraph that clients query through a router. Each subgraph owns part of the schema and can extend types owned by others using keys, for example the reviews service adds a reviews field to User defined by the users service. It lets teams own their parts independently, at the cost of operating a router and composing schemas in CI. Apollo Federation is the most common implementation.

  15. 15

    How do you evolve a GraphQL schema without versions?

    hard

    Add fields and types freely, because clients only get what they ask for. Never remove or change the type of an existing field without a transition. Mark old fields with @deprecated(reason:), track usage in your schema registry or by logging field usage, and remove them once no client uses them. Run schema checks in CI that compare against real operations to detect breaking changes.

  16. 16

    How do subscriptions work and what are the scaling issues?

    hard

    A subscription opens a long-lived connection, usually over WebSocket with the graphql-ws protocol or server-sent events, and the server pushes results when events occur. Each connection holds server resources and, with several server instances, events must be distributed using pub/sub such as Redis or Kafka. Authenticate at connection time and re-check authorisation for each event, and consider whether polling or a simple push would do.

  17. 17

    Write a minimal GraphQL server in JavaScript.

    hard

    Define type definitions and resolvers and pass them to a server such as GraphQL Yoga or Apollo Server. Context is built per request, which is where loaders and the user are created. Keep schema in SDL files, generate types with GraphQL Code Generator, and validate in CI.

    javascript
    import { createSchema, createYoga } from 'graphql-yoga';
    import { createServer } from 'node:http';
    
    const yoga = createYoga({
      schema: createSchema({
        typeDefs: 'type Query { hello(name: String = "world"): String! }',
        resolvers: { Query: { hello: (_, { name }) => 'Hello ' + name } },
      }),
    });
    createServer(yoga).listen(4000);

Frequently asked questions

Is GraphQL replacing REST?

No. Both are in wide use. GraphQL suits clients with varied data needs, while REST is simpler and cache-friendly for resource-oriented APIs.

What is the hardest GraphQL interview topic?

Usually the N+1 problem with DataLoader, followed by securing the API against expensive queries and designing pagination and errors.

Do I need to know a specific server library?

Know one, such as Apollo Server, GraphQL Yoga or a Java or Python equivalent, and understand the concepts well enough to translate between libraries.

Is GraphQL only for JavaScript?

No. Servers and clients exist for Java, Python, Go, C# and others, and the schema language is the same.

Related guides

More in Role-wise Interview Questions by Job and Tech Stack

See all in this section