Modeling a Graph through the Schema Builder
Summary
In this tutorial, you will:
- Start the PuppyGraph and MySQL containers and create example data.
- Add a MySQL catalog to query data as a graph.
- Add two types of vertices: one-to-one type and many-to-one type.
- Add two edges to compose a Modern Graph.
Prerequisites
Please ensure that docker compose
is available. The installation can be verified by running:
See https://docs.docker.com/compose/install/ for Docker Compose installation instructions and https://www.docker.com/get-started/ for more details on Docker.
Accessing the PuppyGraph Web UI requires a browser. However, the tutorial offers alternative instructions for those who wish to exclusively use the CLI.
Setup
Deployment
Create a file
docker-compose.yaml
with the following content:
docker-compose.yaml
version: "3"
services:
puppygraph:
image: puppygraph/puppygraph:stable
pull_policy: always
container_name: puppygraph
environment:
- PUPPYGRAPH_USERNAME=puppygraph
- PUPPYGRAPH_PASSWORD=puppygraph123
networks:
- mysql_net
ports:
- "8081:8081"
- "8182:8182"
- "7687:7687"
mysql:
image: mysql:8.0.33
container_name: mysql-server
environment:
- MYSQL_ROOT_PASSWORD=mysql123
networks:
- mysql_net
ports:
- "3306:3306"
networks:
mysql_net:
name: puppy-mysql
Warning: Ensure to modify your password environment variables, particularly when your machine is publicly accessible.
Then run the following command to start Mysql and PuppyGraph:
[+] Running 3/3
✔ Network puppy-mysql Created 0.1s
✔ Container mysql-server Started 3.7s
✔ Container puppygraph Started 3.7s
Data Preparation
This tutorial is designed to be comprehensive and standalone, so it includes steps to populate data in MySQL. In practical scenarios, PuppyGraph can query data directly from your existing MySQL databases.
Run the following command to start a MySQL shell to access the database using root:
It will show a password prompt:
Input the root password (default root password:
mysql123
) of mysql-server
to access the MySQL client shell.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.33 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Then execute the following SQL statements in the shell to create tables and insert data.
modern.sql
create schema modern;
create table modern.software
(
id text,
name text,
lang text
);
insert into modern.software
values ('v3', 'lop', 'java'),
('v5', 'ripple', 'java');
create table modern.person
(
id text,
name text,
age integer
);
insert into modern.person
values ('v1', 'marko', 29),
('v2', 'vadas', 27);
create table modern.person2
(
id text,
name text,
age integer
);
insert into modern.person2
values ('v4', 'josh', 32),
('v6', 'peter', 35);
create table modern.created
(
id text,
from_id text,
to_id text,
weight double precision,
from_name text,
to_name text
);
insert into modern.created
values ('e9', 'v1', 'v3', 0.4, 'marko', 'lop'),
('e10', 'v4', 'v5', 1.0, 'josh', 'ripple'),
('e11', 'v4', 'v3', 0.4, 'josh', 'lop'),
('e12', 'v6', 'v3', 0.2, 'peter', 'lop');
create table modern.knows
(
id text,
from_id text,
to_id text,
weight double precision,
from_name text,
to_name text
);
insert into modern.knows
values ('e7', 'v1', 'v2', 0.5, 'marko', 'vadas'),
('e8', 'v1', 'v4', 1.0, 'marko', 'josh');
The above SQL creates the following tables:
id | name | lang |
---|---|---|
v3 | lop | java |
v5 | ripple | java |
id | name | age |
---|---|---|
v1 | marko | 29 |
v2 | vadas | 27 |
id | name | age |
---|---|---|
v4 | josh | 32 |
v6 | peter | 35 |
id | from_id | to_id | weight | from_name | to_name |
---|---|---|---|---|---|
e9 | v1 | v3 | 0.4 | marko | lop |
e10 | v4 | v5 | 1.0 | josh | ripple |
e11 | v4 | v3 | 0.4 | josh | lop |
e12 | v6 | v3 | 0.2 | peter | lop |
id | from_id | to_id | weight | from_name | to_name |
---|---|---|---|---|---|
e7 | v1 | v2 | 0.5 | marko | vadas |
e8 | v1 | v4 | 1.0 | marko | josh |
Graph Schema Creation
PuppyGraph provides a graph schema builder in its web UI. Click Create Graph Schema
button to launch the builder.

Adding a catalog
Select the MySQL8
option in the Catalog type
dropdown, then fill in the following text fields.
Catalog name
:mysql_data
Username
:root
Password
:mysql123
JDBC Connection String
:jdbc:mariadb://mysql-server:3306?allowPublicKeyRetrieval=true
After filling in these fields, click Save
and Submit
buttons.

Adding vertices

Adding a one-to-one vertex type
This type of vertex maps a table to a vertex type.
Click the Add a vertex
button, then select the Default
type in the Vertex type
dropdown in the form.

Adding a many-to-one vertex type
This type of vertex maps multiple tables to a vertex type.
Click the Add a vertex
button again, then select the Many To One
type in the Vertex type
dropdown in the form.

Adding Edges
Adding edge types follows a similar procedure to that of adding vertex types. However, this step requires the referenced vertex types to be added to the schema first. Then, you can select "from" and "to" vertex types for the edge. Additionally, you need to select the columns that correspond to the IDs of the "from" and "to" vertex labels.


Submitting the Schema
After adding the vertex and edge types following the steps above, the schema builder will display the added vertex and edge types and visualize them. Click Submit
to create the graph.


If you want to learn more about the Graph Schema Builder, please refer to this document: Graph Schema Builder