What is GraphQL?
GraphQL is an opensource Query Language for APIs. It was Created by Facebook in 2012 for use in their Mobile applications. After, it was open sourced in 2015.
“GraphQL is a Query language for your API that shifts the contract between Clients and servers that allows the server to say these are the capabilities that I exposed and allows the clients to describe their requirements in a way that ultimately empower product developers to build the products they want create .” –Dan Schafer, GraphQL Co-Creator.
What are the key concepts of GraphQL Query language?
- Product centric
- Hierarchical
- Strong -typing
- Client-specified queries
- Introspective
Write an example GraphQL Query?
Query looks like:
{
students {
Name
Grade
}
}
The response for the query is given below −
{
“data”: {
“students”: [
{
“Name”: “Jack”,
“Grade”: “A”
},
{
“Name”: “John”,
“Grade”: “A+”
},
{
“Name”: “Nick”,
“Grade”: “B”
}
]
}
}
What is the use of Schema?
GraphQL schema is core part of GraphQL server.All the queries are validated and executed against the schema. the schema describes the possible data that a client can access.
What is use of mutation?
It is used for the write operations. It is used for operations like add, delete and edit data.
What are Enums in GraphQL?
Enums are basically a special type we can use to enumerate all possible values in th field.By using enums we are adding another kind of validation to existing GraphQl schema.
What is the use of SDL?
SDL stands for Schema Definition Language. It is used for writing schemas.
What is a resolver?
A resolver is a function that returns data for a particular field. Resolver functions return data in the type and shape specified by the schema.
What is the use of typeDefs parameter?
It is a required argument. It represents a GraphQL query as a UTF-8 string.
What are big companies using GraphQL?
Facebook, GitHub, Pinterest, twitter, PayPal, Atlassian, Audi, sky, the New York times, shopify, yelp, and more.
What is the difference between overfetching and underfetching?
Overfetching is extra data for an API request It increase payload size. Underfetching is the opposite of overfetching.It means that not enough data is included in an API response. it requires multiple API calls to fetch the complete data.
Can you explain how GraphQL helps in low network area?
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.
What is the use of introspection?
Interospection allow you to ask GraphQl Schema for information about what queries it supports.
What are the different types of introspection?
- _Shema
- _type
- _Typekind
- _field
- _InputValue
- _EnumValue
- _Directive
What are the differences between REST API and GraphQL?
REST API:
- REST is an architectural pattern Concept for Network based Software.
- REST API easy to understand.
- Data fetch: A typical usage of REST API will fetch data by calling multiple API endpoints, and the server will return all data in those endpoints.
- The shape and size of the resource is determined by the server in REST
- In REST, you specify a write by changing the HTTP verb from GET to something else like POST.
- It uses different routes for requests.
- It is server-driven application state.
- REST only communicates on HTTP or HTTPS.
GraphQL:
GraphQL is a Query Language for APIs and set of tools that operate over a single endpoint using HTTP.
- GraphQL is a flexible and easy to backup.
- Data fetch: It uses queries, schema, and resolvers. Developers can specify the exact data thy need, moreover, they can create and execute nested queries.
- In GraphQL, the server declares what resources are available, and client asks for what it needs at the time.
- In GraphQL, you change a keyword in the query.
- In GraphQL, doesn’t have any Routes.
- It is Contract-driven by nature
- GraphQL server communicate over HTTP, HTTPs, TCP, WebSocket, UDP, FTP.
What are some best IDEs and tools for GraphQL APIs?
- GraphiQL-In browser IDE for exploring GraphQL APIs
- GraphCMS-Build a GraphQL content API
- Bit-Opensource tool and reusable code
- Relay-It is a Library for GraphQL.js
- Apollo Client and server-optimize GraphQL Queries
- GraphQL Voyager -For interactive visual Graph
- GraphQL IDE-The GraphQL Playground
- GraphQL Editor- For Backends from GraphQL Schema
- Prisma– Build GraphQL server with Ease
- GraphQL Bindings– For Reusing and Sharing GraphQL APIs
- GraphQL Network- Network-style tab allowing for easy debugging
What are the Pros and Cons of GraphQL?
Pros:
- It is best option for Complex systems and Microservices
- GraphQL Schema
- Fetching data with a single API call
- Autogenerating API Documentation
- Support for real time data
- Code Sharing
- Easy find errors with Clear message
- Rapid application Prototyping
Cons:
- Complex queries
- Learning curve
- Web caching is more complex than with REST
- No leverage from HTTP
- JSON representation only
- File uploading issues
- Schema similarities