DEV Community

Muhammad Farooq
Muhammad Farooq

Posted on

Understanding Graph Database and Cypher

Introduction

What is graph

A graph is a collection of nodes and relationships (edges) between them. Sometimes nodes are called vertices and relationships are called edges.

Representation

Image showing a graph

A circle typically represents a Node, while an arrowed line indicates an Edge connecting one Node to another.

The Nodes colored in red are labeled as "Females," while the blue Nodes are labeled as "Males."
The connection between them is labeled as "Follows" and is directed from one Node to another.
By assigning labels, the graph becomes easier to handle, allowing for the display, coloring, or manipulation of Nodes or relationships with specific labels.

Properties and Paths

We have the freedom to assign as much information as we desire to each node and relationship in the graph. This data is stored as properties.

To illustrate, let's consider the node named "Adam" which possesses the following properties:

{Name: Adam, Age: 25}

The property list functions similar to a key-value store, where the property name acts as the key, and the corresponding value can be a number (INT or FLOAT), a string, a list, or a BOOLEAN. Some graphs even contain nodes with several megabytes of information per node or edge.

In our graph visualization, we have chosen to display Adam's Name property on the node. However, we have the flexibility to showcase any property of the node based on our preference.

Furthermore, just like nodes, edges can also have unique properties. For example, we can store information such as the duration of Fia's following of Dee within the edge that connects them in the graph.

Paths

A Path is a sequence of alternating nodes and edges.

Nodes can exist with any number of outgoing or incoming edges. If we want to make the relationship bi-directional we must have two edges.

Representing Nodes, Edges, Labels, Properties and Paths.

OpenCypher makes clever use ASCII Art to make using the language easy to use.

  • Nodes are always represented as ( ), brackets - to look like circles.
  • Properties of nodes (or edges) are inside { } curly brackets separated by commas.
  • The property name and value are separated by : colon as in { Age: 30, Eyes: 'Brown' }
  • Edges are represented by [ ] square brackets and their direction is shown with a >
  • Labels are preceded by : colon as in :Female or :Follows

Here are progressively more detailed Pattern examples

*() - [ ] -> () *

  • this is the base notation of a path and matches every pair of connected nodes and their connecting edge

Visit Apache AGE:

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay