> For the complete documentation index, see [llms.txt](https://gremlify.gitbook.io/gremlify/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gremlify.gitbook.io/gremlify/schema.md).

# Define a Schema

Schemas define the structure of your Graph data, e.g what nodes and edges are valid.Generally speaking, TinkerPop, which is used by Gremlify as the Graph database engine, is schema less. But if you work, or plan to work with Graphs such as [JanusGraph](https://janusgraph.org/) or [OrientDB](https://orientdb.org/) you might find it useful (or if you are just curious about schemas!).

{% hint style="info" %}
Note: schemas are **optional**. If you are not interested in creating one, you might want to skip this article.
{% endhint %}

Let's for instance take the following simple schema as an example:

![](/files/-MHRrNImFMY2hwqLvyzh)

That basically means, that a **person** can own a **pet**, and be friends with another **person**, but any other relation is invalid.

## Create a Schema from scratch

To define a schema, click on the "Schema" tab on the side menu of the Graph Builder panel:

![](/files/-MHRqLPx6BTf6F74WYYZ)

\
The Schema builder is an **interactive interface**, that requires both **mouse** and **keyboard** interactions.‌

Below is a list of all available keyboard & mouse combinations:

| Action            | Combination                           |
| ----------------- | ------------------------------------- |
| **Create Vertex** | Shift + Left Mouse click (somewhere)  |
| **Create Edge**   | Shift + Drag mouse between 2 Vertices |
| **Delete Vertex** | Select Vertex + Backspace             |
| **Delete Edge**   | Select Edge + Backspace               |
|                   |                                       |

Let's create the schema from above. We'll start by creating the **person** node (hit **shift + mouse).**

The following dialog will open up:

![](/files/-MHRsbDSw2t607NvEx0L)

Let's fill it up with the following properties, and then hit **save**:

![](/files/-MHRskAa1r3XoAzHyQHY)

{% hint style="info" %}
Note: currently three types of data are supported: **string,** **boolean** and **number**
{% endhint %}

We can now repeat the same process with the **pet** node, but with a slight difference of the properties:

![](/files/-MHRtF3_-XDpbsBZS0KC)

Our schema should look as follows:

![](/files/-MHRtf2rKN3M_EbIYt7I)

Now let's create the **owns** relationship by holding **shift** and dragging the mouse into **pet**. Similarly to the node creation, a dialog will open. The results:

![](/files/-MHRtqlIX_HWZP9o5iOU)

Now, to create the **friendOf** relation, we'll hold **shift** and drag the moue from **person** to itself:

![](/files/-MHRuZFhe3eA1TUWLTfy)

Our schema is ready for work! let's try it out by moving to the **Graph** tab, and create a node. The following dialog opens:

![](/files/-MHV0i--vX9zqGzdAWF-)

As you can see, any property we defined in our schema is labeled with it's corresponding type. That implies that trying to fill it with invalid values will throw an error:

&#x20;

![](/files/-MHV1PLc3JpHZ7sNkaSc)

In addition, and in contrary to the schema-less Graph,  you can only create nodes and edges with the labels defined in the schema. Use the label dropdown for that matter.

Let's create a few nodes:

![](/files/-MHV2B-Uk4eM2NpRvfsc)

Our graph is not complete without some relationships. Assuming that node #18 owns pet #13, and nodes #18 and #22 are friends. Our graph will look like this:

![](/files/-MHV2qgvpjf19pB9L3-1)

But what happens if we try to connect the **pet** node with a **person** node with the **owns** relationship? (hopefully, this kind of scenario will not happen in the future!):

![](/files/-MHV37iFumJTTdazOwvI)

It fails.

But what if we tried to do that via the query editor?

![](/files/-MHV3yYTahTmq6o7f23J)

The query will fail.

## Create a Schema from an existing Graph

Assuming you already have a Gremlify Graph working, and you wish to attach a Schema to it:

![](/files/-MHV552tg2zfUS4aNFWc)

When we click on the **Schema** tab, a dialog pops up:

![](/files/-MHV4fr7qzpVWRVZXJq_)

By clicking yes, gremlify will take any node and edge in your graph, and create a schema out of them:

![](/files/-MHV6jfQharGTu-lTml5)

### What about the properties?

For any two given labeled entities, the algorithm will make a **union** of their properties. Ambiguous types will be handled arbitrarily.

For example, two **person** nodes (we'll call them X and Y) with the following properties:

| property  | X      | Y      |
| --------- | ------ | ------ |
| label     | person | person |
| name      | john   | emma   |
| age       | 26     | 34     |
| isMarried | true   | -      |

The resulting schema node will be:

| property  | type/value |
| --------- | ---------- |
| label     | person     |
| name      | string     |
| age       | number     |
| isMarried | boolean    |

## Altering a Schema

When altering an existing Schema, two main scenarios might take place:

#### The Schema is still synced with our Graph:

That means that the change has no actual effect on our existing graph. Nothing special happens in this scenario.

#### The Schema is now out of sync with our Graph:

Let's take a look at the following Schema from the previous example:

![](/files/-MHV9dFbxyQRkbOBG-gr)

Now if we decide to remove the **knows** edge from our schema. Immediately a dialog opens up

:

![](/files/-MHV9sx9uW8DKP_Xdm0F)

TL;DR. our Graph contains at least one edge with the **knows** label. If we hit **yes**, Gremlify will remove any edge in the Graph that is labeled with **knows**, and the resulting Graph will look as follows:

![](/files/-MHVAHpzsrjEqYOtgNbd)

The same goes for any node or property, including a scenario where a property type changes.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gremlify.gitbook.io/gremlify/schema.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
