GraphQL interview questions

25 questions from the GraphQL course, each with the correct answer and an explanation. Try to answer before you open the answer.

GraphQL Foundations

1. What problem does GraphQL address directly?

  1. TLS encryption
  2. Database indexing
  3. Over-fetching and under-fetching of data
  4. Container orchestration
Show answer

Answer: Over-fetching and under-fetching of data

Clients choose the fields.

Lesson: GraphQL Compared With REST

2. What happens to a query that requests a field not in the schema?

  1. It fails validation before execution
  2. The field is returned as null silently
  3. The server creates the field
  4. Only the HTTP status changes
Show answer

Answer: It fails validation before execution

The schema is a contract.

Lesson: How a GraphQL Request Works

3. Which is a common trade-off of GraphQL?

  1. It only works with SQL databases
  2. It cannot return nested data
  3. It has no type system
  4. HTTP caching is harder than with resource-oriented URLs
Show answer

Answer: HTTP caching is harder than with resource-oriented URLs

One endpoint, varied queries.

Lesson: When to Use GraphQL

Designing the Schema

4. What does [Order!]! mean?

  1. An optional list of optional orders
  2. A non-null list whose items are non-null orders
  3. Exactly one order
  4. A map of orders
Show answer

Answer: A non-null list whose items are non-null orders

Both the list and its items are non-null.

Lesson: Object Types, Scalars and Nullability

5. How are multiple mutation fields in one request executed?

  1. In parallel, in random order
  2. Serially, in the order written
  3. Only the first runs
  4. They are rejected
Show answer

Answer: Serially, in the order written

Query fields may run in parallel; mutations run in order.

Lesson: Query, Mutation and Subscription Types

6. Which type describes structured arguments to a mutation?

  1. A subscription
  2. A union
  3. An interface
  4. An input type
Show answer

Answer: An input type

Inputs are separate from output types.

Lesson: Enums, Interfaces, Unions and Inputs

Writing Queries

7. Why use an alias?

  1. To request the same field more than once with different arguments
  2. To make a field optional
  3. To delete a field
  4. To change its type
Show answer

Answer: To request the same field more than once with different arguments

Response keys must be unique.

Lesson: Fields, Aliases and Fragments

8. Where are variable values sent?

  1. In the HTTP path
  2. Inside the field names
  3. In a separate variables JSON object alongside the query
  4. In a cookie
Show answer

Answer: In a separate variables JSON object alongside the query

Static query text, dynamic variables.

Lesson: Variables and Directives

9. What does introspection provide?

  1. Server CPU usage
  2. Database statistics
  3. A description of the schema's types and fields, queried through GraphQL itself
  4. User passwords
Show answer

Answer: A description of the schema's types and fields, queried through GraphQL itself

Powers tooling and docs.

Lesson: Introspection and Tooling

Mutations, Errors and Subscriptions

10. Why return the modified object in a mutation payload?

  1. So clients can update their caches without another request
  2. Because GraphQL requires exactly one field
  3. To slow down attackers
  4. To avoid using variables
Show answer

Answer: So clients can update their caches without another request

Caches normalise by id.

Lesson: Designing Mutations

11. Where should an expected "coupon expired" error usually be modelled?

  1. As a stack trace in the response
  2. As an HTTP 500
  3. Only in server logs
  4. In the schema, for example as userErrors or a union result type
Show answer

Answer: In the schema, for example as userErrors or a union result type

Expected errors are data.

Lesson: Error Handling

12. Which transport is commonly used for GraphQL subscriptions?

  1. FTP
  2. WebSockets
  3. SMTP
  4. Plain HTTP GET without streaming
Show answer

Answer: WebSockets

Long-lived, two-way connections.

Lesson: Subscriptions

Building a GraphQL Server

13. What is the first argument passed to a field resolver?

  1. The HTTP request
  2. The parent object (the result of the enclosing field)
  3. The database connection
  4. The schema
Show answer

Answer: The parent object (the result of the enclosing field)

parent, args, context, info.

Lesson: Resolvers

14. Why is authorising only root fields insufficient in GraphQL?

  1. GraphQL has no authentication
  2. Root fields cannot have resolvers
  3. Context is not available in nested fields
  4. The same data can be reached through many nested paths
Show answer

Answer: The same data can be reached through many nested paths

Protect data where it is resolved.

Lesson: Context and Authorisation

15. What does DataLoader do?

  1. Batches many individual loads into one call and caches them per request
  2. Encrypts queries
  3. Generates the schema
  4. Replaces the database
Show answer

Answer: Batches many individual loads into one call and caches them per request

Fixes N+1 queries.

Lesson: Solving N+1 With DataLoader

Using GraphQL From Clients

16. What must a client check even when the HTTP status is 200?

  1. The cookie expiry
  2. The Content-Length only
  3. The errors array in the response body
  4. Nothing else
Show answer

Answer: The errors array in the response body

Partial errors are common.

Lesson: Calling GraphQL With fetch

17. How does a normalised cache identify objects?

  1. By the time of the request
  2. By query text only
  3. By type name and id
  4. By the HTTP method
Show answer

Answer: By type name and id

One copy per object.

Lesson: Client Caching Libraries

18. What does GraphQL code generation provide?

  1. Typed results and variables for operations, derived from the schema
  2. A new database
  3. Faster networks
  4. Automatic authentication
Show answer

Answer: Typed results and variables for operations, derived from the schema

Compile-time safety.

Lesson: Code Generation and Typed Operations

Pagination, Limits and Caching

19. What does a client pass to get the next page in cursor pagination?

  1. Nothing; pages are automatic
  2. page: 2
  3. The full previous result
  4. after: the endCursor from the previous page
Show answer

Answer: after: the endCursor from the previous page

Opaque cursors mark positions.

Lesson: Cursor-Based Pagination

20. What do persisted queries allow a server to do?

  1. Skip the schema entirely
  2. Accept only pre-registered operations, identified by hash or ID
  3. Store user passwords
  4. Disable resolvers
Show answer

Answer: Accept only pre-registered operations, identified by hash or ID

An allow-list of queries.

Lesson: Query Cost, Depth Limits and Persisted Queries

21. Why is HTTP caching harder for GraphQL than for REST?

  1. GraphQL responses are binary
  2. Many different queries share one endpoint, often sent with POST
  3. GraphQL forbids caching
  4. Browsers do not support GraphQL
Show answer

Answer: Many different queries share one endpoint, often sent with POST

Use GET, persisted queries and hints.

Lesson: Caching Strategies

GraphQL in Production

22. Which risk is particularly associated with GraphQL?

  1. Inability to authenticate
  2. Missing TLS by design
  3. Lack of a type system
  4. Denial of service through deeply nested or very expensive queries
Show answer

Answer: Denial of service through deeply nested or very expensive queries

Clients compose arbitrary queries.

Lesson: GraphQL Security

23. Which schema change is non-breaking?

  1. Adding a new optional field
  2. Removing a field
  3. Renaming a field
  4. Changing a field from String to Int
Show answer

Answer: Adding a new optional field

Existing queries are unaffected.

Lesson: Evolving the Schema

24. What does a federation router do?

  1. Replaces resolvers in every service
  2. Stores all data centrally
  3. Composes subgraphs into one schema and plans queries across them
  4. Generates REST endpoints
Show answer

Answer: Composes subgraphs into one schema and plans queries across them

One graph, many services.

Lesson: Federation and Composing Services

25. Which belongs on a GraphQL API checklist?

  1. Authorisation only on root fields
  2. Unbounded lists for convenience
  3. Lists use cursor pagination with a maximum page size
  4. Removing fields without deprecation
Show answer

Answer: Lists use cursor pagination with a maximum page size

Predictable, safe APIs.

Lesson: A GraphQL API Checklist

← Back to the course