Field Selection and Over-Fetching
When a mobile client needs only a user's name and the first two friends' names, which GraphQL feature directly reduces over-fetching compared with REST endpoints that return fixed user representations?
- Requesting exactly needed fields and nested lists in one call using selection sets and arguments (e.g., user { name friends(first: 2) { name } })
- Issuing multiple HTTP/2 multiplexxed requests to the same REST resource
- Using a wildcard path like /users/*/compact to trim the payload
- Sending a PATCH request to specify a sparse response body
- Relying solely on server-driven pagination to reduce fields
Caching Semantics
If a client sends a GraphQL POST query like { posts { id title author { name } } } through a CDN, which statement best explains how caching behavior typically differs from a REST GET /posts for the same data?
- GraphQL POST responses are not automatically cacheable by standard HTTP caches, so enabling CDN caching usually requires using GET with a hashed or persisted query and proper cache headers
- All POST responses are cached by default by intermediaries if the body is JSON
- GraphQL always forbids any caching to avoid stale data
- REST resources cannot be cached because their URLs change per client
- ETags are fundamentally incompatible with GraphQL and therefore never usable
Schema Evolution Without Versions
When adding an optional middleName field and planning to retire a legacy nickname field, what approach aligns with GraphQL practices compared with common REST versioned endpoints?
- Expose the new field alongside existing ones, mark the legacy field as deprecated in the schema, and evolve without creating a /v2 endpoint
- Immediately remove the legacy field and return 410 Gone for existing clients
- Create a new /v2 schema with different type names and move all clients at once
- Depend on Accept: application/vnd.api+json;v=2 content negotiation for vershioning
- Force clients to request all fields so that additions are always backward-compatible
Partial Data and Errors
When a query returns a list of products and one nested price field fails to resolve, which GraphQL response pattern is expected compared with typical REST status-code semantics?
- Return HTTP 200 with a data object containing the successful fields and an errors array that describes the failing price field
- Return HTTP 500 and omit the response body to avoid leaking details
- Return HTTP 404 because one nested field was not found
- Return HTTP 204 No Content and include errores in a custom header
- Return HTTP 207 Multi-Status with separate payloads per field
Avoiding the N+1 Problem
Given a query that requests users with their posts and each post's comments, which backend technique helps a GraphQL server avoid the N+1 problem that naive field-by-field fetching would cause?
- Batch and cache data fetches within the request so that many field resolutions are coalesced into fewer backend queries
- Rely on defining GraphQL fragements, which automatically merges database calls
- Use PUT instead of GET for the query operation to reduce round trips
- Disable nested selections so only top-level fields can be fetched
- Execute all resolvers in strict sequence to guarantee consistency