GraphQL Tutorial#6 : 51 Most Imp GraphQL Interview Questions and Answers
To conclude our 5 Articles Series on GraphQL, here we are providing 51 Most Important and Frequently Asked GraphQL Interview Questions. These questions will be very useful for you to crack an interview and help you to make a career in GraphQL.
GraphQL Tutorial Index:
- GraphQL Tutorial #1 -Introduction
- GgraphQL Tutorial #2 – Setting Basic Project in GraphQL
- GraphQL Tutorial #3 – GraphQL Components
- GraphQL Tutorial #4 – GraphQL Operations
- GraphQL Tutorial #5 – Introduction to Apollo GraphQL
- GraphQL Tutorial #6 – 51 Most Important GraphQL Interview Q&A
GraphQL Interview Questions:
1. What is GraphQL
GraphQL is a query language. It is used for APIs and includes the runtime for executing these queries.
2. Which company has started the development of GraphQL?
Facebook has started the development of GraphQL in 2012. But it was open sourced only in 2015.
3. Name a few companies that use GraphQL
GraphQL is used by many big organizations like Github, Facebook, Pinterest, Intuit, coursera, shopify, dailymotion, yelp etc.
4. What is a query language?
In simple words, a query language uses queries to fetch data from a database. GraphQL is a query language and it uses queries for APIs.
5. Do you think that GraphQL is a database technology?
GraphQL is not database technology. GraphQL is a query language used for APIs, it is not a query language for database. GraphQL can be used with any database or even without a database.
6. What is the type of response of a GraphQL query?
GraphQL queries return a JSON response. The response is based on the query we are using in the request.
7. Name a few languages that can be used to implement GraphQL server.
GraphQL server can be implemented in many languages including JavaScript, Python, Java, PHP, Haskell, Ruby, C#, Scala, Go, Elixir, Erlang, R, and Clojure.
8. How GraphQL helps in data loading process?
GraphQL can provide 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. It
9. How GraphQL helps in low network areas?
A client can request only the required data in GraphQL. It makes the payload size smaller than any other network request. In low network areas, small payload network requests can be executed faster.
10. What is overfetching?
Overfetching means fetching extra data for an API request. Overfetching increases payload size.
11. What is underfetching?
Underfetching means not fetching enough data. Underfetching requires multiple API calls to fetch the complete data.
12. How GraphQL solves over and under fetching problems?
With GraphQL, we can modify our query to fetch only the required values. GraphQL queries can fetch all the data in a single request.
13. Name three advantages of using GraphQL over REST
a) GraphQL uses only one endpoint but REST has multiple endpoints.
b) REST requires multiple requests to retrieve a complex data-set, but in GraphQL we can execute complex queries easily.
c) We can change the request data format in GraphQL, but we can’t do that in REST.
14. Give three difference of GraphQL and REST
a) GraphQL is a query language, but REST is not
b) REST uses different routes for different requests, but GraphQL doesn’t have any routes.
c) GraphQL uses query, mutation and subscription but REST uses GET, PUT, POST, DELETE and PATCH.
15. GraphQL can be used only with React.js. Is it true? If not, why?
No, it is not true. GraphQL and React.js were developed initially by Facebook but GraphQL can be used with many other programming languages.
16. GraphQL can be used only with SQL. Is it true?
It is not true. GraphQL is a query language for APIs. We can use any database that we want.
17. What is the full form of SDL?
SDL stands for schema definition language.
18. What is the use of SDL?
SDL or schema definition language is used for writing schemas. This is the language that we use to write GraphQL schemas.
19. Does GraphQL handle offline usage?
GraphQL is designed only to work online. Few libraries can provide cache, but any proper offline solution is not developed yet.
20. What is GraphiQL?
GraphiQL is an in-browser IDE for exploring GraphQL. We can test a GraphQL query and mutation in the browser using [GraphiQL.](http://graphiql.It) It also supports real-time error highlighting.
21. Does GraphQL support server-side caching?
No, GraphQL doesn’t support server-side caching.
22. What are the operations GraphQL supports?
GraphQL supports query, mutation and subscription. Queries are used for the read operation, mutation is for a write operation and subscription is used to listen for any changes.
23. What is Query?
A query is used to read data. Similar to the GET request of REST APIs, we can fetch data from a GraphQL server using a query.
24. What is mutation ?
Mutation is used for the write operation. A mutation is used for operations like add, delete and edit data.
25. What is subscription ?
Subscription is used for listening to any data changes. The server will notify the client on any data change if the client is subscribed to that event.
26. Can we use queries to modify data ?
We can use queries to modify server-side data. But by convention, it is suggested to use mutation for any write operation.
27. What are Fields ?
Fields are ‘key’s of an object that we use in a GraphQL query. For example :
1 2 3 4 5 6 |
{ student{ name age } } |
In this query, ‘name’ and ‘age’ are fields.
28. What are arguments?
With a GraphQL query or mutation, we can pass one argument to request for specific data based on it. For example :
1 2 3 4 5 6 |
{ student(id: "100"){ name age } } |
Here, we are passing the ‘id’ as an argument. It will return the ‘name’ and ‘age’ of ‘student’ with ‘id’ equals to ‘100’.
29. How can you use variables in a query ?
Instead of writing arguments in a query string, we can use variables and pass any arguments to these queries directly. For example :
1 2 3 4 5 6 |
query studentQuery($id : Int) { student(id : $id){ name } } |
In this example, we can pass one new variable each time.
30. What are default variables?
We can add a default value to a variable in a query.
query studentQuery($id : Int = 100)
…
…
We can call the query without passing a variable if the default variable is used.
31. Where __typename is used ?
__typename is a meta field. If the client doesn’t know the type getting back from a GraphQL service, GraphQL allows us to use __typename to get the name of the object type.
32. What is a non-null type modifier in GraphQL?
Non-null type modifier is used to define an argument as non-null. The GraphQL server will send one validation error if we pass null for a non-null argument. “!” sign is used to mark one argument as non-null.
33. What is an aliases? Explain it with one example.
Using aliases, we can change the field name of a GraphQL return JSON. For example :
1 2 3 4 5 6 7 8 |
{ classA : student(id : String){ name } classB : student(id: String){ name } } |
Here we are using an alias to use different name for two ‘student’. Without alias, it will show one error.
34. What is Fragment ?
If our query is large and we have reusable units in the query, we can create fragment by taking the reusable part and use that fragment in the query. It helps us to arrange the code and also to avoid duplicate code.
35. What are the scalar types that GraphQL supports?
GraphQL supports five scalar types: Int, Float, String, Boolean and ID.
36. What is graphql voyager ?
GraphQL voyager is an open sourced library to convert any GraphQL API to an interactive graph.
37. What are object types in GraphQL ?
Objects are resources that a client can access. It can contain a list of GraphQL fields.
38. What is an interface in GraphQL ?
Interface is used to list down common fields of a GraphQL object. Other objects can inherit these properties from an interface.
39. What are unions in GraphQL ?
Union is used to represent multiple objects in GraphQL. We can define more than one type as return type using union.
40. Can you use Enums in GraphQL ?
We can use enums or enumeration type in GraphQL. It is a special kind of scalar that allows us to define a type including a list of allowed values.
41. Can we implement authentication in GraphQL ?
We can implement authentication like OAuth in GraphQL.
42. What is Apollo ?
Apollo platform is an implementation of GraphQL that includes two open sourced libraries to create client and server. The client is used to fetch data from a GraphQL server and the server is used to create an API for GraphQL client.
43. Does Apollo supports caching ?
Apollo library supports caching.
44. Name one GraphQL library to use with an Android and iOS application.
Apollo can be used as a client with both Android and iOS.
45. What is the validation step in GraphQL ?
Validation step is used to check wheather a GraphQL query is in valid format or not. It can inform on the client side if a query is invalid before the runtime check.
46. What is the execution step in GraphQL ?
Execution step is used to execute a GraphQL query. This step runs after the validation step.
47. Name one GraphQL library for python, java and javascript each.
Python : Graphene
JavaScript : express-graphql
Java : graphql-java
48. How can we host a GraphQL server online ?
We can create GraphQL server on any programming language like Node.js or python. We can host it like any other servers.
49. What is a resolver ?
Resolver is used to produce a response to a GraphQL query. Resolver is used to handle queries.
50. What are Remote Schemas in Apollo ?
Remote schemas are used to create GraphQL schema objects that delete to a separate remote server.
51. What is Schema stitching in Apollo ?
Schema stitching is used to combine multiple GraphQL APIs into one single API.
Tutorial Index:
- GraphQL Tutorial #1 -Introduction
- GgraphQL Tutorial #2 – Setting Basic Project in GraphQL
- GraphQL Tutorial #3 – GraphQL Components
- GraphQL Tutorial #4 – GraphQL Operations
- GraphQL Tutorial #5 – Introduction to Apollo GraphQL
- GraphQL Tutorial #6 – 51 Most Important GraphQL Interview Q&A