Mulesoft Anypoint Data Graph

 

MuleSoft Anypoint Datagraph is built on the top of GraphQL. GraphQL was initially developed by facebook and released publicly in year 2015.

With the MuleSoft Anypoint Datagraph, Organizations will be able to utilize capabilities of graphql and reuse multiple APIs into single request. GraphQL also allows customer to request limited data they need.

Anypoint Data Graph Use Case

 

  • To get the aggregated response from the Multiple APIs.

e.g. Let’s consider we have 3 system APIs(Ledger, Customer and Account API) available on exchange and deployed. Now we wanted to send aggregated response from these API without writing any process/business orchestration layer. So basically, developer don’t have to write code for parsing the data from these API’s.

Here Anypoint Datagraph help us to send the aggregated response to the client application just through configuration only.

 

 

  • Mobile and Web application needs separate response data.

e.g. Customer API response schema has 6 attributes (customerId,Name,Age,phone,email,pincode and address) and they want to send separate response to mobile and web application.

 

Getting Started with Anypoint DataGraph

 

Here are the steps below for enabling a datagraph endpoint in MuleSoft

 

 

  • Click on the Add API button. This page has displayed all the discoverable API available on exchange.

Graphical user interface, text, application Description automatically generated

 

  • Select Customer System API from the list and click “Next Configure URL”. Below page displayed in front of you. Click “Confirm Selection ” button with default selected API version and Asset Version.

 

  •  Add/Edit API URL section will be enabled with default selected values. Click “Next Configure Security” button now.

Note:- These values populated from the API manager configuration which we set during the API manager configuration. Please refer Snippet 2 for the reference.

 

 

Snippet 2 API Manager Config:-

 

  • Click on Next. Since we have not applied any policies in API manager so we should select authentication policy as No Auth here and click “Next preview Schema” button.

Note:- Please refer the API Manager snippet for the reference in below section.

Graphical user interface, text, application, email Description automatically generated

 

API Manager snippet:-

 

  • Below page displays the schema details populated from the RAML specification. Click “Next:Edit Schema” button. Anypoint Datagraph is smart enough to populate the details from RAML.

Graphical user interface, text, application, email Description automatically generated

 

  • We can make visible/hidden query method here. Click Customer tab from left yellow highlighted panel.

Graphical user interface, application, Teams Description automatically generated

 

  • This Page has below yellow highlighted section. Click on the “Enable Collaboration” button.

Graphical user interface, application, Teams Description automatically generated

 

  • You will see option to define Primary key and Select Default Query method. Select and click next button

Graphical user interface, text, application Description automatically generated

 

  • Select customerId as primary key here and press confirm button.

Graphical user interface, text, application Description automatically generated

 

  • Press confirm button will display the updated detail here. Now click to “Next:Add to unified schema” button keeping other section as default selected.

Graphical user interface, application Description automatically generated

 

  • Now the Customer API is started to deploy on the Anypoint Datagraph. It will take around ~5 min to deploy.

Graphical user interface, application, Teams Description automatically generated

 

  • Once deployment done its status changed as Up to date. Now click the “Run Operation” button.

 

  • Select 2nd radio button option from this window and click next.

Graphical user interface, text, application Description automatically generated

 

  • Enter the application name and keep rest field as blank and click the Next button. Next page will display GraphQL query language page.

 

Graphical user interface, text, application Description automatically generated

 

  • Write the GraphQL syntax into the middle section of page to fetch the data from the deployed customer API unified schema application. If all good, then we should get the valid response from the API.

Let’s validate the GraphQL response and actual API endpoint response. Both should have same response details data.

Anypoint GrapQL Response:-

Graphical user interface, text, application Description automatically generated

 

Actual API endpoint response:-

Graphical user interface, text, application, email Description automatically generated

 

  • Now time to deploy Account System API into Anypoint Datagraph. Click on Add API button.

A picture containing shape Description automatically generated

 

  • Select the Account System API from the below listed API and click Next:Configure URL

Graphical user interface, text, application Description automatically generated

 

  • Configure URL page should have configured with default selected values and click “Next:Configure Security” button.

Graphical user interface, text, application Description automatically generated

 

  • Here we will set the authentication policy as Basic Auth because we have applied the same policies into this API at API manger section. Please note same client application must use here while applying the policy. Click next preview schema button.

Graphical user interface, text, application Description automatically generated

 

API Manager policies page:-

Graphical user interface, text, application, email Description automatically generated

 

  • Click Next edit schema and select the Account tab from the left panel from next screen and perform the enable collaboration operation.

Graphical user interface, application, Teams Description automatically generated

Graphical user interface, application, Teams Description automatically generated

 

  • Enable the accountId as primary key using this screen.

 

  • Now configure link to another type. Here we will enabled the relation between Account and Customer API based on the customerId. Select customerId attribute as FK into Account schema which will bind with Customer schema using same attribute as PK. Click Save Changes button and then click Next to Add to unified Schema.

Graphical user interface, text, application Description automatically generated

 

  • Account API started to deploy on Anypoint Datagraph. Once it will deployed then click on the Run operation button.

Graphical user interface Description automatically generated with medium confidence

 

  • We can run query using account object that inherit customer object inside that. This happens due to we have created the link between account and customer object using the customerId as PK/FK.

 

  • Let’s validate this data with actual endpoint response. We can see Anypoint Datagraph fetched the correct account and customer data based on the relation defined with customer schema.

Graphical user interface, text, application Description automatically generated

 

  • We can explore more option like share GraphQL query, Trace query, download schema, etc while clicking on the 3 dots.

 

  • Using “Copy & Share query” option we can get the get the details about Anypoint Datagraph endpoint.

 

  • Hit the anypoint data graph endpoint through postman.

 

  • Click the code link in postman and get the graphQL request as converted JSON request and hit the API now.

Points to Note

  • It supports GET method only.
  • Support only RAML and OAS specification
  • 250 API’s per unified schema.
  • It is preferred to have primary keys of datatypes in string format.
  • Maximum 5 MB response data per call.
  • Anypoint Datagraph strongly typed and strictlly follow schema definition.
  • API Manager policies and Anypoint Datagraph API policy should be in sync.
  • Same client application should consider while designing the API through API Manager and Adding the API into Anypoint Datagraph.
  • Recommended to fill all the optional details (API instance label, Implementation URL, Customer endpoints) while defining the API configuration.

References:

https://www.mulesoft.com/platform/anypoint-design-center/datagraph

https://blogs.mulesoft.com/learn-apis/comparing-datagraph-vs-graphql/

 


Post Submitted by:

Madhusudan Chaurasia
Associate Technical Architect at Tavant Technologies
LinkedIn Profile
  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments