Skip to main content


The schema definition in is crucial for defining the structure and shape of the data your solution will use. It represents the contract between the front end and the back end. With the schema definition, provides a standardized approach to define data types, queries, mutations, and subscriptions.

Schema definition is a core concept in - it is used to build the database, the migrations, the orm, the api, and the client. It really forms the "spine" of your solution.

Schema definition

The schema is defined in typescript, in the /schema folder of your solution. The reason it's in a different folder is because when you run a yarn build from your solution, the resulting classes and capabilities can be used by your solution to populate the front end with your new data models.

The core thfx models present a few very simple yet powerful concepts, that you can use to build your solution.

For example, in your solution's schema/models/patient.ts:

import { models } from "@thcare/thfx/prisma";
import FeedItem from "./feed-item.js";
import { createModel } from "@thcare/thschemix";

export default createModel("Patient", (model) =>
.float("latestA1c", {
optional: true,
.relation("feedItems", FeedItem, { list: true })

This enables you to extend the base "Patient" model with your own fields, and even add relationships to other models that you define.

The Graphql Explorer

To become familiar with the schema, you can use the Graphql Explorer. The Graphql Explorer is a tool that allows you to explore the schema and run queries against it. You can access the Graphql Explorer by visiting localhost:7071/api in your browser (or the port that your solution is running on in codespace). This will enable you to test queries and mutations against the api for use in your solution.


Everytime you update your schema, you can run yarn build to generate a new migration that will delta your database and your schema to make them match - you might immediately see that this can lead to tricky situations where you've generated migrations for development (i.e. incomplete) states in your schema. To avoid this, only commit migrations you are sure you want to source control, and make sure when you're ready to commit, you're sure the migrations are the correct ones. Migrations can be found in prisma/migrations.

Graphql Queries and Mutations

When you add a query or mutation to your source code, you don't need to fumble around with console.logging every little data object to see what's going on. if you run a yarn build after adding a query or mutation, you'll see that your IDE should pick up the types that result from the call. This means that you can use the typescript type system to explore the data that's coming back from your queries and mutations.