Blog

Anypoint Datagraph - Merge Datatypes

Anoop RamachandranWritten by Anoop Ramachandran

anypoint-datagraph-merge-datatypes

In this blog I have tried to showcase a step by step demo on how to merge Datatypes with the Anypoint Datagraph in the MuleSoft Anypoint Platform.

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

  • 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.

Once the prerequisites are done, follow the steps below to merge the datatypes.

  • Make sure that you have both the Customers API and Users API added to the Anypoint Datagraph Unified Schema.

anypoint-datagraph-merge-datatypes

  • Open the Users API and click on User type and scroll down to the Merge with another type section.

anypoint-datagraph-merge-datatypes

  • Select Customer type from the target drop down. You will end up having a Mismatched dataType across common fields!

anypoint-datagraph-merge-datatypes

  • Click on Rename field to rename the UserID field.

anypoint-datagraph-merge-datatypes

  • Type customerID in change to text box and click on Confirm.

anypoint-datagraph-merge-datatypes

  • Confirm merge button would be enabled by now and click on Confirm merge.

anypoint-datagraph-merge-datatypes

  • Review the changes and click on the Confirm button.

anypoint-datagraph-merge-datatypes

  • Both Customer and User type would be merged successfully.

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.
  • Along with this you should notice that the fields like email and phone are merged into a single type. This will only work if both the fields have the same data.

anypoint-datagraph-merge-datatypes

anypoint-datagraph-merge-datatypes

  • 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.