Skip to main content

Schema file and codegen

The schema file schema.graphql uses a GraphQL dialect to model the target entities and entity relations. The tooling around the schema file is then used to:

  • Generate TypeORM entities (with squid-typeorm-codegen(1), see below)
  • Generate the database schema from the TypeORM entities (see db migrations)
  • Present the target data with a rich API served by a built-in GraphQL Server. A full API reference is covered in the Query a Squid section.

The schema file format is loosely compatible with the subgraph schema file, see Migrate from subgraph section for details.

TypeORM codegen

The squid-typeorm-codegen(1) tool is used to generate TypeORM entity classes from the schema defined in schema.graphql. The most convenient way to run the tool is usually via the sqd wrapper:

sqd codegen
sqd build

By default the entity classes are generated in src/model/generated.


A Foo entity defined in the schema file:

type Foo @entity {
id: ID!
bar: String
baz: BigInt!

The generated Foo entity with TypeORM decorators:

import {Entity as Entity_, Column as Column_, PrimaryColumn as PrimaryColumn_} from "typeorm"
import * as marshal from "./marshal"

export class Foo {
constructor(props?: Partial<Foo>) {
Object.assign(this, props)

id!: string

@Column_("text", {nullable: true})
bar!: string | undefined | null

@Column_("numeric", {transformer: marshal.bigintTransformer, nullable: false})
baz!: bigint