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.
- Open the Users API and click on User type and scroll down to the Merge with another type section.
- Select Customer type from the target drop down. You will end up having a Mismatched dataType across common fields!
- Click on Rename field to rename the UserID field.
- Type customerID in change to text box and click on Confirm.
- Confirm merge button would be enabled by now and click on Confirm merge.
- Review the changes and click on the Confirm button.
- Both Customer and User type would be merged successfully.
- 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.
- 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.