Graph > GraphDB > GraphQL

Rachit Lohani
3 min readJun 25, 2019

--

Graph : Graphs are networks consisting of nodes that are connected. The connections can be directed (arcs), undirected(edges) or weighted.

#directed unweighted graph in pythongraph =  {
'A': ['B', 'C'],
'B': ['C', 'D'],
'C': ['D'],
'D': ['C'],
'E': ['F'],
'F': ['C']
}

Graph Theory: Study of graphs. Graphs can be efficient data structure to show relations and depict any path traversal problems. Sitemaps, social relations, sorting, searching all can be implemented effectively via graphs. Google uses graphs heavily to find answers to our search queries, FB uses them to find friends, interests and content that we will like, youtube to find videos, ways/maps to find the best route, JVM to manage memory, OS to manage files. Graphs are everywhere and how to use them effectively is what Graph theory focuses on.

GrahpDB :

Given the following table structure write queries in SQL and Cypher (graphDB query language) to list all the names of friends of Jane. ER diagrams are easy to understand and relate to but translating them to RDBMS can be painful as it is not easy for one to show relationships in them, that is what changes with GraphDB. GraphDB is a database that uses graph data structure for semantic queries with nodes, edges and properties to represent, store and fetch the data. The best part about GraphDB mimics how a human brain thinks when dealing with dataset.

SQL

SELECT p2.person_name 
FROM people p1
JOIN friend ON (p1.person_id == friend.person_id)
JOIN people p2 ON (p2.person_id == friend.friend_id)
WHERE p1.person_name = 'Jane';

CYPHER

MATCH (ee:person)-[:FRIEND-WITH]-(friend)
WHERE ee.name = "Jack"
RETURN ee, friend

GraphQL

https://graphql.org/ did a good job at providing a concise capability overview of what graphQL is and does.

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

GraphQL and REST solve for the same purpose, better accessibility/consumption of a service for a client. REST is like going to “chipotle”, they know what you want. GraphQL is like going to a food court, where you as a client can pick and choose. Clients have to know exactly what they are looking for else they could end up eating too much and feeling bloated ;-)

In the next article, let deep dive into REST V/s GraphQL and when to use which paradigm.

--

--

Rachit Lohani
Rachit Lohani

Written by Rachit Lohani

CPTO ( Chief Product and Tech Officer

No responses yet