Migrate Subgraph
If you have an existing subgraph project that you want to migrate to the Blockflow system, follow this guide to ensure a smooth transition.
Configuring the studio.yaml file
Start by comparing your existing subgraph.yaml
file with the studio.yaml
file used in the Blockflow system. Both files serve as the entry point for configuring the subgraph, but the structure and naming conventions may differ.
subgraph.yaml
studio.yaml
Comparing the Schema
Next, compare your existing schema.graphql
file with the studio.schema.ts
file used in the Blockflow system. While the schema.graphql
file uses the GraphQL Schema Definition Language (SDL), the studio.schema.ts
file utilizes TypeScript interfaces to define the data model and entities.
Ensure that all entities and their fields are correctly mapped between the two schema files. You may need to make adjustments to the studio.schema.ts
file to ensure compatibility with the Blockflow system.
schema.graphql
studio.schema.ts
During the migration process, it's important to note that the conversion between types and interfaces should be handled correctly:
Types to Interfaces: Any object types defined in the
schema.graphql
file should be converted to TypeScript interfaces in thestudio.schema.ts
file.Interfaces to Types: Conversely, any interfaces defined in the
schema.graphql
file should be converted to TypeScript types in thestudio.schema.ts
file.
schema.graphql
studio.schema.ts
Transforming Mapping Handlers
In the Blockflow system, each handler function for a specific trigger (event or function) must be written in a separate file. This file structure aligns with the configuration defined in the studio.yaml
file, where each trigger is listed with its corresponding handler file path.
Syntax Changes
When migrating from an existing subgraph to the Blockflow system, there are a few syntax changes you'll need to make in your handler functions:
Retrieving and Creating Entities:
In the subgraph, you use the
.load()
function to retrieve entities.In blockflow, you should use a combination of
findOne
andcreate
functions.First, use
findOne
to check if an entity with the given criteria exists. If it does, you can update and save the existing entity.If
findOne
returnsnull
, meaning the entity does not exist, you can use thecreate
function to create a new entity instance.
subgraph syntax
blockflow syntax
Saving Entities:
In the Blockflow system, there is a minor difference in the syntax for saving entities.
Instead of using
entity.save()
directly, you should use thesave
function returned by thebind
function.The
save
function takes the entity instance as an argument.
subgraph syntax
blockflow syntax