All 36 GraphQL quiz questions below come with a short explanation, visible right on the page — no sign-in needed. They're grouped by beginner and intermediate levels and 36 subtopics, so you can revise one part at a time. Choose Try GraphQL quiz above to take a scored run and review the questions you got wrong.
What is the core difference between GraphQL and REST?
A.GraphQL fully removes the need for a database
B.The client describes exactly the data it needs
C.GraphQL is always faster than REST
D.GraphQL does not use HTTP to transport data
Answer: B
The client describes exactly the fields it needs and the server returns exactly that shape. REST endpoints have fixed response shapes, so the client either over-fetches or has to call multiple times.
A.It is where the database's table structure is declared
B.It is a configuration file setting the server's port and address
C.It is the list of each user's permissions in the system
D.It is the contract describing every type and queryable field
Answer: D
The schema is the contract describing every type, field, and argument a client can query. Thanks to it, queries with wrong field names or types are rejected before execution, and code generation tools and editor suggestions all rely on it.
In execution, top-level fields of a mutation run sequentially so the order of data changes is deterministic, while queries are read-only so their fields can run in parallel. Semantically, a query reads and a mutation writes.
A.It translates the GraphQL query into the equivalent SQL
B.It decides which users may call the API
C.It returns the value for one field when the query reaches it
D.It checks the query's syntax before running it
Answer: C
A resolver is a function that returns the value for a field. The server follows the query shape and calls the corresponding resolver for each field, so a deeply nested query triggers a call tree.
What does an exclamation mark after a type name mean in a GraphQL schema?
A.That field is only for logged-in users
B.That field never returns null
C.That field is a required argument when querying
D.That field is indexed in the database
Answer: B
An exclamation mark means the field is never null. This is a strong commitment: if a resolver returns null for that field, the error propagates to the nearest nullable parent field, and it can wipe out an entire data branch.
Why use variables rather than interpolating values into the query string?
A.String concatenation cannot pass numeric values
B.Variables make the query run faster on the server
C.Variables let you skip the schema's type checking
D.The query keeps the same shape for every value
Answer: D
Using variables keeps the query document unchanged for every value, so the server can parse and cache it, while values are type-checked. String interpolation produces a different query each time and opens the door to unintended content injection.
A.Grouping a set of fields reused across several queries
B.Storing query results in the client's cache
C.Splitting one large query into several HTTP requests
D.Loading the data progressively over time
Answer: A
A fragment groups a reusable set of fields. In practice, it lets each component declare the data it needs, and then the screen composes those fragments into a single query.
Can a GraphQL response contain both data and errors?
A.Yes — the data that was retrieved is returned alongside the errors
B.No — errors are always returned on a separate endpoint
C.No — any error discards the whole response
D.Yes, but only with an HTTP 500 status code
Answer: A
Yes. The response contains both a data part and an errors part, so a query can return a partial result: the branch that fails is null and recorded in the errors list, while other branches still have normal data.
A.Optimizing queries automatically before execution
B.Watching the queries other users are running
C.Viewing the real data of every record in the system
D.Querying the schema itself to discover what is there
Answer: D
Introspection lets you query the schema itself to discover which types, fields, and arguments exist. It is the foundation for API exploration tools, query autocomplete, and automatic type generation for clients.
A.The server returns more fields than the client needs
B.The client lacks permission for some of the fields
C.One screen must call several endpoints and stitch the results
D.The response is truncated for exceeding a size limit
Answer: C
Under-fetching is when one screen has to call multiple endpoints and stitch the data together itself, because each endpoint only returns part of it. On mobile networks, every extra round trip makes the screen noticeably slower.
Querying 50 posts with their authors produces 51 database calls. Why?
A.The server has no response caching enabled
B.GraphQL always calls the database once per field
C.The author resolver runs separately for each post
D.The query is missing a record limit argument
Answer: C
This is the N+1 problem: one call fetches the list of posts, then the author field's resolver runs separately for each post. The standard fix is to batch the calls within the same execution round into a single query.
What does a normalized GraphQL client cache use to identify objects?
A.The type name combined with the record's identifier
B.When the response was received
C.The order of the items in the returned list
D.The query string that was sent to the server
Answer: A
It uses the record's type name plus identifier. That way the same object appearing in multiple queries is stored only once, and updating it in one place automatically reflects on every screen displaying it.
Why is cursor pagination preferred over offset pagination in GraphQL?
A.Newly inserted data does not cause items to repeat
B.A cursor reduces how many fields must be returned
C.A cursor needs no index in the database
D.A cursor makes jumping to an arbitrary page easier
Answer: A
A cursor points to a specific position in the result set, so newly inserted records don't shift pages the way offset pagination does. The trade-off is that jumping straight to the tenth page is hard with cursors.
Where should authorisation live in a GraphQL server?
A.In the business layer behind the resolvers
B.Only at the gateway before the query executes
C.In the schema, by hiding the sensitive fields
D.On the client before the query is sent
Answer: A
Put it in the business layer behind the resolver, where both the user and the specific record are known. Checking only at the entry point isn't enough, because it doesn't know whether the user is allowed to see the exact record being requested.
Why does a public GraphQL server need depth and complexity limits?
A.The limits let queries be cached more effectively
B.The parser cannot handle an over-long query
C.The GraphQL specification requires these limits
D.A deeply nested query can overwhelm the server
Answer: D
Because the client decides the query shape, a query nested deeply through bidirectional relationships can grow exponentially and overload the server with a single request.
What benefit do persisted queries bring to a production application?
A.The client no longer needs to know the schema
B.The query results are stored permanently on the server
C.The server rewrites the query for optimization before running it
D.The client sends a hash rather than the whole query document
Answer: D
The client sends a hash of the query instead of the whole document, so requests are lighter. More importantly, the server can accept only registered queries, turning that list into a barrier against arbitrary queries.
What should a mutation return after successfully updating a record?
A.The changed record along with its related fields
B.The whole list containing that record
C.A message string to display to the user
D.A boolean saying whether it succeeded
Answer: A
Return the record that was just changed along with its related fields, so the client can update its cache and UI immediately. With a normalized cache, just the identifier and the changed fields are enough for every screen displaying it to update itself.
C.Any data that must update frequently in the interface
D.Unpredictable events that need pushing immediately
Answer: D
Subscriptions suit unpredictable events that need to be pushed immediately: new messages, price changes, order status. For data that changes on a regular schedule, polling is usually simpler and much cheaper to operate.
How does GraphQL handle API change instead of versioning?
A.Keep several schema versions running side by side on one server
B.Require every client to update at once when the schema changes
C.Create a new endpoint for each schema version
D.Add new fields and mark the old ones deprecated
Answer: D
GraphQL evolves by adding new fields and marking old ones as deprecated, rather than numbering versions. Old clients keep working because the old fields remain, and a field is only removed once nobody queries it anymore.
Why is HTTP caching harder for GraphQL than for REST?
A.GraphQL data always differs per user
B.Every query goes through a single address
C.GraphQL does not allow setting cache headers
D.GraphQL responses are always too large to cache
Answer: B
Because every query goes through a single endpoint and usually uses the POST method, intermediate caches cannot distinguish them. In return, GraphQL pushes caching to the client with normalized object caching.
What is the main benefit of code generation from a GraphQL schema for clients?
A.The client no longer needs a GraphQL library
B.The queries are rewritten to run faster
C.The schema updates itself when the server changes
D.The query's types are checked at build time
Answer: D
Code generation produces exact types for each query, so misspelled field names or wrong types are caught at compile time. Combined with schema checks in the CI pipeline, a breaking change breaks the build instead of breaking the application.
A.Running real queries through the schema and asserting on the results
B.Measuring each query's response time
C.Comparing the schema text against a previously saved copy
D.Calling each resolver function directly in isolation
Answer: A
Run real queries through the schema and compare results, since this covers the schema, resolvers, and business layer exactly as the client will encounter them. Mock the underlying data sources for fast, stable tests.
What is the most robust way to upload an image with GraphQL?
A.Split the file across several small mutations and reassemble on the server
B.Request a signed URL and upload directly to the storage service
C.Embed the file's content as an encoded string in a variable
D.Send the file in a multipart mutation
Answer: B
The most robust approach is to request a presigned URL via a mutation, upload the file directly to storage, then call a second mutation to attach the file to the record. The file never passes through the API server, avoiding size limits and heavy load.
At what level should GraphQL server performance be measured?
A.Per named query and per field
B.By the size of the response returned to the client
C.By the response's HTTP status code
D.By endpoint address as with REST
Answer: A
Measure by query name and by per-field resolution time. Measuring at the endpoint level is meaningless because all queries share one address, and the status code is usually 200 even when the response contains errors.
A.An application with many client types with different needs
B.A simple API with few clients and fixed needs
C.A mobile app needing fewer network round trips
D.A screen needing to combine data from several services
Answer: B
GraphQL is not worth it for simple APIs with few clients and fixed data needs. The cost of the execution layer, caching, query limits, and operational observability is not offset by any clear benefit.
B.A union requires every member to share an identifier
C.An interface does not allow querying a subtype's own fields
D.An interface requires the implementing types to share a set of fields
Answer: D
An interface requires every implementing type to share a common set of fields, so those fields can be queried without knowing the concrete type. A union groups types with nothing in common, so you must use per-type fragments.
What does defining a custom scalar for date and time give you?
A.The ability to compare dates directly in the query
B.Format validation at the schema layer
C.Automatic conversion to the client's timezone
D.A reduction in the data transferred over the network
Answer: B
A custom scalar lets you validate and normalize the format at the schema layer: invalid values are rejected before reaching the resolver, and every client receives the same format instead of each endpoint having its own.
What are the include and skip directives used for?
A.Turning part of a query on or off by a variable's value
B.Removing fields the user is not allowed to see
C.Asking the server to cache that part of the data
D.Marking a field as due for removal in a later version
Answer: A
They toggle parts of a query based on variable values, so one document can serve many cases. This matters for persisted queries, where the number of distinct documents must be kept to a minimum.
The schema handles types and requiredness, while business rules belong in the business layer. The type system cannot express rules like amounts must be positive, coupons must still be valid, or the end date must come after the start date.
What should rate limiting for a GraphQL API be based on?
A.How many distinct fields appear in the query
B.The size of the response returned to the client
C.The number of requests in a time window, as with REST
D.The query's estimated cost rather than the request count
Answer: D
Base it on the estimated query cost, not the request count. A query fetching one record and a query nested three levels deep over a thousand-element list are workloads that differ by thousands of times.
B.The loader needs to know the client's IP address
C.The loader consumes a lot of memory if it lives long
D.The loader stops working when reused several times
Answer: A
The loader caches results by key without knowing about permissions, so sharing it globally would return one user's cached data to another user's request. Creating it per request is a mandatory security boundary.
When should a GraphQL query be sent with GET rather than POST?
A.When using a persisted query so caching can be exploited
B.When a file attachment must be sent with the query
C.When the query has many complex variables
D.When the query changes data on the server
Answer: A
Use GET when combined with persisted queries: the URL becomes unique by hash and variables, so CDNs and intermediate caches can cache it. For long queries written inline, POST is safer because it doesn't hit URL length limits.
A.Sending the mutation repeatedly until it succeeds
B.Skipping the error checking to respond faster
C.Writing the expected result into the cache immediately
D.Preloading data the user might need
Answer: C
The client writes the expected result into the buffer immediately when sending the mutation, so the UI responds instantly. When the server replies, the real data replaces the temporary data; on failure the buffer is rolled back to its previous state.
How do schema-first and code-first approaches differ?
A.Code-first cannot generate documentation for the API
B.One writes the schema first while the other generates it
C.Code-first only works with statically typed languages
D.Schema-first does not support abstract types
Answer: B
Schema-first: write the schema in the definition language, then implement resolvers against it. Code-first: define types in code and the schema is generated. The real difference lies in the source of truth for the contract and how teams collaborate.
A query is slow but the cause is unclear. What helps narrow it down?
A.The endpoint's overall error rate
B.A log recording every query string received
C.A trace of the resolution time per field
D.Figures on the size of the returned responses
Answer: C
Use per-field resolution timing traces: they show which field takes most of the time and how many times it calls the data source, so an N+1 problem or a slow downstream service is immediately visible.
Where should purely UI state such as a selected filter live?
A.In the application's state rather than in the GraphQL cache
B.Send it to the server to store with the user's data
C.In the page address so it can be shared
D.In the GraphQL cache so it all lives in one place
Answer: A
Put it in application state, not in the GraphQL buffer. The buffer is designed for server data with its own refresh and expiry mechanisms, while UI state has a completely different lifecycle.