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)
- Optionally, the schema can be used to present the target data with a GraphQL API.
TypeORM codegen
Thesquid-typeorm-codegen(1) tool is used to generate TypeORM entity classes from the schema defined in schema.graphql. Invoke it with
src/model/generated. Codegen
accepts either a single schema.graphql file or all .graphql files in a
schema/ directory.
Example
AFoo entity defined in the schema file:
schema.graphql
Foo entity with TypeORM decorators:
src/model/generated/foo.model.ts
StringColumn, BigIntColumn, BigDecimalColumn, BytesColumn, and
DateTimeColumn. Import these from @subsquid/typeorm-store when writing model
classes by hand.
Query and cost directives
Customize generated GraphQL root field names with arguments on@entity:
@fulltext(query:) can be applied to one or more String fields. TypeORM
codegen writes a migration that adds a generated PostgreSQL tsvector column
and GIN index for each participating entity.
OpenReader’s query-size estimator also understands @cardinality(value:) on
entities and relation fields, and @byteWeight(value:) on fields. These
annotations do not change the database schema. They provide expected result
counts and field sizes for the GraphQL server’s response-size limits.