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
- 3.1 Schema and type system
- 3.2 Queries, variables, fragments and directives
- 3.3 Mutations and subscriptions
- 3.4 Resolvers and execution
- 3.5 Performance: N+1, DataLoader and batching
- 3.6 Pagination and schema design
- 3.7 Security: authorization, query cost and persisted queries
- 3.8 Errors, caching and clients
- 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
What is a GraphQL schema?
- A layout of the database tables behind the GraphQL server
- A list of the REST endpoints that GraphQL wraps
- A typed description, in SDL, of the API's data and operations
- 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.
What is a key advantage of GraphQL over a typical REST API for clients?
- GraphQL responses are always cached by browsers automatically
- Clients fetch exactly the fields they need, across types, in one call
- GraphQL APIs don't need any server to run
- 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.
How do GraphQL subscriptions usually deliver updates?
- By email notifications sent to the user's address
- Over a separate REST API that clients call on demand
- By the client polling the server once every second
- 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.
What is a resolver?
- A function that produces one field's value from its parent and args
- A client-side library that sends queries to the server
- A database index that speeds up GraphQL queries
- 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.
What is the N+1 problem in GraphQL?
- One query for N items, then one more query per item
- A schema that has N+1 types defined in it
- A client sending N+1 separate HTTP requests
- 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.
What does Relay-style connection pagination return?
- A list of URLs the client fetches one by one
- Every item in the collection with no pagination
- `edges` with `node` and `cursor`, plus `pageInfo`
- 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`.
Where should authorization rules usually live in a GraphQL API?
- Only in the client application, by hiding fields from users
- In the business layer resolvers call, so rules apply on every path
- Only in the schema's field descriptions, as documentation
- 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.
A GraphQL query partly fails: one field's resolver throws. What does a typical server return?
- A redirect to a generic error page on the server
- HTTP 404, because the failing field couldn't be found
- HTTP 200 with partial `data` (that field null) and an `errors` array
- 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.
What problem does GraphQL Federation solve?
- Running a full GraphQL server inside the user's browser
- Encrypting GraphQL traffic between clients and servers
- Composing one graph from subgraphs owned by separate services
- 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.
In SDL, what does `name: String!` mean?
- `name` is a deprecated String field
- `name` is a list of String values
- `name` is a String that's never null
- `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.
More Server Side
- HTTP fundamentals
- REST API design
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting