GraphQL: schemas, queries, resolvers and performance – Server Side interview prep

261 interview-style multiple-choice questions on GraphQL: schemas, queries, resolvers and performance, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 88 key terms with the flashcards first, then test yourself.

Take the practice test · Flashcards · All study tools

What it covers

  1. 3.1 Schema and type system
  2. 3.2 Queries, variables, fragments and directives
  3. 3.3 Mutations and subscriptions
  4. 3.4 Resolvers and execution
  5. 3.5 Performance: N+1, DataLoader and batching
  6. 3.6 Pagination and schema design
  7. 3.7 Security: authorization, query cost and persisted queries
  8. 3.8 Errors, caching and clients
  9. 3.9 Federation, tooling and GraphQL vs alternatives

Key terms

3.1 Schema and type system

SDL
Schema Definition Language for GraphQL schemas
Non-null
Type marked with ! that can never be null
Introspection
Querying a GraphQL schema about itself
Input type
Object type used for arguments
Scalar
Leaf type like Int or a custom DateTime
Enum
Fixed set of named values
Interface
Shared fields types must implement
Union
One of several object types
Custom directive
Annotation the server interprets
OneOf input
Input with exactly one field set
__typename
Meta-field naming the concrete type

3.2 Queries, variables, fragments and directives

Selection set
The fields requested in a query
Fragment
Reusable group of fields
Alias
Renamed field in a query response
Subscription
Operation that pushes updates to the client
Operation name
Label for a query or mutation
Variable
Typed value passed separately from the query
Inline fragment
Type-conditional selection
Fragment colocation
Components declaring their data needs
@include / @skip
Conditional field selection
@defer / @stream
Incremental delivery directives
Query batching
Several operations in one request
GraphQL over HTTP
Spec for serving GraphQL via HTTP

3.3 Mutations and subscriptions

Mutation payload
Result object returned by a mutation
Serial execution
Top-level mutation fields run in order
Idempotency key
Client token to dedupe retries
User error
Expected failure returned as data
Optimistic response
Predicted mutation result shown early
graphql-ws
WebSocket protocol for subscriptions
Live query
Query re-sent when its data changes
Presigned upload
Direct-to-storage file upload URL

3.4 Resolvers and execution

Resolver
Function that returns a field's value
N+1 problem
One query for a list plus one per item
DataLoader
Batching and per-request caching utility
Context
Per-request object shared by resolvers
Resolver signature
parent, args, context, info
Default resolver
Returns parent[fieldName]
Lookahead
Inspecting selected fields before fetching
resolveType
Picking an abstract type's concrete type
Null propagation
Non-null errors nulling the nearest nullable parent
Code-first
Schema generated from code
Schema-first
SDL written first, code follows
Custom scalar functions
serialize, parseValue, parseLiteral

3.5 Performance: N+1, DataLoader and batching

Batch function
Loads many keys, returns results in key order
prime / clear
Seeding or evicting a DataLoader key
Cache hint
Per-field caching guidance
APQ
Automatic persisted queries by hash
Query compilation
Turning GraphQL into one SQL query
Request waterfall
Sequential round trips per nesting level

3.6 Pagination and schema design

Connection
Relay pagination wrapper type
Edge
Item plus cursor and relationship data
pageInfo
Paging metadata
Node interface
Globally identifiable object
Global ID
Type-qualified opaque identifier
Viewer pattern
Root field for the current user
Result union
Union of success and error types
Deprecation workflow
Add, deprecate, monitor, remove

3.7 Security: authorization, query cost and persisted queries

Query cost analysis
Estimating expense before executing
Cost directive
@cost and @listSize schema hints
Alias abuse
Repeating a field via aliases in one request
Trusted documents
Allowlist of registered operations
Depth limit
Max nesting allowed by validation
Field suggestions
"Did you mean" hints that leak schema
Directive overloading
Many repeated directives to exhaust CPU
Mass assignment
Clients setting fields they shouldn't

3.8 Errors, caching and clients

Query complexity
Estimated cost of a query used to limit expensive requests
Persisted query
Pre-registered query sent by ID
Normalized cache
Client cache keyed by type and ID
Federation
Combining subgraphs into one GraphQL API
errors array
Response list of error objects
Error path
Response location of a failure
extensions.code
Machine-readable error code
Request error
Error before execution, no data
Field error
Error during execution with partial data
Fetch policy
How a client uses cache vs network
Type policy
Cache config for a type
Relay compiler
Build-time GraphQL artifact generator
Graphcache
urql's normalized cache

3.9 Federation, tooling and GraphQL vs alternatives

Subgraph
Service contributing part of a federated graph
Entity
Type shared across subgraphs by key
Router
Gateway that plans and runs federated queries
Supergraph
Composed schema of all subgraphs
Schema stitching
Gateway-merged schemas with custom glue
Schema registry
Store of schema versions and usage
Composite Schemas
Foundation effort to standardize federation
Schema coordinate
Reference like Type.field
GraphQL Inspector
Schema diff tool
Schema mocking
Fake data from a schema

Sample practice questions

  1. What is a GraphQL schema?

    1. A layout of the database tables behind the GraphQL server
    2. A list of the REST endpoints that GraphQL wraps
    3. A typed description, in SDL, of the API's data and operations
    4. A JSON file of sample responses used for mocking clients

    Answer: C. A typed description, in SDL, of the API's data and operations Clients and tools use the schema to validate queries and generate code.

  2. What is a key advantage of GraphQL over a typical REST API for clients?

    1. GraphQL responses are always cached by browsers automatically
    2. Clients fetch exactly the fields they need, across types, in one call
    3. GraphQL APIs don't need any server to run
    4. GraphQL removes the need for any authentication

    Answer: B. Clients fetch exactly the fields they need, across types, in one call This avoids both over-fetching and multiple round trips.

  3. How do GraphQL subscriptions usually deliver updates?

    1. By email notifications sent to the user's address
    2. Over a separate REST API that clients call on demand
    3. By the client polling the server once every second
    4. Pushed over a long-lived connection like WebSockets

    Answer: D. Pushed over a long-lived connection like WebSockets They suit chat, notifications and live dashboards.

  4. What is a resolver?

    1. A function that produces one field's value from its parent and args
    2. A client-side library that sends queries to the server
    3. A database index that speeds up GraphQL queries
    4. A tool that automatically fixes errors found in the schema

    Answer: A. A function that produces one field's value from its parent and args Fields without a custom resolver usually read the property of the same name from the parent.

  5. What is the N+1 problem in GraphQL?

    1. One query for N items, then one more query per item
    2. A schema that has N+1 types defined in it
    3. A client sending N+1 separate HTTP requests
    4. A query nested exactly one level too deep

    Answer: A. One query for N items, then one more query per item Listing 100 posts and then each post's author can mean 101 database queries.

  6. What does Relay-style connection pagination return?

    1. A list of URLs the client fetches one by one
    2. Every item in the collection with no pagination
    3. `edges` with `node` and `cursor`, plus `pageInfo`
    4. A plain array of items plus the current page number

    Answer: C. `edges` with `node` and `cursor`, plus `pageInfo` Clients ask for more with `first` and `after: endCursor`.

  7. Where should authorization rules usually live in a GraphQL API?

    1. Only in the client application, by hiding fields from users
    2. In the business layer resolvers call, so rules apply on every path
    3. Only in the schema's field descriptions, as documentation
    4. Only at the HTTP gateway in front of the GraphQL server

    Answer: B. In the business layer resolvers call, so rules apply on every path GraphQL lets clients reach the same data through many paths, so rules must be consistent.

  8. A GraphQL query partly fails: one field's resolver throws. What does a typical server return?

    1. A redirect to a generic error page on the server
    2. HTTP 404, because the failing field couldn't be found
    3. HTTP 200 with partial `data` (that field null) and an `errors` array
    4. HTTP 500 with no `data` at all and a plain-text error message

    Answer: C. HTTP 200 with partial `data` (that field null) and an `errors` array Clients must check `errors` even when `data` is present.

  9. What problem does GraphQL Federation solve?

    1. Running a full GraphQL server inside the user's browser
    2. Encrypting GraphQL traffic between clients and servers
    3. Composing one graph from subgraphs owned by separate services
    4. Translating existing REST APIs directly into SQL queries

    Answer: C. Composing one graph from subgraphs owned by separate services Each team owns part of the graph while clients see one schema.

  10. In SDL, what does `name: String!` mean?

    1. `name` is a deprecated String field
    2. `name` is a list of String values
    3. `name` is a String that's never null
    4. `name` is an optional String field

    Answer: C. `name` is a String that's never null If a non-null field resolves to null, the error propagates to the nearest nullable parent.

Practice all 261 questions

More Server Side