Data Schema in Tailor Platform
This tutorial demonstrates how a data schema is mapped to GraphQL APIs using the SDK.
- Complete the SDK Quickstart
Data Schema
A data model of your application is defined by the schema. Each type is typically defined in its own file for readability. See TailorDB Documentation to learn more about schema definition.
Tutorial Steps
- Define a data type
- View the schema in GraphQL playground
- See how the configuration maps to GraphQL APIs
1. Define a Data Type
Create a Project type in your application. In your project's db/ directory, create a file called project.ts:
import { db } from "@tailor-platform/sdk";
export const project = db.type("Project", {
name: db.string().description("Project name"),
description: db.string().optional().description("Project description"),
status: db
.enum(["planning", "active", "completed", "archived"])
.description("Current project status"),
startDate: db.string().optional().description("Project start date"),
endDate: db.string().optional().description("Project end date"),
budget: db.float().optional().description("Project budget"),
priority: db.enum(["low", "medium", "high", "critical"]).description("Project priority level"),
...db.fields.timestamps(),
});
export type project = typeof project;This TypeScript file defines a Project type with various fields:
- name: Required string field for the project name
- description: Optional string field for project details
- status: Enumeration field with predefined values
- startDate/endDate: Optional date fields
- budget: Optional float field for financial tracking
- priority: Enumeration for priority levels
- createdAt/updatedAt: Timestamp fields for tracking changes
Deploy this schema using:
npm run deploy -- --workspace-id <your-workspace-id>2. View the Schema in GraphQL Playground
Open the GraphQL playground by navigating to the Console and selecting your workspace. Click on "GraphQL Playground" to access the interactive API explorer.
3. See How the Configuration Maps to GraphQL APIs
Now that you've seen the schema definition in the TypeScript file, let's explore how this maps to the GraphQL API. In the GraphQL playground, you can test the API with a query like the one below:
query {
projects {
edges {
node {
id
name
description
status
priority
startDate
endDate
budget
createdAt
updatedAt
}
}
}
}This query will return a list of Project objects with the specified fields. You can see how the schema defined in the TypeScript file is automatically converted to GraphQL types and operations.
You'll notice some fields like id are generated automatically without being explicitly defined in the schema. These are pre-defined fields. Please refer to Auto-generated fields for more information.
The SDK automatically creates:
- Query operations:
project,projectsfor fetching data - Mutation operations:
createProject,updateProject,deleteProjectfor modifying data - Connection types: For pagination support with
edgesandnodestructure
Next Steps
Learn more about working with data schemas:
- TailorDB Service - Complete TailorDB reference
- Field Types - Available field types and options
- Relationships - Define relations between types
- Modifying Data Schema - How to update existing schemas
- Creating Data Schema - Add new types to your application