HarperFast / HarperFast/harper

schema.graphql: support @default(value:) for automatic default values on write

Open
#663 0 comments 0 reactions 0 assignees View on GitHub
area:rest-api enhancement from-jira
Dominant language
JavaScript
Stars
89
Forks
10
Avg merge
2d 6h
Merged PRs (30d)
200

Description

Allow attributes in `schema.graphql` to declare a default value that is applied automatically when a record is created without that field.

## Proposed API

```graphql
type MyTable @table @export {
id: ID @primaryKey
status: String @default(value: "active")
createdAt: DateTime @default(value: "now")
score: Int @default(value: 0)
}
```

When a `PUT /MyTable` request omits `status`, Harper would set it to `"active"` transparently.

## Design considerations (Not Ready — needs decisions)

- **Where applied:** server-side only, or also reflected in the generated TypeScript types as non-optional?
- **Supported types:** scalar literals (`String`, `Int`, `Boolean`, `Float`), dynamic sentinels (`"now"` for datetime)?
- **Null vs. absent:** does a missing field apply the default, or only a missing field that's also `Non-Null`?
- **Interaction with `@computed`:** can a default coexist with a `@computed` directive?
- **Operations API path:** does the JSON operations API also get default application, or is it REST only?

## Acceptance criteria (once design is settled)

- Schema-defined defaults are applied transparently on write.
- Defaults are surfaced in the generated `.d.ts` types (non-optional).
- Documented with examples.

---

Jira fields: **Feature Type:** Product Feature Expansion · **Business Impact:** Customer Experience (GRR/NPS) *(both suggested)*

🤖 Filed by Claude on behalf of Kris.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.