Do you know about REST (Representational State Transfer)?
Then you will be very pleased to learn about GraphQL.
GraphQL was originally developed in 2012 at Facebook and open-sourced. It is a query language for APIs that provides a more efficient, powerful and flexible alternative to Rest.
About every application today have the need to fetch data from a database stored on a server. It is the responsibility of the API to provide an interface to the stored data that fits the application’s need. In fact, APIs defines how a client can load data from a server
GraphQL enables declarative data fetching where a client can specify what data it requires from an API, not lots of endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and communicate exactly the data a client asked for.
This unique attribute towers GraphQL over its counterparts, for which you would typically gather the data by accessing multiple endpoints. Which would most definitely result to over/under fetching.
GraphQL is versatile and not tied to a specific database or storage tool engine but is backed by existing codes and data provided by every single user.
The community of users of GraphQL is rapidly growing. Today, GraphQL is used in production by lots of different companies such as Cousera, GitHub, Twitter, Yelp and Shopify — to name only a few. It is a technology that can be used everywhere a client communicates with an API.
Features
1. Aggregate data from multiple UI components.
2. Create a graphical representation of your data that feels familiar and natural.
3. Ensure that all of your data is statistically compiled and these types inform what queries the Schema will adopt.
4. Utilize a built in mechanism for depreciations when you need to.
5. Access to a stable and reliable tooling ecosystem with GUIs, editor integrations, code generation, analytics etc
Types of GraphQL
1. GraphQL Object Type: This GraphQL has both query and mutation variants and are special because they define the entry of every GraphQL query.
2. Scalar Type: while the object type has a name and field, scalar type comes in as the need to resolve some concrete data erupts. GraphQL comes with some set of default Scalar Types but it is up to users implementation and specifications.
3. Enumeration Type: It is fondly called Enums and these are special kinds of Scalar that is restricted to a particular set of values. The Enumeration Types allow user to validate argument and communicate through the type system.
Object Types, Scalar and Enums are the only kinds of types you can define in GraphQL but in other query variables, additional type modifiers includes
List and non-null type
Interface type
Union type
Input type.