Integrating Graph Database with MuleSoft

March 21, 2023

Blogger Image

Pooja G Bhat

Software Engineer – Enterprise Integration

Graph database is a new database concept of storing nodes and relationships instead of tables or documents. The data is depicted as sketches of thoughts on a whiteboard, making it incredibly simple to interpret. Data is also saved without confining it to a pre-defined model, allowing for a very flexible way of comprehending and using it.

Neo4j is one of the enterprise-strength graph databases that combines native graph storage. Companies such as eBay, Walmart, Telenor, UBS, Cisco, Hewlett-Packard, and Lufthansa have made substantial use of the Neo4j graph database to improve their services.

How Neo4j works

Neo4j uses graphs to represent data and the relationships between them. A graph is any graphical representation that consists of vertices (shown by circles) and edges (shown with intersection lines).

Neo4j Mule 4 connector

Anypoint Connector for Neo4j provides the capability to execute CQL statements and run basic operations, such as create, update, delete, and select nodes against a Neo4j Graph database instance.

Prerequisites

  • Neo4j Desktop
  • Anypoint Studio

**Note:

The community edition of Neo4j is not supported for MuleSoft.

Neo4j Mule 4 Connector supports only enterprise edition and 3.X versions

Sample use case

Create a MuleSoft API to access and manage the Customer and Product information and their relationship in a Neo4j graph database.

This system has the following vertices/entities (with attributes in parentheses):

  • Category (title)
  • Product (title, description, price, availability, delivery)
  • Customer (name, email, registration date)
  • Promotional offer (type, content)

In this graph database, all these entities will have nodes with respective labels and will be connected preferably in a relationship (intersection lines).

Neo4j Desktop setup

Link for downloading enterprise edition: https://neo4j.com/download/

  1. Click the Add button in the Project section to create a new instance.
  2. Select Local DBMS from the dropdown.
  3. Create a new project by giving the required name, password, and version.
  4. Once the project is created, start the instance by clicking the start button.
  5. Once the instance is Active, open it with the Neo4j browser.
  6. Using the Neo4j browser, users can see the nodes and the relationships in a graph database.

Configuration in Anypoint Studio

Check the port number in the Neo4j browser before installing Anypoint studio. The default username and password are neo4j and password, respectively.

Mule implementation

There are 4 endpoints in the application - /customer, /product, /category, and /relationship.

  • /customer has 2 operations: to create the customer and retrieve the details of customer based on the relationship
  • /product has 1 operation: to create the product
  • /category has 1 operation: to create the category
  • /relationship has 1 operation: to create the relationship between any of the above entities

To create the entities, the query needs to be written in CQL (Cypher Query Language).

Cypher is a declarative language like SQL that has distinctive semantics and allows you to write flexible and easy-to-read queries. Cypher syntax emphasizes directions in relationships between entities.

Keywords used for writing the query are:

  • Create: This clause is used to create nodes, relationships, and properties.
  • Merge: This clause verifies whether the specified pattern exists in the graph. If not, it creates a pattern.
  • Match: This clause is used to search the data with a specified pattern.

Create Relationship query

In this CQL query, a relationship is established based on the match query between the source and target nodes. A source node and a target node are required to establish a relationship.

In the above query, the keyword Match is used to match the source and target node by filtering on the parameters passed, and then the Create keyword is used to create a relationship between them.

Create Product query

To create a product, provide the product title, price, shippability, and availability and use the Create keyword to create the node called Product.

Create Customer query

To create a customer, provide the customer’s name, age, and email and use the Create keyword to create the node called Customer.

Create Customer query

To create a category, provide the title of the category and use the Create keyword to create the node called Category.

Retrieve customer details based on the relationship

To get the customer's details based on the relationship name, we provide the product name and the relationship between the product and the customer.

Conclusion

Working with Neo4j and its integration with MuleSoft can be a new experience. Like any new technology, Neo4j comes with its own challenges and limitations. Understanding the basics of Neo4j desktop UI, CQL commands, and how to configure the graphical database and the MuleSoft connector with the help of a sample integration use case will help users to run basic operations against a Neo4j Graph database instance. Explore Anypoint Connector for Neo4J with Nous’ experts and learn our MuleSoft services help deliver seamless digital connectivity and integration.

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.