Skip to main content
Contact Us 1-800-596-4880

What is GraphQL? An introduction

GraphQL is a query language for APIs. The APIs that provide a GraphQL interface to query data are called GraphQL APIs. They provide an easy-to-use interface to query data from different sources in a single API call.

GraphQL was initially developed by Facebook to overcome the challenges it faced with its existing REST APIs (~2012). The company open-sourced the query language in 2015 and is now managed by the GraphQL Foundation. Today, many people have implemented the specification in different programming languages. Most common programming languages support it.

GraphQL is a relatively new technology with significant promise and growing adoption. It is very popular among React developers.

 

GraphQL vs. REST vs. SQL

People often debate whether GraphQL vs. REST is the better programming methodology. While both GraphQL and REST are good interfaces to APIs, this is not an apples to apples comparison.

There is also debate about GraphQL vs SQL. Again, both are excellent options to query data but serve different purposes. GraphQL is best suited for the web due to its JSON friendliness and Javascript like syntax.

You can find a complete GraphQL ecosystem, including tooling, customers, and companies, in the GraphQL Landscape.

Challenges that GraphQL addresses:

#1: Enables the use of multiple endpoints

Customers can have hundreds of APIs and a single data request might span across accessing 10-20 APIs and too many requests. GraphQL provides a single endpoint for querying data across multiple data sources. This way, front-end developers can easily get data and build fast. 


#2: Prevents over-fetching data

Traditional APIs return data in a specific data format. Due to this reason, you often end up getting fields that you do not need. GraphQL also lets you pre-define what JSON format is the data needed in. This way, only the data you need is returned with your request.

This means that your applications perform faster. This is an important factor for slow internet devices, like mobile phones.


#3: Simple versioning

Tradition APIs have challenges with versioning and backward compatibility. This is because the versions need to be passed in the endpoint itself (like “/v1/”) or headers. GraphQL only returns the data that's explicitly requested, so new capabilities can be added easily.


#4: Easily access (relational) data

Traditional way of obtaining relational data from a data source involves writing SQL queries and joining data across different tables. This is difficult with nested data with parent-child relations. GraphQL makes it simple to query data using web standards. This way, you do not need to be an SQL expert to access the data. 


#5: Integration

GraphQL provides an easy-to-use interface to query data from different data sources in a single API call. However, accessing data from different data sources requires robust connectivity and performance that scales. MuleSoft can serve as an integration layer between your systems and the GraphQL API you expose.

Another solution is to create a data graph on top of your application network and expose it as a GraphQL endpoint. This single endpoint is created using a graphical builder through which APIs can be linked together in a data graph based on the relationships existing between them. Consumers can then query this single endpoint using a visual query builder, where they can select the fields they need for their project. 

API federation allows organizations to define data relationships between APIs in their application network and automatically generate a GraphQL endpoint to access the data. This way, developers can quickly get an alternative way to access data from the application network.
 

To get a more in-depth overview of the application network, download our whitepaper.

Try Anypoint Platform for APIs