This demo repo provides a practical example of building an Ecommerce App (read-heavy
)using Hasura's Data Delivery Network (DDN) with a supergraph architecture.
Please note that a new release for the repo is out. Make sure to try the workflow again if you are a returning user.
This repository has credentials for databases, which are intentionally published by Hasura for demo purposes. These credentials allows for read-only access to synthetic datasets, which do not contain any user or customer sensitive data.
This example supergraph is composed of three subgraphs - users, experience, and sales, each backed by one or more data connectors. These subgraphs integrate various data sources to provide a comprehensive Ecommerce solution as follows.
flowchart TD
%% Module 1
M1[Experience Subgraph]
M1 --> D1A[Postgres]
M1 --> D1B[Mongo]
D1A --> T1A[• Products
• Manufacturers
• Categories
• Carts
• CartItems
• ProductVectorDistance]
D1B --> T1B[• ProductDetails]
%% Module 2
M2[Users Subgraph]
M2 --> D2A[Postgres]
M2 --> D2B[Clickhouse]
D2A --> T2A[• Notifications
• Reviews
• Users]
D2B --> T2B[• Browsing History
• Recently Viewed Products
• Session History]
%% Module 3
M3[Sales Subgraph]
M3 --> D3A[Postgres]
M3 --> D3B[Typescript]
D3A --> T3A[• Coupons
• Orders]
D3B --> T3B[• ToCurrencyString
• ToDateString]
Git Clone this repo: https://github.com/hasura/ddn-sample-app.git and cd into it
Build the supergraph locally using the following command
ddn supergraph build local
Run Docker. For local development, Hasura runs several services (engine, connectors, auth, etc.), which use the following ports: 3000, 4317 and so on. Please ensure these ports are available. If not, modify the published ports in the Docker Compose files from this repository accordingly.
ddn run docker-start
Check out the console to discover and test the GraphQL API
ddn console --local
4a. DDN also supports JSON API as output. The feature is out in experimental phase. Run the following command to fetch the openapi JSON file. An example of the swagger file is shown here.
curl http://localhost:3000/v1/rest/__schema > ddn_openapi.json
Test using GraphQL API queries from the Composability folder.
To rebuild after any changes, you may run the following command to get the changes reflected.
ddn supergraph build local
ddn project init
This will create a new project and shows the project name output in the terminal. You get an output such as below -
+-----------+--------------------------------+
| Project | sincere-turtle-2027 |
+-----------+--------------------------------+
| Subgraphs | globals,experience,sales,users |
+-----------+--------------------------------+
ddn context set project <Project Name>
# ddn context set project vast-buzzard-0000
# 5:36PM INF Key "project" set to "vast-buzzard-0000" in the context successfully
ddn supergraph build create
⚠️ First Time Build can take 8 to 10 mins. Subsequent builds will be faster because of caching. Recommend
If you want to just make metadata changes and quickly see changes without rebuilding the connectors, run the following command:
ddn run build-supergraph
or
ddn supergraph build create --no-build-connectors
This is a script which passes the flag --no-build-connectors
Note: Once deployed to your new project, if you don't have any connector changes, you can only rebuild supergraph alone, ie. connectors are only need to be deployed when there is change (data schema changes, functions etc.)
Filtering and Sorting Operations
countryOfOrigin: {_eq: "US"}
)_gt
operator)order_by: { distance: Asc }
)Remote Relationships in Predicates
kind: BooleanExpressionType
version: v1
definition:
name: ProductsBoolExp
operand:
object:
type: Products
comparableFields:
- fieldName: categoryId
booleanExpressionType: UuidBoolExp
- fieldName: countryOfOrigin
booleanExpressionType: TextBoolExp
- fieldName: createdAt
booleanExpressionType: TimestamptzBoolExp
comparableRelationships:
- relationshipName: reviews
booleanExpressionType: ReviewsBoolExp
logicalOperators:
enable: true
isNull:
enable: true
graphql:
typeName: ProductsBoolExp
Pagination
offset
parameter limit
parameterSame Database Join
manufacturedBy
)Cross-Database Operations
kind: Relationship
version: v1
definition:
name: recentlyViewedProducts
source: Users
target:
model:
name: RecentlyViewedProducts
subgraph: users
relationshipType: Array
mapping:
- source:
fieldPath:
- fieldName: id
target:
modelField:
- fieldName: userId
Multi-Level Nested Joins
Nested Filtering
Nested Sorting
Nested Pagination
Field Selection
Data Transformations
kind: Command
version: v1
definition:
name: ToCurrencyString
outputType: String!
arguments:
- name: amount
type: Float
description: The number to format into currency.
source:
dataConnectorName: salests
dataConnectorCommand:
function: toCurrencyString
graphql:
rootFieldName: toCurrencyString
rootFieldKind: Query
description: Formats a number into a currency string.
export function toDateString(date?: string): string {
console.log("date", date);
if (!date) {
return "Invalid date";
}
try {
return new Date(date).toDateString();
} catch (error) {
console.error("Error formatting date:", error);
return "Invalid date";
}
}
Vector Search Operations
Query Arguments
Get round-the-clock support on our Discord Server here.
Two Main Features
See more details on DDN Advanced here.
Switch to this branch to start the DDN Advanced Workflow - https://github.com/hasura/ddn-sample-app/tree/multirepo/team1admin
The following section outlines the core concepts of Hasura DDN, providing a deeper understanding of its architecture and functionality.
For a multi-team organization working on a Hasura project, it can make sense for any one team to not have access to all metadata objects. Subgraphs introduces the notion of a module system for your Hasura metadata. Think of it is as an independent domain consisting of one or more data sources. Read More
Models are the link between your data connectors and the API Hasura generates. A model may be backed by a database table, an ad-hoc SQL query, a pre-materialized view, a custom REST or GraphQL API server, etc. Read More
Commands are backed by functions or procedures declared in a DataConnectorLink allowing you to execute business logic directly from your GraphQL API. You can use them to validate, process or enrich data, call another API, or even log a user in.
A build is a fully-functional, immutable supergraph API which is built based on your project's configuration.
During the build process, Hasura builds and deploys all the data connectors and supergraph builds. This includes connector configurations, models, functions, and all other related components, which are integrated into the deployments.
Considering the size of the supergraph and separate deployments, it may initially take some time to complete. Once deployed, the supergraph provides a unified GraphQL API that leverages the capabilities of all subgraphs to offer a comprehensive Ecommerce solution.