@bairock/lenz 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -41,7 +41,8 @@ type User @model {
41
41
  id: ID! @id
42
42
  email: String! @unique
43
43
  name: String!
44
- posts: [Post!]! @relation(field: "authorId")
44
+ posts: [Post!]! @relation(field: "postIds")
45
+ postIds: [ID!]!
45
46
  createdAt: DateTime! @createdAt
46
47
  updatedAt: DateTime! @updatedAt
47
48
  }
@@ -142,10 +143,66 @@ Lenz extends GraphQL with custom directives:
142
143
  - `@unique` - Creates a unique index
143
144
  - `@index` - Creates a regular index
144
145
  - `@default(value: "...")` - Sets default value
145
- - `@relation(field: "...")` - Defines relation field
146
+ - `@relation(field: "...")` - Defines relation field (foreign key must be in the same model)
146
147
  - `@createdAt` - Auto-sets creation timestamp
147
148
  - `@updatedAt` - Auto-updates timestamp
148
149
 
150
+ ## Relations
151
+
152
+ Lenz requires explicit foreign key fields for all relation types:
153
+
154
+ ### One-to-Many / Many-to-One
155
+ A bidirectional relationship where one side has an array and the other has a single reference:
156
+
157
+ ```graphql
158
+ type Author @model {
159
+ id: ID! @id
160
+ books: [Book!]! @relation(field: "bookIds") # one-to-many side
161
+ bookIds: [ID!]! # array of Book IDs in Author document
162
+ }
163
+
164
+ type Book @model {
165
+ id: ID! @id
166
+ author: Author! @relation(field: "authorId") # many-to-one side
167
+ authorId: ID! # single Author ID in Book document
168
+ }
169
+ ```
170
+
171
+ - **Author → Book (one-to-many):** Foreign key `bookIds` is an array of IDs in the Author document
172
+ - **Book → Author (many-to-one):** Foreign key `authorId` is a single ID in the Book document
173
+
174
+ ### One-to-One (foreign key single ID in source model)
175
+ ```graphql
176
+ type User @model {
177
+ id: ID! @id
178
+ profile: Profile @relation(field: "profileId")
179
+ profileId: ID
180
+ }
181
+
182
+ type Profile @model {
183
+ id: ID! @id
184
+ user: User @relation(field: "userId")
185
+ userId: ID
186
+ }
187
+ ```
188
+
189
+ ### Many-to-Many (ID arrays on both sides)
190
+ ```graphql
191
+ type Post @model {
192
+ id: ID! @id
193
+ categories: [Category!]! @relation(field: "categoryIds")
194
+ categoryIds: [ID!]!
195
+ }
196
+
197
+ type Category @model {
198
+ id: ID! @id
199
+ posts: [Post!]! @relation(field: "postIds")
200
+ postIds: [ID!]!
201
+ }
202
+ ```
203
+
204
+ **Important:** Foreign keys must always be in the **source model** (the model containing the `@relation` directive). Classic one-to-many patterns with foreign keys in target models will cause validation errors.
205
+
149
206
  ## Supported Field Types
150
207
 
151
208
  - `String`
@@ -1 +1 @@
1
- {"version":3,"file":"CodeGenerator.d.ts","sourceRoot":"","sources":["../../src/engine/CodeGenerator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG3E,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,KAAK,EAAE,WAAW,EAAE,CAAC;IACrB,SAAS,EAAE,aAAa,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,OAAO,CAUb;IAEF,OAAO,CAAC,6BAA6B;IAyBrC,OAAO,CAAC,wBAAwB;IAyBhC,OAAO,CAAC,sBAAsB;IA8B9B,OAAO,CAAC,mBAAmB;IAO3B,OAAO,CAAC,wBAAwB;IA4IhC,OAAO,CAAC,oBAAoB;IAM5B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,cAAc;IAmClD,OAAO,CAAC,aAAa;IAkBrB,OAAO,CAAC,cAAc;IAwLtB,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,aAAa;IAiKrB,OAAO,CAAC,iBAAiB;IA+BzB,OAAO,CAAC,WAAW;IAUnB,OAAO,CAAC,aAAa;IAiBrB,OAAO,CAAC,yBAAyB;I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