Implementation of GraphQL using Anypoint DataGraph                                                                      

January 04, 2023

Blogger Image

Karnam Dinesh Kumar

Software Engineer

MuleSoft Anypoint DataGraph leverages GraphQL to enhance the consumption of APIs. With Anypoint DataGraph, MuleSoft customers can consume data from multiple APIs in a single request. To achieve this, we can compose a data service by unifying data across all the APIs into one unified schema without writing any code. Developers will be able to query the requests as they do it in GraphQL. They will also be able to select the fields they need and get results in just one query.

GraphQL is a syntax for requesting data. It’s a query language for APIs. GraphQL provides a complete and understandable description of the data in your API and gives clients the power to ask for exactly what they need and nothing more, making it easier for APIs to evolve and enabling powerful developer tools.

REST APIs, as we all know, work in a request and response manner - you ask them for some information, and they give you every possible answer that it has, and they are designed to capture the capabilities of each system according to the user’s needs. With REST APIs exposing critical data that a business needs, IT can enable developers to self-serve and reuse rather than starting from scratch.

However, as different systems expand, your network of APIs naturally increases, and there will be many APIs for IT to manage and developers to consume. If a developer needs to expose data from a few systems, they would either need to call multiple APIs or ask IT to create another API that can connect with multiple APIs or systems.

Benefits of Anypoint DataGraph

  • With Anypoint DataGraph, you can serve data from multiple underlying APIs within a single request without writing any code.
  • Developers do not have to write code to parse data from multiple APIs.
  • Request the data you want, no more, no less.
  • Reduce development and maintenance efforts.
  • Since Anypoint DataGraph is a managed service, there is no need to worry about the underlying infrastructure and maintenance.

Limitations of DataGraph

  • DataGraph supports GET methods only.
  • It supports 250 APIs, up to 16,000 fields, and a maximum of 150 concurrent or ongoing calls per unified schema.
  • It supports a max 5MB size response per call and a 30-second timeout per query.
  • The maximum number of fields supported in a query is 100.
  • It is preferred to have primary keys of datatypes in string format.
  • The depth of the query can be the sixth level at max.

Sample scenario for DataGraph Implementation

Let's consider the scenario where you have two REST APIs - Account API and Customer API.

The Accounts API returns the customerId field, using which we need to fetch the customer details from the Customer API for that account. Generally, you need to call multiple Rest APIs or must fetch data from multiple Rest APIs, and each API will respond with a JSON payload. However, DataGraph offers one of the most optimal options where the client can pass a single input request, and Anypoint DataGraph will aggregate all the responses and send back the required data to the client.

Let’s see the responses of both the APIs. Here both the response is linked with primary key customerId.

Conclusion

With Anypoint DataGraph, you can instantly serve data across multiple APIs, which means less time spent on getting the data across the APIs and more on actual innovation. To achieve this, you automatically compose a data service by unifying data across APIs into one GraphQL endpoint without more code. Developers can then act on this data service without understanding the underlying relationships or complexities among different APIs. They can get the data they need for their project from many APIs with a single request.

MuleSoft also enables developers to gain insights and visibility into the application network using monitoring capabilities with the Anypoint Monitoring platform. Read our blog to learn more about Monitoring your APIs in Anypoint Platform.

Join the conversation

What are your thoughts on this blog? Drop us a line below. We’d love to hear from you.

© 2024 Nous Infosystems. All rights reserved.