When using the Block Protocol's graph module, data is shared between applications and blocks in the form of 'entities', and each entity has a type, known as an 'entity type'.
This type describes what properties an entity has, what type of value each is expected to be, and the relationship between the entity in question and other entities.
Relationships between entities are known as 'links' and they too are entities, which means they may have properties and relations to other entities.
The system by which types are defined is known as the 'type system'.
The Block Protocol type system is designed so that types are composed of re-usable, sharable parts, which can be referenced by other users and by other types.
The type system consists of three classes of elements:
The easiest way to get started is to visit your dashboard and click 'create an entity type'.
Give your entity type a name and a description, and then click 'create'.
You can now define the properties your entity expects:
You can also define the links your entity expects following a similar process:
Make sure to click 'publish update' when you're done to release a new version of the entity type.
Once you have a type which describes the data your block expects, copy the URL from your browser.
You can enter this as the value for schema
in the blockprotocol
object of your block source's package.json
, and
run yarn schema
to automatically generate TypeScript types from it.
You can also view the raw JSON of any type by a simple fetch or curl:
fetch("https://blockprotocol.org/@blockprotocol/types/entity-type/thing/v/2")
.then((resp) => resp.json())
.then(console.log);
curl https://blockprotocol.org/@blockprotocol/types/entity-type/thing/v/2
Previous
Next