@gqlkit-ts/cli 0.2.0 → 0.3.0

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.
Files changed (190) hide show
  1. package/dist/auto-type-generator/auto-type-generator.d.ts +10 -4
  2. package/dist/auto-type-generator/auto-type-generator.d.ts.map +1 -1
  3. package/dist/auto-type-generator/auto-type-generator.js +640 -133
  4. package/dist/auto-type-generator/auto-type-generator.js.map +1 -1
  5. package/dist/auto-type-generator/index.d.ts +8 -1
  6. package/dist/auto-type-generator/index.d.ts.map +1 -1
  7. package/dist/auto-type-generator/index.js +3 -0
  8. package/dist/auto-type-generator/index.js.map +1 -1
  9. package/dist/auto-type-generator/inline-enum-collector.d.ts +13 -5
  10. package/dist/auto-type-generator/inline-enum-collector.d.ts.map +1 -1
  11. package/dist/auto-type-generator/inline-enum-collector.js +107 -71
  12. package/dist/auto-type-generator/inline-enum-collector.js.map +1 -1
  13. package/dist/auto-type-generator/inline-object-traverser.d.ts +20 -0
  14. package/dist/auto-type-generator/inline-object-traverser.d.ts.map +1 -0
  15. package/dist/auto-type-generator/inline-object-traverser.js +22 -0
  16. package/dist/auto-type-generator/inline-object-traverser.js.map +1 -0
  17. package/dist/auto-type-generator/inline-union-collector.d.ts +29 -0
  18. package/dist/auto-type-generator/inline-union-collector.d.ts.map +1 -0
  19. package/dist/auto-type-generator/inline-union-collector.js +216 -0
  20. package/dist/auto-type-generator/inline-union-collector.js.map +1 -0
  21. package/dist/auto-type-generator/inline-union-types.d.ts +29 -0
  22. package/dist/auto-type-generator/inline-union-types.d.ts.map +1 -0
  23. package/dist/auto-type-generator/inline-union-types.js +2 -0
  24. package/dist/auto-type-generator/inline-union-types.js.map +1 -0
  25. package/dist/auto-type-generator/inline-union-validator.d.ts +76 -0
  26. package/dist/auto-type-generator/inline-union-validator.d.ts.map +1 -0
  27. package/dist/auto-type-generator/inline-union-validator.js +329 -0
  28. package/dist/auto-type-generator/inline-union-validator.js.map +1 -0
  29. package/dist/auto-type-generator/naming-convention.d.ts +18 -1
  30. package/dist/auto-type-generator/naming-convention.d.ts.map +1 -1
  31. package/dist/auto-type-generator/naming-convention.js +16 -0
  32. package/dist/auto-type-generator/naming-convention.js.map +1 -1
  33. package/dist/auto-type-generator/resolve-type-generator.d.ts +20 -0
  34. package/dist/auto-type-generator/resolve-type-generator.d.ts.map +1 -0
  35. package/dist/auto-type-generator/resolve-type-generator.js +2 -0
  36. package/dist/auto-type-generator/resolve-type-generator.js.map +1 -0
  37. package/dist/auto-type-generator/resolver-field-iterator.d.ts +13 -0
  38. package/dist/auto-type-generator/resolver-field-iterator.d.ts.map +1 -0
  39. package/dist/auto-type-generator/resolver-field-iterator.js +22 -0
  40. package/dist/auto-type-generator/resolver-field-iterator.js.map +1 -0
  41. package/dist/auto-type-generator/typename-extractor.d.ts +26 -0
  42. package/dist/auto-type-generator/typename-extractor.d.ts.map +1 -0
  43. package/dist/auto-type-generator/typename-extractor.js +142 -0
  44. package/dist/auto-type-generator/typename-extractor.js.map +1 -0
  45. package/dist/auto-type-generator/typename-resolve-type-generator.d.ts +35 -0
  46. package/dist/auto-type-generator/typename-resolve-type-generator.d.ts.map +1 -0
  47. package/dist/auto-type-generator/typename-resolve-type-generator.js +177 -0
  48. package/dist/auto-type-generator/typename-resolve-type-generator.js.map +1 -0
  49. package/dist/auto-type-generator/typename-types.d.ts +43 -0
  50. package/dist/auto-type-generator/typename-types.d.ts.map +1 -0
  51. package/dist/auto-type-generator/typename-types.js +37 -0
  52. package/dist/auto-type-generator/typename-types.js.map +1 -0
  53. package/dist/auto-type-generator/typename-validator.d.ts +37 -0
  54. package/dist/auto-type-generator/typename-validator.d.ts.map +1 -0
  55. package/dist/auto-type-generator/typename-validator.js +206 -0
  56. package/dist/auto-type-generator/typename-validator.js.map +1 -0
  57. package/dist/cli.js +2 -0
  58. package/dist/cli.js.map +1 -1
  59. package/dist/commands/docs.d.ts +51 -0
  60. package/dist/commands/docs.d.ts.map +1 -0
  61. package/dist/commands/docs.js +154 -0
  62. package/dist/commands/docs.js.map +1 -0
  63. package/dist/gen-orchestrator/orchestrator.d.ts.map +1 -1
  64. package/dist/gen-orchestrator/orchestrator.js +13 -6
  65. package/dist/gen-orchestrator/orchestrator.js.map +1 -1
  66. package/dist/resolver-extractor/extract-resolvers.d.ts +19 -1
  67. package/dist/resolver-extractor/extract-resolvers.d.ts.map +1 -1
  68. package/dist/resolver-extractor/extractor/define-api-extractor.d.ts +5 -0
  69. package/dist/resolver-extractor/extractor/define-api-extractor.d.ts.map +1 -1
  70. package/dist/resolver-extractor/extractor/define-api-extractor.js +14 -61
  71. package/dist/resolver-extractor/extractor/define-api-extractor.js.map +1 -1
  72. package/dist/resolver-extractor/index.d.ts +0 -1
  73. package/dist/resolver-extractor/index.d.ts.map +1 -1
  74. package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts +1 -0
  75. package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts.map +1 -1
  76. package/dist/resolver-extractor/validator/abstract-resolver-validator.js +9 -5
  77. package/dist/resolver-extractor/validator/abstract-resolver-validator.js.map +1 -1
  78. package/dist/schema-generator/emitter/code-emitter.d.ts.map +1 -1
  79. package/dist/schema-generator/emitter/code-emitter.js +20 -0
  80. package/dist/schema-generator/emitter/code-emitter.js.map +1 -1
  81. package/dist/schema-generator/generate-schema.d.ts +1 -0
  82. package/dist/schema-generator/generate-schema.d.ts.map +1 -1
  83. package/dist/schema-generator/generate-schema.js +72 -3
  84. package/dist/schema-generator/generate-schema.js.map +1 -1
  85. package/dist/schema-generator/integrator/result-integrator.d.ts +14 -2
  86. package/dist/schema-generator/integrator/result-integrator.d.ts.map +1 -1
  87. package/dist/schema-generator/integrator/result-integrator.js +54 -1
  88. package/dist/schema-generator/integrator/result-integrator.js.map +1 -1
  89. package/dist/schema-generator/resolver-collector/resolver-collector.d.ts +2 -0
  90. package/dist/schema-generator/resolver-collector/resolver-collector.d.ts.map +1 -1
  91. package/dist/schema-generator/resolver-collector/resolver-collector.js +22 -0
  92. package/dist/schema-generator/resolver-collector/resolver-collector.js.map +1 -1
  93. package/dist/shared/enum-prefix-detector.d.ts +63 -0
  94. package/dist/shared/enum-prefix-detector.d.ts.map +1 -0
  95. package/dist/shared/enum-prefix-detector.js +80 -0
  96. package/dist/shared/enum-prefix-detector.js.map +1 -0
  97. package/dist/shared/ignore-fields-detector.d.ts +26 -0
  98. package/dist/shared/ignore-fields-detector.d.ts.map +1 -0
  99. package/dist/shared/ignore-fields-detector.js +83 -0
  100. package/dist/shared/ignore-fields-detector.js.map +1 -0
  101. package/dist/shared/ignore-fields-validator.d.ts +29 -0
  102. package/dist/shared/ignore-fields-validator.d.ts.map +1 -0
  103. package/dist/shared/ignore-fields-validator.js +43 -0
  104. package/dist/shared/ignore-fields-validator.js.map +1 -0
  105. package/dist/shared/index.d.ts +2 -0
  106. package/dist/shared/index.d.ts.map +1 -1
  107. package/dist/shared/index.js.map +1 -1
  108. package/dist/shared/source-location.d.ts +5 -0
  109. package/dist/shared/source-location.d.ts.map +1 -1
  110. package/dist/shared/source-location.js +7 -0
  111. package/dist/shared/source-location.js.map +1 -1
  112. package/dist/type-extractor/converter/graphql-converter.d.ts.map +1 -1
  113. package/dist/type-extractor/converter/graphql-converter.js +21 -7
  114. package/dist/type-extractor/converter/graphql-converter.js.map +1 -1
  115. package/dist/type-extractor/extractor/field-type-resolver.js +42 -3
  116. package/dist/type-extractor/extractor/field-type-resolver.js.map +1 -1
  117. package/dist/type-extractor/extractor/type-extractor.d.ts.map +1 -1
  118. package/dist/type-extractor/extractor/type-extractor.js +88 -23
  119. package/dist/type-extractor/extractor/type-extractor.js.map +1 -1
  120. package/dist/type-extractor/types/diagnostics.d.ts +1 -1
  121. package/dist/type-extractor/types/diagnostics.d.ts.map +1 -1
  122. package/dist/type-extractor/types/ts-type-reference-factory.d.ts +10 -2
  123. package/dist/type-extractor/types/ts-type-reference-factory.d.ts.map +1 -1
  124. package/dist/type-extractor/types/ts-type-reference-factory.js +8 -2
  125. package/dist/type-extractor/types/ts-type-reference-factory.js.map +1 -1
  126. package/dist/type-extractor/types/typescript.d.ts +4 -0
  127. package/dist/type-extractor/types/typescript.d.ts.map +1 -1
  128. package/docs/coding-agents.md +64 -0
  129. package/docs/configuration.md +6 -20
  130. package/docs/getting-started.md +15 -12
  131. package/docs/index.md +36 -22
  132. package/docs/integration/apollo.md +8 -40
  133. package/docs/integration/drizzle.md +6 -10
  134. package/docs/integration/prisma.md +196 -0
  135. package/docs/integration/yoga.md +8 -40
  136. package/docs/schema/abstract-resolvers.md +117 -0
  137. package/docs/schema/directives.md +5 -0
  138. package/docs/schema/documentation.md +5 -0
  139. package/docs/schema/enums.md +99 -0
  140. package/docs/schema/fields.md +64 -0
  141. package/docs/schema/index.md +21 -0
  142. package/docs/schema/inputs.md +115 -15
  143. package/docs/schema/interfaces.md +31 -1
  144. package/docs/schema/objects.md +40 -0
  145. package/docs/schema/queries-mutations.md +136 -22
  146. package/docs/schema/scalars.md +5 -0
  147. package/docs/schema/unions.md +208 -1
  148. package/docs/what-is-gqlkit.md +13 -8
  149. package/package.json +6 -4
  150. package/src/auto-type-generator/auto-type-generator.ts +946 -201
  151. package/src/auto-type-generator/index.ts +42 -0
  152. package/src/auto-type-generator/inline-enum-collector.ts +187 -139
  153. package/src/auto-type-generator/inline-object-traverser.ts +49 -0
  154. package/src/auto-type-generator/inline-union-collector.ts +402 -0
  155. package/src/auto-type-generator/inline-union-types.ts +33 -0
  156. package/src/auto-type-generator/inline-union-validator.ts +482 -0
  157. package/src/auto-type-generator/naming-convention.ts +38 -1
  158. package/src/auto-type-generator/resolve-type-generator.ts +21 -0
  159. package/src/auto-type-generator/resolver-field-iterator.ts +39 -0
  160. package/src/auto-type-generator/typename-extractor.ts +230 -0
  161. package/src/auto-type-generator/typename-resolve-type-generator.ts +281 -0
  162. package/src/auto-type-generator/typename-types.ts +66 -0
  163. package/src/auto-type-generator/typename-validator.ts +326 -0
  164. package/src/cli.ts +2 -0
  165. package/src/commands/docs.ts +211 -0
  166. package/src/gen-orchestrator/orchestrator.ts +20 -6
  167. package/src/resolver-extractor/extract-resolvers.ts +19 -0
  168. package/src/resolver-extractor/extractor/define-api-extractor.ts +23 -89
  169. package/src/resolver-extractor/index.ts +0 -6
  170. package/src/resolver-extractor/validator/abstract-resolver-validator.ts +16 -8
  171. package/src/schema-generator/emitter/code-emitter.ts +34 -0
  172. package/src/schema-generator/generate-schema.ts +99 -2
  173. package/src/schema-generator/integrator/result-integrator.ts +70 -1
  174. package/src/schema-generator/resolver-collector/resolver-collector.ts +34 -0
  175. package/src/shared/enum-prefix-detector.ts +99 -0
  176. package/src/shared/ignore-fields-detector.ts +109 -0
  177. package/src/shared/ignore-fields-validator.ts +66 -0
  178. package/src/shared/index.ts +2 -0
  179. package/src/shared/source-location.ts +11 -0
  180. package/src/type-extractor/converter/graphql-converter.ts +31 -7
  181. package/src/type-extractor/extractor/field-type-resolver.ts +48 -3
  182. package/src/type-extractor/extractor/type-extractor.ts +103 -26
  183. package/src/type-extractor/types/diagnostics.ts +12 -2
  184. package/src/type-extractor/types/ts-type-reference-factory.ts +18 -5
  185. package/src/type-extractor/types/typescript.ts +4 -0
  186. package/dist/resolver-extractor/validator/only-validator.d.ts +0 -61
  187. package/dist/resolver-extractor/validator/only-validator.d.ts.map +0 -1
  188. package/dist/resolver-extractor/validator/only-validator.js +0 -76
  189. package/dist/resolver-extractor/validator/only-validator.js.map +0 -1
  190. package/src/resolver-extractor/validator/only-validator.ts +0 -158
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Enum Types
3
+ description: gqlkit converts TypeScript string literal unions and enums to GraphQL enum types.
4
+ ---
5
+
1
6
  # Enum Types
2
7
 
3
8
  gqlkit converts TypeScript string literal unions and enums to GraphQL enum types.
@@ -273,6 +278,54 @@ export type User = {
273
278
  };
274
279
  ```
275
280
 
281
+ ### Inline Enum Payloads
282
+
283
+ String literal unions in resolver return types generate GraphQL Enum types with the naming convention `{ResolverName}Payload`:
284
+
285
+ ```typescript
286
+ export const getStatus = defineQuery<NoArgs, "active" | "inactive" | "pending">(
287
+ (_root, _args, ctx) => ctx.db.getStatus()
288
+ );
289
+ ```
290
+
291
+ Generates:
292
+
293
+ ```graphql
294
+ type Query {
295
+ getStatus: GetStatusPayload!
296
+ }
297
+
298
+ enum GetStatusPayload {
299
+ ACTIVE
300
+ INACTIVE
301
+ PENDING
302
+ }
303
+ ```
304
+
305
+ For field resolvers, the naming convention is `{ParentTypeName}{PascalCaseFieldName}Payload`:
306
+
307
+ ```typescript
308
+ export const status = defineField<User, NoArgs, "online" | "offline" | "away">(
309
+ (parent) => parent.currentStatus
310
+ );
311
+ ```
312
+
313
+ Generates:
314
+
315
+ ```graphql
316
+ type User {
317
+ status: UserStatusPayload!
318
+ }
319
+
320
+ enum UserStatusPayload {
321
+ ONLINE
322
+ OFFLINE
323
+ AWAY
324
+ }
325
+ ```
326
+
327
+ See [Queries & Mutations](./queries-mutations.md#inline-payload-types) for more details on inline payload types.
328
+
276
329
  ## Automatic Case Conversion
277
330
 
278
331
  gqlkit automatically converts enum values to `SCREAMING_SNAKE_CASE` format, which is the GraphQL convention:
@@ -310,6 +363,52 @@ export function createResolvers() {
310
363
 
311
364
  If values are already in `SCREAMING_SNAKE_CASE`, no resolver mapping is generated.
312
365
 
366
+ ### Automatic Prefix Stripping
367
+
368
+ When all enum values share a common prefix that matches the enum name, gqlkit automatically strips the prefix to produce cleaner GraphQL values:
369
+
370
+ ```typescript
371
+ export type UserStatus = "USER_STATUS_ACTIVE" | "USER_STATUS_INACTIVE" | "USER_STATUS_PENDING";
372
+ ```
373
+
374
+ Generates:
375
+
376
+ ```graphql
377
+ enum UserStatus {
378
+ ACTIVE
379
+ INACTIVE
380
+ PENDING
381
+ }
382
+ ```
383
+
384
+ This works with various naming conventions:
385
+
386
+ | TypeScript Enum | Values | Generated GraphQL Values |
387
+ |-----------------|--------|--------------------------|
388
+ | `UserStatus` | `USER_STATUS_ACTIVE`, `USER_STATUS_INACTIVE` | `ACTIVE`, `INACTIVE` |
389
+ | `orderStatus` | `ORDER_STATUS_PENDING`, `ORDER_STATUS_SHIPPED` | `PENDING`, `SHIPPED` |
390
+ | `Status` | `STATUS_ACTIVE`, `STATUS_INACTIVE` | `ACTIVE`, `INACTIVE` |
391
+
392
+ Prefix stripping is **not applied** when:
393
+
394
+ - Not all values share the common prefix
395
+ - Stripping would result in an empty value (e.g., `USER_STATUS_` for `UserStatus`)
396
+
397
+ When prefix stripping is applied, gqlkit generates resolver mappings to preserve the original TypeScript values:
398
+
399
+ ```typescript
400
+ // Generated resolvers.ts
401
+ export function createResolvers() {
402
+ return {
403
+ UserStatus: {
404
+ ACTIVE: "USER_STATUS_ACTIVE",
405
+ INACTIVE: "USER_STATUS_INACTIVE",
406
+ PENDING: "USER_STATUS_PENDING",
407
+ },
408
+ };
409
+ }
410
+ ```
411
+
313
412
  ### Duplicate Value Detection
314
413
 
315
414
  If multiple TypeScript values convert to the same GraphQL enum value, gqlkit reports a `DUPLICATE_ENUM_VALUE_AFTER_CONVERSION` error:
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Field Resolvers
3
+ description: Add computed fields to object types using defineField.
4
+ ---
5
+
1
6
  # Field Resolvers
2
7
 
3
8
  Add computed fields to object types using `defineField`. Define them alongside the type.
@@ -122,6 +127,65 @@ input UserPostsFilterInput {
122
127
 
123
128
  Inline string literal unions and external TypeScript enums in arguments are also automatically converted to GraphQL enum types. See [Inline Enums](./enums.md#inline-enums) for details.
124
129
 
130
+ ## Inline Payload Types
131
+
132
+ Field resolver return types can use inline object literals. gqlkit automatically generates GraphQL Object types with the naming convention `{ParentTypeName}{PascalCaseFieldName}Payload`:
133
+
134
+ ```typescript
135
+ export const statistics = defineField<
136
+ User,
137
+ NoArgs,
138
+ { postCount: number; followerCount: number; isActive: boolean }
139
+ >((parent, _args, ctx) => ctx.db.getUserStatistics(parent.id));
140
+ ```
141
+
142
+ Generates:
143
+
144
+ ```graphql
145
+ type User {
146
+ statistics: UserStatisticsPayload!
147
+ }
148
+
149
+ type UserStatisticsPayload {
150
+ postCount: Float!
151
+ followerCount: Float!
152
+ isActive: Boolean!
153
+ }
154
+ ```
155
+
156
+ ### Inline Union Payloads
157
+
158
+ Union types with inline object literals generate GraphQL Union types. Each union member must have a `__typename` property:
159
+
160
+ ```typescript
161
+ export const verification = defineField<
162
+ User,
163
+ NoArgs,
164
+ | { __typename: "Verified"; verifiedAt: string }
165
+ | { __typename: "Unverified"; reason: string }
166
+ >((parent) => parent.verification);
167
+ ```
168
+
169
+ Generates:
170
+
171
+ ```graphql
172
+ type User {
173
+ verification: UserVerificationPayload!
174
+ }
175
+
176
+ union UserVerificationPayload = Unverified | Verified
177
+
178
+ type Verified {
179
+ verifiedAt: String!
180
+ }
181
+
182
+ type Unverified {
183
+ reason: String!
184
+ }
185
+ ```
186
+
187
+ See [Queries & Mutations](./queries-mutations.md#inline-payload-types) for more details on inline payload types.
188
+
125
189
  ## Default Values in Arguments
126
190
 
127
191
  Default values in Input Objects are applied to resolver arguments:
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Schema Definition
3
+ description: gqlkit generates GraphQL schema from your TypeScript types.
4
+ ---
5
+
1
6
  # Schema Definition
2
7
 
3
8
  gqlkit generates GraphQL schema from your TypeScript types. All exported types from `src/gqlkit/schema/` are automatically scanned and converted to GraphQL types.
@@ -23,6 +28,22 @@ gqlkit maps TypeScript types to GraphQL types as follows:
23
28
  | Union with `*Input` suffix | `@oneOf` input object |
24
29
  | `GqlInterface<T>` | Interface type |
25
30
  | `GqlScalar<Name, Base>` | Custom scalar |
31
+ | `NoArgs` | Indicates resolver takes no arguments |
32
+
33
+ ## Naming Conventions
34
+
35
+ gqlkit generates type names using predictable conventions:
36
+
37
+ | Context | Pattern | Example |
38
+ |---------|---------|---------|
39
+ | Object field (inline) | `{ParentType}{Field}` | `User.profile` → `UserProfile` |
40
+ | Input field (inline) | `{ParentWithoutInput}{Field}Input` | `CreateUserInput.address` → `CreateUserAddressInput` |
41
+ | Query/Mutation arg | `{Resolver}{Arg}Input` | `searchUsers(filter)` → `SearchUsersFilterInput` |
42
+ | Field resolver arg | `{Parent}{Field}{Arg}Input` | `User.posts(filter)` → `UserPostsFilterInput` |
43
+ | Inline enum | Same as parent context | `User.status` → `UserStatus` |
44
+ | Payload type | `{Resolver}Payload` | `updateUser` → `UpdateUserPayload` |
45
+
46
+ For complete details on inline enum naming, see [Inline Enums](./enums.md#inline-enums).
26
47
 
27
48
  ## Project Layout
28
49
 
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Input Types
3
+ description: TypeScript types with Input suffix are treated as GraphQL input types.
4
+ ---
5
+
1
6
  # Input Types
2
7
 
3
8
  TypeScript types with `Input` suffix are treated as GraphQL input types.
@@ -91,6 +96,94 @@ input ProductInput @oneOf {
91
96
 
92
97
  Each property becomes a nullable field in the generated input type. The `@oneOf` directive ensures exactly one field is provided at runtime.
93
98
 
99
+ ### Inline @oneOf in Input Fields
100
+
101
+ Union types can be used as field types within Input Objects to create nested `@oneOf` input objects. The generated type name follows the convention `{ParentTypeNameWithoutInputSuffix}{PascalCaseFieldName}Input`:
102
+
103
+ ```typescript
104
+ export type CreateUserInput = {
105
+ name: string;
106
+ /**
107
+ * User identifier - either by ID or email
108
+ */
109
+ identifier: { id: string } | { email: string };
110
+ };
111
+ ```
112
+
113
+ Generates:
114
+
115
+ ```graphql
116
+ input CreateUserInput {
117
+ name: String!
118
+ """User identifier - either by ID or email"""
119
+ identifier: CreateUserIdentifierInput!
120
+ }
121
+
122
+ input CreateUserIdentifierInput @oneOf {
123
+ email: String
124
+ id: String
125
+ }
126
+ ```
127
+
128
+ ### Inline @oneOf in Resolver Arguments
129
+
130
+ Inline unions in resolver arguments are also converted to `@oneOf` input objects:
131
+
132
+ **Query/Mutation arguments** - naming convention: `{PascalCaseResolverName}{PascalCaseArgPath}Input`
133
+
134
+ ```typescript
135
+ export const findUser = defineQuery<
136
+ {
137
+ criteria: {
138
+ identifier: { id: string } | { email: string };
139
+ };
140
+ },
141
+ User | null
142
+ >(...);
143
+ ```
144
+
145
+ Generates:
146
+
147
+ ```graphql
148
+ input FindUserCriteriaIdentifierInput @oneOf {
149
+ email: String
150
+ id: String
151
+ }
152
+
153
+ input FindUserCriteriaInput {
154
+ identifier: FindUserCriteriaIdentifierInput!
155
+ }
156
+
157
+ type Query {
158
+ findUser(criteria: FindUserCriteriaInput!): User
159
+ }
160
+ ```
161
+
162
+ **Field resolver arguments** - naming convention: `{ParentTypeName}{PascalCaseFieldName}{PascalCaseArgPath}Input`
163
+
164
+ ```typescript
165
+ export const posts = defineField<
166
+ User,
167
+ {
168
+ filter: { status: string } | { createdAfter: string } | null;
169
+ },
170
+ Post[]
171
+ >(...);
172
+ ```
173
+
174
+ Generates:
175
+
176
+ ```graphql
177
+ input UserPostsFilterInput @oneOf {
178
+ createdAfter: String
179
+ status: String
180
+ }
181
+
182
+ type User {
183
+ posts(filter: UserPostsFilterInput): [Post!]!
184
+ }
185
+ ```
186
+
94
187
  ## Default Values
95
188
 
96
189
  Specify default values for Input Object fields using `GqlField` with the `defaultValue` option.
@@ -250,30 +343,37 @@ export type BadInput = {
250
343
  };
251
344
  ```
252
345
 
253
- ## Invalid Field Names
254
-
255
- Input field names that are not valid GraphQL identifiers are automatically skipped with a warning. Valid GraphQL names must:
346
+ ## Excluding Fields
256
347
 
257
- - Match the pattern `/^[_A-Za-z][_0-9A-Za-z]*$/`
258
- - Not start with `__` (reserved for GraphQL introspection)
348
+ Use `GqlObject` with the `ignoreFields` option to exclude specific fields from the generated Input Object. This is useful for internal fields that should not be accepted from clients:
259
349
 
260
350
  ```typescript
261
- export type CreateUserInput = {
262
- name: string; // ✅ Valid
263
- _metadata: string; // ✅ Valid (single underscore is OK)
264
- "123abc": string; // ⚠️ Skipped: starts with a number
265
- __private: string; // ⚠️ Skipped: starts with __
266
- "hyphen-field": string; // ⚠️ Skipped: contains hyphen
267
- };
351
+ import { type GqlObject } from "@gqlkit-ts/runtime";
352
+
353
+ /**
354
+ * Input for creating a user.
355
+ */
356
+ export type CreateUserInput = GqlObject<
357
+ {
358
+ name: string;
359
+ email: string;
360
+ internalData: string; // Internal field - excluded from schema
361
+ trackingId: string; // Internal field - excluded from schema
362
+ },
363
+ { ignoreFields: "internalData" | "trackingId" }
364
+ >;
268
365
  ```
269
366
 
270
- Generates (invalid fields are skipped):
367
+ Generates:
271
368
 
272
369
  ```graphql
370
+ """Input for creating a user."""
273
371
  input CreateUserInput {
274
372
  name: String!
275
- _metadata: String!
373
+ email: String!
276
374
  }
277
375
  ```
278
376
 
279
- When fields are skipped, gqlkit outputs a warning with the field name and location.
377
+ ## Invalid Field Names
378
+
379
+ Input field names follow the same validation rules as object type fields. See [Invalid Field Names](./objects.md#invalid-field-names) for details.
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Interface Types
3
+ description: Define GraphQL interface types using the GqlInterface utility type.
4
+ ---
5
+
1
6
  # Interface Types
2
7
 
3
8
  Define GraphQL interface types using the `GqlInterface` utility type.
@@ -163,7 +168,32 @@ See [Object Types](./objects.md) for more details on implementing interfaces.
163
168
 
164
169
  ## Runtime Type Resolution
165
170
 
166
- When GraphQL executes a query that returns an interface type, it needs to determine the concrete type at runtime. You can use either `defineResolveType` on the interface or `defineIsTypeOf` on each implementing type.
171
+ When GraphQL executes a query that returns an interface type, it needs to determine the concrete type at runtime.
172
+
173
+ ### Automatic Resolution
174
+
175
+ If all implementing types have `__typename` or `$typeName` fields with string literal values, gqlkit automatically generates the `resolveType` function:
176
+
177
+ ```typescript
178
+ export interface User {
179
+ __typename: "User";
180
+ id: IDString;
181
+ name: string;
182
+ }
183
+
184
+ export interface Post {
185
+ __typename: "Post";
186
+ id: IDString;
187
+ title: string;
188
+ }
189
+
190
+ // Both User and Post implement Node
191
+ // resolveType is automatically generated - no manual definition needed
192
+ ```
193
+
194
+ ### Manual Resolution
195
+
196
+ For types without `__typename` or `$typeName`, use `defineResolveType` on the interface or `defineIsTypeOf` on each implementing type:
167
197
 
168
198
  ```typescript
169
199
  import { defineResolveType } from "../gqlkit";
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Object Types
3
+ description: Plain TypeScript type exports become GraphQL Object types.
4
+ ---
5
+
1
6
  # Object Types
2
7
 
3
8
  Plain TypeScript type exports become GraphQL Object types.
@@ -157,6 +162,41 @@ export type Post = GqlObject<
157
162
 
158
163
  See [Interfaces](./interfaces.md) for more details on defining interface types.
159
164
 
165
+ ## Excluding Fields
166
+
167
+ Use `GqlObject` with the `ignoreFields` option to exclude specific fields from the generated GraphQL schema. This is useful for internal fields that should not be exposed in the public API:
168
+
169
+ ```typescript
170
+ import { type GqlObject, type IDString } from "@gqlkit-ts/runtime";
171
+
172
+ /**
173
+ * A user in the system.
174
+ */
175
+ export type User = GqlObject<
176
+ {
177
+ id: IDString;
178
+ name: string;
179
+ email: string | null;
180
+ internalId: string; // Internal field - excluded from schema
181
+ cacheKey: string; // Internal field - excluded from schema
182
+ },
183
+ { ignoreFields: "internalId" | "cacheKey" }
184
+ >;
185
+ ```
186
+
187
+ Generates:
188
+
189
+ ```graphql
190
+ """A user in the system."""
191
+ type User {
192
+ id: ID!
193
+ name: String!
194
+ email: String
195
+ }
196
+ ```
197
+
198
+ The excluded fields (`internalId` and `cacheKey`) are not included in the generated schema, and no resolvers are generated for them.
199
+
160
200
  ## Invalid Field Names
161
201
 
162
202
  Field names that are not valid GraphQL identifiers are automatically skipped with a warning. Valid GraphQL names must:
@@ -1,29 +1,13 @@
1
+ ---
2
+ title: Defining Queries and Mutations
3
+ description: Define Query and Mutation fields using the @gqlkit-ts/runtime API.
4
+ ---
5
+
1
6
  # Queries & Mutations
2
7
 
3
8
  Define Query and Mutation fields using the `@gqlkit-ts/runtime` API.
4
9
 
5
- ## Setup
6
-
7
- Create `src/gqlkit/context.ts` to define your context type:
8
-
9
- ```typescript
10
- export type Context = {
11
- userId: string;
12
- db: Database;
13
- };
14
- ```
15
-
16
- Create `src/gqlkit/gqlkit.ts` to export resolver factories:
17
-
18
- ```typescript
19
- import { createGqlkitApis } from "@gqlkit-ts/runtime";
20
- import type { Context } from "./context";
21
-
22
- export const { defineQuery, defineMutation, defineField } =
23
- createGqlkitApis<Context>();
24
- ```
25
-
26
- Then import the factories in your schema files.
10
+ > **Prerequisites**: This guide assumes you have completed the [basic setup](../getting-started.md#set-up-context-and-resolver-factories).
27
11
 
28
12
  ## Query Resolvers
29
13
 
@@ -179,6 +163,136 @@ Inline string literal unions and external TypeScript enums in arguments are also
179
163
 
180
164
  See [Field Resolvers](./fields.md) for more details on inline object arguments.
181
165
 
166
+ ## Inline Payload Types
167
+
168
+ Return types can use inline object literals. gqlkit automatically generates GraphQL Object types with the naming convention `{PascalCaseResolverName}Payload`:
169
+
170
+ ```typescript
171
+ export const updateUser = defineMutation<
172
+ { input: UpdateUserInput },
173
+ { user: User; updatedAt: string }
174
+ >((_root, args, ctx) => ({
175
+ user: ctx.db.updateUser(args.input),
176
+ updatedAt: new Date().toISOString(),
177
+ }));
178
+ ```
179
+
180
+ Generates:
181
+
182
+ ```graphql
183
+ type Mutation {
184
+ updateUser(input: UpdateUserInput!): UpdateUserPayload!
185
+ }
186
+
187
+ type UpdateUserPayload {
188
+ user: User!
189
+ updatedAt: String!
190
+ }
191
+ ```
192
+
193
+ ### Inline Union Payloads
194
+
195
+ Union types with inline object literals generate GraphQL Union types. Each union member must have a `__typename` property with a string literal type:
196
+
197
+ ```typescript
198
+ export const updateUser = defineMutation<
199
+ { input: UpdateUserInput },
200
+ | { __typename: "UpdateUserSuccess"; user: User }
201
+ | { __typename: "UpdateUserError"; message: string }
202
+ >((_root, args, ctx) => {
203
+ const result = ctx.db.updateUser(args.input);
204
+ if (result.ok) {
205
+ return { __typename: "UpdateUserSuccess", user: result.user };
206
+ }
207
+ return { __typename: "UpdateUserError", message: result.error };
208
+ });
209
+ ```
210
+
211
+ Generates:
212
+
213
+ ```graphql
214
+ type Mutation {
215
+ updateUser(input: UpdateUserInput!): UpdateUserPayload!
216
+ }
217
+
218
+ union UpdateUserPayload = UpdateUserError | UpdateUserSuccess
219
+
220
+ type UpdateUserSuccess {
221
+ user: User!
222
+ }
223
+
224
+ type UpdateUserError {
225
+ message: String!
226
+ }
227
+ ```
228
+
229
+ The `__resolveType` function is automatically generated based on the `__typename` property. See [Abstract Type Resolution](./abstract-resolvers.md) for more details.
230
+
231
+ ### Inline Enum Payloads
232
+
233
+ String literal unions in return types generate GraphQL Enum types:
234
+
235
+ ```typescript
236
+ export const getStatus = defineQuery<NoArgs, "active" | "inactive" | "pending">(
237
+ (_root, _args, ctx) => ctx.db.getStatus()
238
+ );
239
+ ```
240
+
241
+ Generates:
242
+
243
+ ```graphql
244
+ type Query {
245
+ getStatus: GetStatusPayload!
246
+ }
247
+
248
+ enum GetStatusPayload {
249
+ ACTIVE
250
+ INACTIVE
251
+ PENDING
252
+ }
253
+ ```
254
+
255
+ ### Nested Inline Types
256
+
257
+ Inline types can be nested within payload objects:
258
+
259
+ ```typescript
260
+ export const createOrder = defineMutation<
261
+ { input: CreateOrderInput },
262
+ {
263
+ order: {
264
+ id: string;
265
+ status: "pending" | "confirmed";
266
+ items: { productId: string; quantity: number }[];
267
+ };
268
+ }
269
+ >(/* ... */);
270
+ ```
271
+
272
+ Generates:
273
+
274
+ ```graphql
275
+ type CreateOrderPayload {
276
+ order: CreateOrderPayloadOrder!
277
+ }
278
+
279
+ type CreateOrderPayloadOrder {
280
+ id: String!
281
+ status: CreateOrderPayloadOrderStatus!
282
+ items: [CreateOrderPayloadOrderItems!]!
283
+ }
284
+
285
+ enum CreateOrderPayloadOrderStatus {
286
+ PENDING
287
+ CONFIRMED
288
+ }
289
+
290
+ type CreateOrderPayloadOrderItems {
291
+ productId: String!
292
+ quantity: Float!
293
+ }
294
+ ```
295
+
182
296
  ## Attaching Directives
183
297
 
184
298
  Add a third type parameter to attach directives to Query/Mutation fields:
@@ -1,3 +1,8 @@
1
+ ---
2
+ title: Defining Scalar Types
3
+ description: gqlkit provides built-in scalar types and supports custom scalar definitions.
4
+ ---
5
+
1
6
  # Scalar Types
2
7
 
3
8
  gqlkit provides built-in scalar types and supports custom scalar definitions.