YouBothAgent▾
You — Business rules and flows you own. Read these yourself.
Both — Know the idea; your agent follows the details.
Agent — Conventions and references your agent follows. Look up as needed.
Introduction▾
Tutorials▾
System Architecture▾
Module Convention▾
Scalar Convention▾
Scalar Types
Scalar types are primitive data types used in GraphQL and MongoDB schemas. Akan.js provides a set of predefined scalar types that map to GraphQL scalars and are used throughout the framework for type-safe model definitions.
Supported Scalar Types
📦Import from @akanjs/base
import { ID, Int, Float, Upload, JSON } from "@akanjs/base";Scalar Type Reference Table
Complete reference of all scalar types with their GraphQL mapping, MongoDB type, default values, and example usage.
| Type | GraphQL | MongoDB | Default | Example Value |
|---|---|---|---|---|
String | String | String | "" | "Hello World" |
Boolean | Boolean | Boolean | false | true |
Date | Date (custom) | Date | dayjs(new Date(-1)) | "2024-01-15T09:30:00Z" |
ID | ID | ObjectId | null | "1234567890abcdef12345678" |
Int | Int | Number | 0 | 42 |
Float | Float | Number | 0 | 3.14159 |
Upload | Upload (GraphQL Upload) | - | - | FileUpload stream |
JSON | JSON (custom) | Mixed | {} | { "key": "value" } |
Map | JSON | Map | {} | { "a": 1, "b": 2 } |


Blue types (String, Boolean, Date) are JavaScript built-ins. Purple types (ID, Int, Float, Upload, JSON) are custom Akan.js classes that need to be imported.
constant.ts Scalars
Scalar types are used in constant.ts files to define model field types. Here are practical examples of how each scalar type is used:
String - Text Data
String Usage
Boolean - True/False
Boolean Usage
Date - Date and Time
Date Usage
Int & Float - Numbers
Int & Float Usage
ID - MongoDB ObjectId
ID Usage
JSON - Arbitrary Data
JSON Usage
Complete Model Example
Here's a complete example showing various scalar types used together in a model definition:
article.constant.ts
💡Scalar Types Used
- String: title, slug
- Boolean: isPublic, isFeatured
- Int: viewCount, likeCount, commentCount
- Float: rating
- Date: publishedAt, lastEditedAt
- ID: authorId, tagIds
- JSON: content, seoMeta
Scalar Best Practices
1️⃣Use Int for Counts and Quantities
Use Int instead of Float for whole numbers like counts, quantities, and IDs. It provides better performance and prevents floating-point issues.
2️⃣Use dayjs() for Date Defaults
Always use a function for Date defaults: { default: () => dayjs() }. Static defaults would capture the build time, not creation time.
3️⃣Use ID for Document References
Use ID type when you need to store a reference to another MongoDB document. It automatically converts to ObjectId in the database.
4️⃣Use JSON for Flexible Content
Use JSON type for rich text content (TipTap editor), flexible metadata, or configuration objects. Avoid using it for structured data - define proper fields instead.
🎉 What You've Learned:
- ✓ 9 scalar types: String, Boolean, Date, ID, Int, Float, Upload, JSON, Map
- ✓ Custom scalar classes (ID, Int, Float, Upload, JSON) from @akanjs/base
- ✓ GraphQL and MongoDB type mappings for each scalar
- ✓ Practical usage patterns in constant.ts model definitions