Intermediate GraphQL Interview Questions

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

It occurs when resolving a collection causes one additional data-access operation for each item, resulting in excessive database requests.

12. How does DataLoader solve N+1?

It batches multiple requests for related resources and commonly caches repeated loads within the same request.

13. What is a GraphQL fragment?

A fragment is a reusable selection set that allows clients to define a group of fields once and reuse them across operations.

14. What is an inline fragment?

An inline fragment allows a query to select fields conditionally based on the runtime type of an interface or union.

15. What is an alias?

An alias allows a client to give a different response field name to a selected GraphQL field.

16. What are GraphQL variables?

Variables allow dynamic values to be supplied separately from the query document instead of embedding values directly in the query string.

17. What is an input object?

An input object groups structured arguments for queries or mutations and is especially useful for complex mutation inputs.

18. What is the difference between an interface and a union?

An interface defines common fields that implementing object types must provide, while a union represents multiple possible object types without requiring shared fields.

19. Why are mutations usually designed with input objects?

Input objects provide a structured contract that is easier to extend, validate, and evolve than a long list of independent mutation arguments.

20. What is GraphQL introspection?

Introspection allows clients and tools to query metadata about the GraphQL schema itself.

21. What is the purpose of GraphQL directives?

Directives provide metadata or instructions that can influence how fields, selections, or schema elements are handled.

22. What is the difference between authentication and authorization?

Authentication determines who the caller is, while authorization determines what that caller is permitted to access or perform.

23. Where is authentication information commonly placed in a GraphQL server?

It is commonly processed before resolver execution and made available through the GraphQL context.

24. What is cursor-based pagination?

Cursor pagination uses opaque positions representing locations in an ordered result set instead of relying only on numeric offsets.

25. Why can cursor pagination be better for large datasets?

It can provide more stable traversal when records are inserted or removed and can avoid some expensive large-offset database operations.