Skip to content

Commit 0306747

Browse files
add(doc) - Relational and complex fields documentation (#10404)
* add - Relational and complex fields documentation * fix- wording * remove - relational fields docs
1 parent 2d5b216 commit 0306747

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

guides/the-manual/schemas/complex-fields.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,93 @@ order: 5
33
---
44

55
# Complex Fields
6+
7+
Complex Fields let you model nested or repeated structures inside a resource. They are useful when a resource contains structured data that is not itself a top-level resource.
8+
They always appear inside a [ResourceSchema](./resource-schemas.md).
9+
10+
## Schema Objects
11+
12+
A Schema Object represents a single embedded structure with no identity of its own.
13+
See also [ObjectSchemas](./object-schemas.md) for more details.
14+
15+
```ts [schemas/address.ts]
16+
export const AddressSchema = {
17+
type: 'address',
18+
identity: null,
19+
fields: [
20+
{ name: 'street', kind: 'field' },
21+
{ name: 'city', kind: 'field' },
22+
{ name: 'zipCode', kind: 'field' }
23+
]
24+
};
25+
```
26+
27+
```ts [schemas/user.ts]
28+
import { withDefaults } from '@warp-drive/core/reactive';
29+
import { AddressSchema } from './address';
30+
31+
export const UserSchema = withDefaults({
32+
type: 'user',
33+
fields: [
34+
{ name: 'id', kind: '@id' },
35+
{ name: 'name', kind: 'field' },
36+
{ name: 'address', kind: 'schema-object', type: 'address' }
37+
]
38+
});
39+
```
40+
41+
* `identity: null` marks the schema as embedded.
42+
* `schema-object` fields embed it inside another resource.
43+
* Embedded fields are reactive just like top-level fields.
44+
45+
## Schema Arrays
46+
47+
A Schema Array represents a list of embedded objects.
48+
49+
```ts [schemas/translation.ts]
50+
export const TranslationSchema = {
51+
type: 'translation',
52+
identity: null,
53+
fields: [
54+
{ name: 'locale', kind: 'field' },
55+
{ name: 'text', kind: 'field' }
56+
]
57+
};
58+
```
59+
60+
```ts [schemas/post.ts]
61+
import { withDefaults } from '@warp-drive/core/reactive';
62+
import { TranslationSchema } from './translation';
63+
64+
export const PostSchema = withDefaults({
65+
type: 'post',
66+
fields: [
67+
{ name: 'id', kind: '@id' },
68+
{ name: 'title', kind: 'field' },
69+
{ name: 'translations', kind: 'schema-array', type: 'translation' }
70+
]
71+
});
72+
```
73+
74+
This makes `post.translations` a reactive array of translation objects.
75+
76+
## Why Use Complex Fields
77+
78+
Complex Fields keep nested data structured without making it a top-level resource. They can be reused across schemas and work well for:
79+
80+
* Addresses or contact info.
81+
* Translations and localized content.
82+
* Structured metadata.
83+
* Tags or other small repeated objects.
84+
85+
All nested fields remain reactive, so UI updates flow naturally.
86+
87+
## Summary
88+
89+
Complex Fields come in two forms:
90+
91+
* `schema-object` for a single embedded object.
92+
* `schema-array` for a list of embedded objects.
93+
94+
They are ideal for representing nested data like addresses, translations, or metadata while keeping everything reactive and consistent.
95+
For defining the top-level shape of your data, see [ResourceSchemas](./resource-schemas.md).

0 commit comments

Comments
 (0)