GraphQL+-: A Simplified Language for Graph Databases
GraphQL has emerged as a dominant query language, widely used for APIs in various domains. Originally developed by Facebook, GraphQL revolutionized the way developers interact with data, providing a flexible, efficient, and powerful framework for querying APIs. However, its design was not tailored for graph databases, a specific category of databases that inherently store data in the form of nodes, edges, and properties, typically used for representing networks, hierarchies, and interconnected data structures.

In 2017, Dgraph introduced GraphQL+-, a language that adapts Facebook’s GraphQL for graph databases. This modification provides a more fitting query language that enhances the power of graph databases. This article will explore the evolution, features, and use cases of GraphQL+- and how it contributes to the growing field of graph-based data management.
The Origins of GraphQL and Its Limitations for Graph Databases
GraphQL, since its inception, has been a transformative API query language. Unlike REST, which requires multiple endpoints for various resources, GraphQL allows clients to request exactly the data they need in a single request, thus optimizing performance and flexibility. It uses a schema to define the structure of the data, enabling both the client and the server to have a shared understanding of the data format. This self-descriptive nature makes it an excellent tool for working with complex data structures in a unified way.
However, GraphQL was not designed with graph databases in mind. Graph databases, such as those built on Dgraph, Neo4j, and ArangoDB, use nodes (entities) and edges (relationships) to represent data. The architecture of these databases is fundamentally different from traditional relational databases. Traditional relational databases rely on tables and rows, while graph databases focus on relationships and traversal between connected nodes. Despite the power of GraphQL, its original design was not optimized to express the types of operations typically needed for graph data manipulation, such as traversing relationships, aggregating graph-based data, and maintaining graph structure integrity.
The Birth of GraphQL+-: A Tailored Query Language for Graph Databases
Recognizing the potential for improving the interaction between GraphQL and graph databases, Dgraph introduced GraphQL+- in 2017. By extending the syntax of GraphQL, Dgraph was able to create a query language that was specifically tailored for graph operations, providing a more seamless experience for developers working with graph data.
GraphQL+- builds on GraphQL’s core concepts, such as its flexible query syntax and schema validation. However, it introduces additional features that allow for more efficient querying and manipulation of graph data. These features make it easier for developers to work with graph data structures, perform graph traversals, and work with relationships between nodes in a way that would be challenging with standard GraphQL.
Key Features of GraphQL+-
1. Graph-Specific Query Operations
One of the most significant additions to GraphQL+- is its ability to execute graph-specific operations directly within the query. Traditional GraphQL is optimized for working with data that is structured in tables and rows, whereas graph databases require operations that can navigate the relationships between nodes. With GraphQL+-, users can specify operations such as:
- Traversal: Moving across the graph from one node to another by following edges, allowing for the exploration of related data.
- Path Queries: Extracting paths of nodes and relationships, which is critical in graph analytics and modeling networks.
- Relationship Counting: Determining the number of relationships a node has, which is essential for analyzing the connectivity and significance of entities in a graph.
These operations are essential for working with complex, interconnected data in graph databases and are seamlessly integrated into the GraphQL+- language.
2. Schema Definition for Graph Data
GraphQL+- uses a schema definition that is similar to GraphQL’s but is adapted for the graph model. The schema defines types, relationships, and their properties, allowing for robust validation of queries. However, unlike traditional GraphQL schemas, GraphQL+- schemas support the direct representation of relationships between nodes, making it easier to model complex graph data structures.
For instance, relationships in graph data can be defined with specific properties and types, allowing users to capture more nuanced details about how entities are related to one another. This flexibility in schema definition is a core advantage when working with graph databases, where relationships often carry significant meaning and require careful modeling.
3. Aggregation and Filtering
GraphQL+- introduces additional functionality for graph-specific aggregation and filtering operations. In a graph database, relationships are not just about connecting nodes but are also crucial for analyzing data and making decisions. With GraphQL+-, developers can:
- Aggregate Data Across Relationships: Aggregate operations in GraphQL+- allow developers to compute values based on graph traversal, such as finding the sum of weights along a path or counting the number of relationships between nodes.
- Filter by Relationship Properties: GraphQL+- enables filtering based on the properties of relationships, rather than just the nodes themselves, allowing for more sophisticated queries based on the nature of connections between entities.
These features add depth to the querying capabilities of graph databases, enabling complex graph analytics and queries that would be difficult or inefficient to express in standard GraphQL.
4. Simplified Syntax for Graph Database Operations
While GraphQL’s syntax is already known for being straightforward and flexible, GraphQL+- further simplifies the process of interacting with graph databases. By incorporating graph-specific keywords and operations into the language, developers can write concise and efficient queries for graph data. The syntax is designed to be intuitive, reducing the learning curve for those new to graph databases and making it easier to implement graph-based solutions.
The simplified nature of the language ensures that developers can focus on solving problems rather than wrestling with complex query language constructs. As a result, it accelerates the development process and enhances productivity.
5. Optimized Performance for Graph Operations
Graph databases often deal with large volumes of interconnected data. Efficient query performance is essential for handling such data, especially in real-time applications. GraphQL+- introduces optimizations that are specific to the traversal and manipulation of graph data, ensuring that queries are executed with minimal overhead. These optimizations are crucial in applications where speed and scalability are paramount, such as recommendation engines, social networks, and fraud detection systems.
Use Cases of GraphQL+-
GraphQL+- opens up new possibilities for developers working with graph databases. Here are some of the key use cases where GraphQL+- can provide significant value:
1. Social Network Analysis
Social networks are inherently graph-based, with users as nodes and relationships (such as friendships, follows, or interactions) as edges. GraphQL+- allows developers to easily query relationships between users, find shortest paths, and analyze the strength of connections. For example, it can be used to identify influential users in a network, recommend new connections, or trace the spread of information across the network.
2. Recommendation Systems
Recommendation engines, such as those used by e-commerce platforms, rely on understanding the relationships between products, users, and behaviors. By using GraphQL+-, developers can traverse the graph of users, their preferences, and past interactions to provide personalized recommendations. This is particularly powerful when the system needs to consider multiple factors (e.g., user demographics, product similarity, past purchases) to make a recommendation.
3. Fraud Detection
Graph databases are commonly used for fraud detection, as they excel in identifying patterns of unusual behavior within complex networks. GraphQL+- allows for querying and analyzing relationships between accounts, transactions, and behaviors. This makes it easier to spot fraudulent activities, such as money laundering or account takeover, by examining the connections between suspicious entities and their actions.
4. Supply Chain Management
Supply chains often involve a complex web of suppliers, distributors, and customers. Using GraphQL+-, businesses can map out their entire supply chain as a graph, identifying dependencies and optimizing logistics. Graph queries can be used to determine the most efficient routes, identify potential bottlenecks, and analyze relationships between suppliers and manufacturers.
Conclusion
GraphQL+- represents an exciting evolution of the GraphQL language, tailored specifically for graph databases. By extending GraphQL’s flexible and powerful syntax to better support graph-based operations, it simplifies the process of querying and manipulating graph data. With its graph-specific optimizations, improved schema support, and enhanced query capabilities, GraphQL+- empowers developers to build more efficient, scalable, and insightful applications based on graph data.
As the adoption of graph databases continues to grow across various industries, the introduction of GraphQL+- highlights the ongoing evolution of tools that make it easier to work with complex, interconnected data. Whether for social networks, recommendation systems, fraud detection, or supply chain management, GraphQL+- is positioned to become a core language for developers working in the graph database space, enabling them to harness the full power of graph-based data models.