linkedin

Anypoint Datagraph – Merge Datatypes

anypoint-datagraph-merge-datatypes

In this blog, I showcase a step-by-step demo on how to merge datatypes using Anypoint Datagraph in the MuleSoft Anypoint Platform. More importantly, this walkthrough helps you understand how unified schemas can be enhanced by consolidating related data models across APIs.

Note:- This blog is a continuation of my previous blogs Anypoint Datagraph – REST to GraphQL and Anypoint Datagraph – Link Datatypes. If you have not done the walkthrough of the previous blogs, it would be difficult to do and follow this one, so read the prevoius blog first.

Prerequisites and Required APIs

  • Do the walkthrough of the previous blog.
  • Add the Users API to the Anypoint Datagraph in the similar fashion we added for Customers API.

Basically we need the Customer’s API and Users API for this demo.

Merging Datatypes in Anypoint Datagraph

After completing the prerequisites, follow the steps below to merge the datatypes.

Datagraph
  • Begin by opening the Users API, then click on the User type. As you scroll down, you will notice the Merge with another type section, which is where the actual merging process begins.
API schema
  • From the target dropdown, select the Customer type. However, once selected, you will immediately see a warning indicating a mismatched datatype across common fields. This occurs because the field names do not yet align between the two types.
Object type
  • Click on Rename field to rename the UserID field.
Object type
  • Type customerID in change to text box and click on Confirm.
Rename field

Anypoint Datagraph Merge Datatypes in the Unified Schema

  • By now, the Confirm Merge button is enabled—click Confirm Merge to proceed.
anypoint-datagraph-merge-datatypes
  • Review the changes and click on the Confirm button.
anypoint-datagraph-merge-datatypes
  • The system successfully merges the Customer and User types.
anypoint-datagraph-merge-datatypes
  • Click Apply Changes and wait for the API to be updated.
  • Navigate to the Datagraph home page and click on Run a Query
  • Now the users method includes both user type fields as well as the customer type fields.
  • You’ll also notice that fields such as email and phone merge into a single type. This works only when both fields contain the same data.
anypoint-datagraph-merge-datatypes
anypoint-datagraph-merge-datatypes

Validating the Merged Datatypes Using Queries

  • Query
        {
          users{
            customerID
            firstName
            lastName
            lastLogin
            phone
            accountType
            email
            paymentType
            profilePicture
            address
          }
        }

You have now successfully created an Anypoint Datagraph API from the Users REST API and merged it with the Customer type.

Â