In this article, we have covered the basics of graphql like: the terminologies, advantages & disadvantages, history and what is apollo-graphql.
Basics of GraphQL
Instead of having the server deliver a predetermined set of data, GraphQL is an excellent approach to let the client choose the data they wish to be transferred over the network.
GrpahQL Terminologies
Schemas
Developers of APIs use GraphQL to build a schema that lists all the potential data that users of the service may query.
Object types make up a GraphQL schema and specify the kinds of objects that can be requested as well as their fields.
Queries
GraphQL checks the queries against the schema as they come in. The verified requests are then carried out by GraphQL.
Resolver
In GraphQL, a resolver is a function which populates the data for a field in our schema. It can populate that data in any way we define, for example it can be by fetching the required data from a backend database or a third-party API.
GraphQL History and Open Source Adoption
Facebook created GraphQL, which it used for mobile applications for the first time in 2012. In 2015, the GraphQL specification became open source. These days, the GraphQL Foundation is in charge of it.
GraphQL is used in a wide range of open source applications. GraphQL adoption efforts are included in the following list, which is not exhaustive.
- Apollo: A GraphQL platform that consists of the frontend client library (Apollo Client) and backend server framework (Apollo Server).
- Offix: An offline client that permits the execution of GraphQL mutations and queries even when an application is not accessible.
- Graphback: A command-line tool for creating Node.js servers with GraphQL support.
- OpenAPI-to-GraphQL: A command-line interface and library for converting OpenAPI Specifications or Swagger-described APIs into GraphQL.
Advantages of Using GraphQL
- In a GraphQL application, a GraphQL schema establishes a single source of truth. It gives an organisation a method to federate all of its APIs.
- Calls to GraphQL are processed in a single round trip. Client requests are fulfilled without any overfetching.
- Data types are strongly defined , which reduces the miscommunication between client and the server.
- GraphQL supports introspection. A customer may ask for a list of the available data types. This is ideal for generating documentation automatically.
- There are numerous free and open source GraphQL extensions that provide functionality not found in REST APIs.
- No particular application architecture is required by GraphQL. It is compatible with current API management tools and may be added on top of an existing REST API.
Disadvantages of GraphQL
- For developers accustomed to REST APIs, learning GraphQL involves a steep curve.
- Because GraphQL places a large portion of the effort of a data query on the server, server developers must deal with additional complexity.
- GraphQL could need different API management techniques than REST APIs, depending on how it is implemented, especially when taking into account rate limiting and pricing.
- Compared to REST, caching is more complicated.
- The added responsibility of creating maintainable GraphQL schema falls on API maintainers.
What is Apollo GraphQL
- Apollo is a team or community who provide us tools, using those tools it is very seamless to adopt graphql then.
- Mainly there are 3 tools provided by apollo community: Apollo Client, Apollo Server, Apollo Engine.
- Apollo Client: Apollo client helps us consuming a GraphQL API response, with support for the most popular frontend web technologies including React, Vue, Angular, Ember, Meteor and more, and native development on iOS and Android.
- Apollo Server: This is the server part of GraphQL, which interfaces with our backend and sends responses back to the client requests. This is a library that connects our GraphQL Schema to a server through the use of other popular HTTP servers like Lambda, Hapi, Koa, Express, and Connect.
- Apollo Engine: This is available as SAAS and serves as a bridge between the client and our server. It provids several functionalities for our application like: caching, performance reporting, load measurement, error tracking, schema field usage statistics, historical stats etc. It is the only part of Apollo that’s not open source and free yet. It’s currently free up to 1 million requests per month.