GraphQL Flashcards

1
Q

What is GraphQL?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What was the reason behind the development of GraphQL?

A

GraphQL was initially developed by Facebook as an internal solution for their mobile apps. It was designed to optimize RESTful API calls and provide a flexible, robust, and efficient alternative to REST. It is not a replacement for REST. It is an alternative to writing APIs using REST.

After its release, it has become prevalent among developers and is also a popular solution for building web services along with REST.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the top companies that use GraphQL?

A

There are many big organizations such as Facebook, Github, Pinterest, Intuit, coursera, shopify, dailymotion, yelp etc. that uses GraphQL. Actually GraphQL was designed and developed by Facebook itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How GraphQL utilizes the data loading process?

A

When the users fetch the data in GraphQL, it retrieves only the minimum amount of data required by the client.
Even if the object model contains a lot of fields, the client can request only the required fields.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the similarity of Graph database and GraphQL

A

Fundamentally, there is no relationship. Besides the fact that GraphQL and graph databases have the word “graph” in their name, they were designed for two entirely different purposes.

GraphQL, the query language, was created to make it easier for app developers to fetch data by asking specifically for what they want, while graph databases were designed to allow for performant analysis of relationships between entities.

The main advantage I can think of for using a graph database as a data source is a shared mental model between edges, nodes, and properties between GraphQL and graph databases. You can model your GraphQL schema similarly to how we think about graph databases’ main abstractions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Is GraphQL only suitable for React / JavaScript Developers?

A

No. It is not correct to say that GraphQL is only for React or JavaScript Developers. GraphQL is a cross-platform, open-source data query, and manipulation language for API technology, so it can be used in any scenario where API technology is required.

On the backend, the GraphQL servers are available for multiple languages such as Java, Python, .NET, C#, PHP, R, Haskell, JavaScript, Perl, Ruby, Scala, Go, Elixir, Erlang, and Clojure, etc. So, it can be implemented with any programming language and framework to build a web server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the reasons behind using GraphQL while we already had an API named REST?

A

Yes, we already had an API called REST for data communication, which follows a clear and well-structured resource-oriented approach. It also provides some great ideas such as stateless servers, structured access to resources, etc. But, REST is not so flexible to cope up with the rapidly changing requirements of the clients. In that case, when the data gets more complex, the routes get longer. Sometimes, 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 cope up with the REST’s limitations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How GraphQL facilitate developers to choose protocols other than HTTP to implement your server?

A

The GraphQL API is usually operated over HTTP, and it is a transport layer agnostic technology, so you can choose protocols other than HTTP to implement your server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Authentication and Authorization in GraphQL?

A

Authentication and Authorization are the processes used in services.
Sometimes people get confused in these two terms and exchange their definitions for each other.

Authentication:
Authentication is a process that is used to claim an identity. Authentication is done when you want to log in to a service with a username and password. Here, you have to authenticate yourself. In GraphQL, Authentication can be implemented with common patterns such as OAuth.
OAuth is an open protocol that is used to allow secure Authorization in a simple and standard method from web, mobile, and desktop applications.

Authorization:
On the other hand, Authorization is a process that is used to give permission rules that specify the access rights of individual users and user groups to certain parts of the system. For authorization implementation in GraphQL, it is recommended to delegate any data access logic to the business logic layer and not handle it directly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How to do Error Handling in GraphQL?

A

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”: [ … ]
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to do Server-side Caching in GraphQL? How is it different from REST?

A

The biggest concern with GraphQL technology is that it is difficult to maintain the server-side cache compared to the REST. In REST API, we can easily cache data for each endpoint. This is because the structure of the data does not change. On the other hand, in GraphQL API, it’s not clear what the client will request next, so it does not matter to put a caching layer right behind the API. That’s why doing Server-side Caching difficult in GraphQL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to be cache in server side of Apollo?

A

Using cacheControl

votes: Int @cacheControl(maxAge: 30)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What type of response you get after a GraphQL query?

A

In GraphQL, when a client requests a query, the server returns the JSON format response. The response returned by the server is based on the query the client uses for the request.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is Over-fetching in GraphQL?

A

Over-fetching is a response where the client gets too much data or extra data for an API request. In over-fetching, you have a lot of additional data in the response you don’t use. Over-fetching unnecessarily increases the payload size.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Under-fetching?

A

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 second endpoint to fulfill your request or multiple API calls to fetch the complete data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How GraphQL fixes the issues of Over-Fetching or Under-fetching?

A

Over-Fetching and Under-fetching both are the performance issues that can be solved by using GraphQL. You won’t see these problems if you have precisely the right endpoints to give your products exactly the correct data. These problems occur when you have to maintain multiple endpoints to get the exact right data. It has increased the data load, which finally results in a performance issue.

GraphQL resolves this issue because it facilitates you to request the specific data which you want from the server. Here, you can specify what you need in a single request and get the exact result that you need in just one response from the server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the most significant advantages of using GraphQL over REST?

A

A list of the most significant advantages of using GraphQL over REST:

There is only one endpoint in GraphQL, but REST has multiple endpoints. That’s why GraphQL is more cost-effective than REST. You don’t have to use your resources for various endpoints.
In REST API, you have to use multiple requests to retrieve a complex data-set, but in GraphQL, you can execute a complex query easily in just a single request.
You can change the request data format in GraphQL, but it is not possible to do the same in REST.
The development speed in GraphQL is faster than REST.
GraphQL provides high consistency across all platforms, while In REST, it is hard to get consistency across all platforms.
GraphQL doesn’t support an automatic caching system, while REST uses caching automatically.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Is REST also a query language like GraphQL?

A

No. REST is not a query language like GraphQL. It is a web service API.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Is it true that we can use GraphQl only with the SQL database?

A

No. GraphQL is a query language for APIs that can be used with any SQL or NoSQL databases.

20
Q

What is SDL, and what is the use of it?

A

SDL is an acronym that stands for Schema Definition Language. It is used for writing schemas. SDL is the language that is used to write GraphQL schemas.

21
Q

Can GraphQL API be used to handle offline usage?

A

GraphQL is a query language for web APIs that is designed only to work online. The caching abilities of some GraphQL libraries such as Relay and Apollo can be used for some cases, but there is not any proper offline solution developed or available yet.

22
Q

What do you know about GraphiQL?

A

GraphiQL is used to provide UI representation for GraphQL. It is an in-browser IDE used to explore GraphQL and make GraphQl usage easy. GraphQL supports real-time error highlighting, so you can see and handle errors easily.

23
Q

Does GraphQL support server-side caching like REST?

A

No. GraphQL doesn’t support server-side caching like REST.

24
Q

What are the main operations that GraphQL supports?

A

GraphQL supports three 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 after any data changes, if the client is subscribed to that event.

25
Q

Can queries be used to modify data?

A

Yes. Queries can be used to modify server-side data. But according to the conventional method, it is the best practice to use mutation for any write operation.

26
Q

What is Apollo in GraphQL?

A

Apollo is a platform for the implementation of GraphQL. As we know that GraphQL is a query language, so in order to use this query language easily, we need a platform, Apollo provides that platform.

Apollo provides two open-sourced libraries to create clients and servers. Here, the client is used to fetch data from a GraphQL server, and the server is used to create an API for the GraphQL client.

27
Q

What do you know by Mutation in GraphQL?

A

Mutation is one of the most important operations in GraphQL. It is used for write operation when you want to add delete and edit data.

28
Q

What is subscription in GraphQL?

A

In GraphQL, the subscription is used for listening to any data changes. The server sends a notification message to the client after any data changes, if the client is subscribed to that event.

29
Q

What do you mean by a Query in GraphQL?

A

A GraphQL query is used to read data. It is similar to the GET request we use in REST APIs. The GraphQL queries are used to retrieve data from the GraphQL server.

30
Q

What do you know by Fields in GraphQL?

A

The keys of an object that are used in the GraphQL query are known as Fields.

For example:

{
employee{
name
salary
}
}

In the above query, ‘name’ and ‘salary’ are fields.

31
Q

What is the use of object types in GraphQL?

A

The resources that are accessed by a client is called Objects. Objects can contain a list of GraphQL fields.

32
Q

What is the use of an interface in GraphQL?

A

In GraphQL, an interface is used to list down the common fields of a GraphQL object. Other objects can use this interface to inherit properties.

33
Q

What is the union in GraphQL?

A

In GraphQL, sometimes we have to represent multiple objects, that’s why the union is used. The user can define more than one type as return type using a union.

34
Q

What is the use of Enums in GraphQL?

A

The enum or enumeration type in GraphQL is a special kind of scalar used to define a type, including a list of allowed values.

35
Q

What is the use of resolver in GraphQL?

A

In GraphQL, a resolver is used to handle queries and produce a response to the GraphQL query.

36
Q

What do you know by arguments in GraphQL?

A

The arguments are used in GraphQL Queries and Fields when we want to request specific data.

For example:

{
employee(id: “001”){
name
salary
}
}

In the above query, the ‘id’ is an argument passed to return the ‘name’ and ‘salary’ of ‘employee’ where we want specific data with ‘id’ equals to ‘001’.

37
Q

What do you know by a non-null type modifier in GraphQL?

A

In GraphQL, a non-null type modifier is used to specify an argument as non-null value. If you pass null for a non-null argument, the GraphQL server will send a validation error. The exclamation mark “!” is used to mark an argument as non-null.

38
Q

What do you mean by aliases in GraphQL?

A

In GraphQL, the alias is used to change the field name of the query. It facilitates you to rename the result of a field according to yourself.

For example:

{
classA : employee(id : String){
name
}
classB : employee(id: String){
name
}
}

In the above query, we have used an alias to use a different name for two ‘employees.’ Without an alias, you will get an error in the result.

39
Q

What do you understand by Fragment in GraphQL?

A

In GraphQL, the fragment is used when the query is very large, and your query contains the reusable units. You can create a fragment by taking the reusable part and use that fragment in the query. The fragment concept was designed to arrange the code in a simple way and avoid duplicate code.

40
Q

What do you understand by GraphQL Voyager?

A

GraphQL Voyager is an open-sourced library used to represent any GraphQL API to an interactive graph.

41
Q

What is the use of the validation step in GraphQL?

A

The validation step is a crucial step in GraphQL. It is used to check whether a GraphQL query is in a valid format or not. If it gets that the query is invalid, it informs on the client-side before the runtime check.

42
Q

What is the use of the execution step in GraphQL?

A

The execution step is used to execute a query in GraphQL. This step comes and executes after the validation step.

43
Q

How can you host a GraphQL server online?

A

You can use any programming language such as Node.js or Python to create a GraphQL server and host it the same as any other servers.

44
Q

What do you know about the Remote Schemas in Apollo GraphQL?

A

The Remote schemas are used to create GraphQL schema objects that delete to a separate remote server.

45
Q

What is the use of Schema stitching in Apollo?

A

Schema stitching is used to merge or combine multiple GraphQL APIs into a single API.