API / GraphQL Interview Questions
1. What is GraphQL?
GraphQL is a new API standard designed and developed by Facebook. It is an open-source server-side technology that is now maintained by a large community of companies and individuals worldwide. It is also an execution engine that works as a data query language and used to fetch declarative data. ...
2. Is GraphQL based on Database Technology?
No. GraphQL is not a Database Technology. GraphQL is data query and manipulation language for APIs - not databases.
3. How GraphQL uses the data loading process?
When the users fetch the data in GraphQL, it retrieves only the minimum amount of data that is required by the client. Even if the object model contains a lot of fields, the client can request only the required fields.
4. Advantages of GraphQL over REST API.
REST is not so flexible to cope up with the rapidly changing requirements of the clients. When the data gets more complex, the routes get longer. Often, it is challenging to fetch the data with a single request. That's why Facebook takes a step to develop a new API technology named GraphQL to cop...
5. What is Over-fetching in GraphQL?
Over-fetching is a response where the client gets extra/additional data for an API request that the client won't use. Over-fetching unnecessarily increases the payload size.
6. What is Under-fetching in GraphQL?
Under-fetching is a response where the client doesn't get enough data. The under-fetching response doesn't have enough data with a call to an endpoint, so you have to call a another endpoint to fulfill your request or multiple API calls to fetch the complete data.
7. How to perform Error Handling in GraphQL?
A successful GraphQL query is supposed to return a JSON object with a root field called "data" . If your request query fails or partially fails, you will see a second root field called "errors" in the response. { "data" : { ... }, "errors" : [ ... ] }
8. What type of response you get using a GraphQL query?
In GraphQL, when a client requests a query, the server returns the JSON format response based on the query the client uses for the request.
9. Advantages of GraphQL.
GraphQL Simplifies API Development: Unlike REST which uses a different endpoint for each resource, a GraphQL API only needs to use one. Reducing the number of endpoints simplifies the development process. Fetching becomes easier as you do not have to make calls to many endpoints to fetch a set of...
10. Disadvantages of GraphQL.
Error Handling Complexity: The GraphQL queries always return a HTTP status code of 200, regardless of whether or not that query was successful. If your query is unsuccessful, your response JSON will have a top-level "errors" key with associated error messages and stacktrace. This can make it much...
11. Explain GraphQL Schema.
A schema is like a contract between the server and the client . It defines what a GraphQL API can and can't do, and how clients can request or change data. It's an abstraction layer that provides flexibility to consumers while hiding backend implementation details. A GraphQL Schema Definition Lan...
12. name: String! Is this a valid field type in GraphQL?
Yes, name is a String type and ! denotes that name cannot be null .
13. What does an exclamation mark after a field's type indicate in GraphQL?
An exclamation mark after a field's type marks it as non-nullable .
14. What is SDL in GraphQL?
Schema Definition Language (SDL) is used for writing schemas. SDL is the language that is used to write GraphQL schemas.
15. What are the main operations that GraphQL supports?
GraphQL supports 3 types of operations: query, mutation, and subscription . The query is used for the request, and it is a read operation, the mutation is used for write operations, and subscription is used for listening for any data changes. The server sends a notification message to the client ...
16. What is a mutation in GraphQL?
A Mutation is a GraphQL Operation that allows you to insert new data or modify the existing data on the server-side. You can think of GraphQL Mutations as the equivalent of POST, PUT, PATCH and DELETE requests in REST.
17. Difference between a mutation and a query in GraphQL.
In GraphQL, mutations are used to write or change data, while queries are used to read data. Queries are used for operations that do not have side effects, such as data retrieval, while mutations are used for operations that can modify data (CRUD operations), such as those that create, update, or...
18. What are scalar types in GraphQL?
Scalar types are basic atomic data types in GraphQL that represent single values. They include types like String for text, Int for integers, Float for floating-point numbers, Boolean for true or false values, and ID for unique identifiers. Scalars are used to represent the leaves of the GraphQL q...
19. What is an exclamation point (!) in GraphQL?
In GraphQL, an exclamation point (!) indicates that a field in a query or a field argument is non-nullable. This means that the field must contain a value and cannot be empty. When used with a field, it ensures that the server always returns a value that is not null. When used with a field argume...
20. What are resolvers in GraphQL?
In GraphQL, each schema field corresponds to a function known as the resolver. The resolver returns the value for a given field in an operation. Resolvers provide instructions on how to compute or retrieve data from the server or other sources. They are a crucial part of implementing GraphQL serv...
21. Supported GraphQL Data types.
GraphQL provides five standard scalars, String, Int, Float, Boolean, and ID.
22. How is GraphQL different from REST?
Single endpoint instead of multiple endpoints Client controls data shape No over-fetching or under-fetching Strongly typed schema
23. What are the main components of GraphQL?
Schema Queries Mutations Resolvers
24. What is a Subscription in GraphQL?
Subscriptions allow real-time data updates using WebSockets.
25. What is N+1 Problem in GraphQL?
The N+1 problem occurs when nested resolvers trigger excessive database queries. It can be solved using batching tools like DataLoader.
26. What is DataLoader?
DataLoader is a utility for batching and caching database requests to improve performance.
27. What is Schema Stitching?
Schema stitching allows combining multiple GraphQL schemas into one unified schema.
28. What is Federation?
Federation is an architecture where multiple GraphQL services collaborate to form a single graph.
29. How is Error Handling done in GraphQL?
Errors are returned in a dedicated "errors" field in the response without breaking the entire query.
30. Is GraphQL strongly typed?
Yes, GraphQL uses a strongly typed schema, enabling validation and better tooling support. test
31. What are Directives in GraphQL?
In GraphQL, directives are annotations prefixed with the @ symbol that provide instructions to the GraphQL engine on how to handle specific parts of a schema or operation. They act as "syntax sugar" or metadata that can modify runtime behavior, execution logic, or type validation. Categories of D...
32. What is the difference between Schema Stitching and Federation?
Schema Stitching: A manual process of merging multiple GraphQL APIs into a single gateway. Federation: A more automated and declarative architecture (popularized by Apollo Federation) that allows different teams to own separate parts of a unified "supergraph".