@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.
- package/dist/auto-type-generator/auto-type-generator.d.ts +10 -4
- package/dist/auto-type-generator/auto-type-generator.d.ts.map +1 -1
- package/dist/auto-type-generator/auto-type-generator.js +640 -133
- package/dist/auto-type-generator/auto-type-generator.js.map +1 -1
- package/dist/auto-type-generator/index.d.ts +8 -1
- package/dist/auto-type-generator/index.d.ts.map +1 -1
- package/dist/auto-type-generator/index.js +3 -0
- package/dist/auto-type-generator/index.js.map +1 -1
- package/dist/auto-type-generator/inline-enum-collector.d.ts +13 -5
- package/dist/auto-type-generator/inline-enum-collector.d.ts.map +1 -1
- package/dist/auto-type-generator/inline-enum-collector.js +107 -71
- package/dist/auto-type-generator/inline-enum-collector.js.map +1 -1
- package/dist/auto-type-generator/inline-object-traverser.d.ts +20 -0
- package/dist/auto-type-generator/inline-object-traverser.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-object-traverser.js +22 -0
- package/dist/auto-type-generator/inline-object-traverser.js.map +1 -0
- package/dist/auto-type-generator/inline-union-collector.d.ts +29 -0
- package/dist/auto-type-generator/inline-union-collector.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-collector.js +216 -0
- package/dist/auto-type-generator/inline-union-collector.js.map +1 -0
- package/dist/auto-type-generator/inline-union-types.d.ts +29 -0
- package/dist/auto-type-generator/inline-union-types.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-types.js +2 -0
- package/dist/auto-type-generator/inline-union-types.js.map +1 -0
- package/dist/auto-type-generator/inline-union-validator.d.ts +76 -0
- package/dist/auto-type-generator/inline-union-validator.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-validator.js +329 -0
- package/dist/auto-type-generator/inline-union-validator.js.map +1 -0
- package/dist/auto-type-generator/naming-convention.d.ts +18 -1
- package/dist/auto-type-generator/naming-convention.d.ts.map +1 -1
- package/dist/auto-type-generator/naming-convention.js +16 -0
- package/dist/auto-type-generator/naming-convention.js.map +1 -1
- package/dist/auto-type-generator/resolve-type-generator.d.ts +20 -0
- package/dist/auto-type-generator/resolve-type-generator.d.ts.map +1 -0
- package/dist/auto-type-generator/resolve-type-generator.js +2 -0
- package/dist/auto-type-generator/resolve-type-generator.js.map +1 -0
- package/dist/auto-type-generator/resolver-field-iterator.d.ts +13 -0
- package/dist/auto-type-generator/resolver-field-iterator.d.ts.map +1 -0
- package/dist/auto-type-generator/resolver-field-iterator.js +22 -0
- package/dist/auto-type-generator/resolver-field-iterator.js.map +1 -0
- package/dist/auto-type-generator/typename-extractor.d.ts +26 -0
- package/dist/auto-type-generator/typename-extractor.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-extractor.js +142 -0
- package/dist/auto-type-generator/typename-extractor.js.map +1 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts +35 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.js +177 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.js.map +1 -0
- package/dist/auto-type-generator/typename-types.d.ts +43 -0
- package/dist/auto-type-generator/typename-types.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-types.js +37 -0
- package/dist/auto-type-generator/typename-types.js.map +1 -0
- package/dist/auto-type-generator/typename-validator.d.ts +37 -0
- package/dist/auto-type-generator/typename-validator.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-validator.js +206 -0
- package/dist/auto-type-generator/typename-validator.js.map +1 -0
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/docs.d.ts +51 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +154 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/gen-orchestrator/orchestrator.d.ts.map +1 -1
- package/dist/gen-orchestrator/orchestrator.js +13 -6
- package/dist/gen-orchestrator/orchestrator.js.map +1 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts +19 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts +5 -0
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.js +14 -61
- package/dist/resolver-extractor/extractor/define-api-extractor.js.map +1 -1
- package/dist/resolver-extractor/index.d.ts +0 -1
- package/dist/resolver-extractor/index.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts +1 -0
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js +9 -5
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.d.ts.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.js +20 -0
- package/dist/schema-generator/emitter/code-emitter.js.map +1 -1
- package/dist/schema-generator/generate-schema.d.ts +1 -0
- package/dist/schema-generator/generate-schema.d.ts.map +1 -1
- package/dist/schema-generator/generate-schema.js +72 -3
- package/dist/schema-generator/generate-schema.js.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.d.ts +14 -2
- package/dist/schema-generator/integrator/result-integrator.d.ts.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.js +54 -1
- package/dist/schema-generator/integrator/result-integrator.js.map +1 -1
- package/dist/schema-generator/resolver-collector/resolver-collector.d.ts +2 -0
- package/dist/schema-generator/resolver-collector/resolver-collector.d.ts.map +1 -1
- package/dist/schema-generator/resolver-collector/resolver-collector.js +22 -0
- package/dist/schema-generator/resolver-collector/resolver-collector.js.map +1 -1
- package/dist/shared/enum-prefix-detector.d.ts +63 -0
- package/dist/shared/enum-prefix-detector.d.ts.map +1 -0
- package/dist/shared/enum-prefix-detector.js +80 -0
- package/dist/shared/enum-prefix-detector.js.map +1 -0
- package/dist/shared/ignore-fields-detector.d.ts +26 -0
- package/dist/shared/ignore-fields-detector.d.ts.map +1 -0
- package/dist/shared/ignore-fields-detector.js +83 -0
- package/dist/shared/ignore-fields-detector.js.map +1 -0
- package/dist/shared/ignore-fields-validator.d.ts +29 -0
- package/dist/shared/ignore-fields-validator.d.ts.map +1 -0
- package/dist/shared/ignore-fields-validator.js +43 -0
- package/dist/shared/ignore-fields-validator.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/source-location.d.ts +5 -0
- package/dist/shared/source-location.d.ts.map +1 -1
- package/dist/shared/source-location.js +7 -0
- package/dist/shared/source-location.js.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.d.ts.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.js +21 -7
- package/dist/type-extractor/converter/graphql-converter.js.map +1 -1
- package/dist/type-extractor/extractor/field-type-resolver.js +42 -3
- package/dist/type-extractor/extractor/field-type-resolver.js.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.js +88 -23
- package/dist/type-extractor/extractor/type-extractor.js.map +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts +10 -2
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.js +8 -2
- package/dist/type-extractor/types/ts-type-reference-factory.js.map +1 -1
- package/dist/type-extractor/types/typescript.d.ts +4 -0
- package/dist/type-extractor/types/typescript.d.ts.map +1 -1
- package/docs/coding-agents.md +64 -0
- package/docs/configuration.md +6 -20
- package/docs/getting-started.md +15 -12
- package/docs/index.md +36 -22
- package/docs/integration/apollo.md +8 -40
- package/docs/integration/drizzle.md +6 -10
- package/docs/integration/prisma.md +196 -0
- package/docs/integration/yoga.md +8 -40
- package/docs/schema/abstract-resolvers.md +117 -0
- package/docs/schema/directives.md +5 -0
- package/docs/schema/documentation.md +5 -0
- package/docs/schema/enums.md +99 -0
- package/docs/schema/fields.md +64 -0
- package/docs/schema/index.md +21 -0
- package/docs/schema/inputs.md +115 -15
- package/docs/schema/interfaces.md +31 -1
- package/docs/schema/objects.md +40 -0
- package/docs/schema/queries-mutations.md +136 -22
- package/docs/schema/scalars.md +5 -0
- package/docs/schema/unions.md +208 -1
- package/docs/what-is-gqlkit.md +13 -8
- package/package.json +6 -4
- package/src/auto-type-generator/auto-type-generator.ts +946 -201
- package/src/auto-type-generator/index.ts +42 -0
- package/src/auto-type-generator/inline-enum-collector.ts +187 -139
- package/src/auto-type-generator/inline-object-traverser.ts +49 -0
- package/src/auto-type-generator/inline-union-collector.ts +402 -0
- package/src/auto-type-generator/inline-union-types.ts +33 -0
- package/src/auto-type-generator/inline-union-validator.ts +482 -0
- package/src/auto-type-generator/naming-convention.ts +38 -1
- package/src/auto-type-generator/resolve-type-generator.ts +21 -0
- package/src/auto-type-generator/resolver-field-iterator.ts +39 -0
- package/src/auto-type-generator/typename-extractor.ts +230 -0
- package/src/auto-type-generator/typename-resolve-type-generator.ts +281 -0
- package/src/auto-type-generator/typename-types.ts +66 -0
- package/src/auto-type-generator/typename-validator.ts +326 -0
- package/src/cli.ts +2 -0
- package/src/commands/docs.ts +211 -0
- package/src/gen-orchestrator/orchestrator.ts +20 -6
- package/src/resolver-extractor/extract-resolvers.ts +19 -0
- package/src/resolver-extractor/extractor/define-api-extractor.ts +23 -89
- package/src/resolver-extractor/index.ts +0 -6
- package/src/resolver-extractor/validator/abstract-resolver-validator.ts +16 -8
- package/src/schema-generator/emitter/code-emitter.ts +34 -0
- package/src/schema-generator/generate-schema.ts +99 -2
- package/src/schema-generator/integrator/result-integrator.ts +70 -1
- package/src/schema-generator/resolver-collector/resolver-collector.ts +34 -0
- package/src/shared/enum-prefix-detector.ts +99 -0
- package/src/shared/ignore-fields-detector.ts +109 -0
- package/src/shared/ignore-fields-validator.ts +66 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/source-location.ts +11 -0
- package/src/type-extractor/converter/graphql-converter.ts +31 -7
- package/src/type-extractor/extractor/field-type-resolver.ts +48 -3
- package/src/type-extractor/extractor/type-extractor.ts +103 -26
- package/src/type-extractor/types/diagnostics.ts +12 -2
- package/src/type-extractor/types/ts-type-reference-factory.ts +18 -5
- package/src/type-extractor/types/typescript.ts +4 -0
- package/dist/resolver-extractor/validator/only-validator.d.ts +0 -61
- package/dist/resolver-extractor/validator/only-validator.d.ts.map +0 -1
- package/dist/resolver-extractor/validator/only-validator.js +0 -76
- package/dist/resolver-extractor/validator/only-validator.js.map +0 -1
- package/src/resolver-extractor/validator/only-validator.ts +0 -158
package/docs/schema/enums.md
CHANGED
|
@@ -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:
|
package/docs/schema/fields.md
CHANGED
|
@@ -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:
|
package/docs/schema/index.md
CHANGED
|
@@ -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
|
|
package/docs/schema/inputs.md
CHANGED
|
@@ -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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
|
367
|
+
Generates:
|
|
271
368
|
|
|
272
369
|
```graphql
|
|
370
|
+
"""Input for creating a user."""
|
|
273
371
|
input CreateUserInput {
|
|
274
372
|
name: String!
|
|
275
|
-
|
|
373
|
+
email: String!
|
|
276
374
|
}
|
|
277
375
|
```
|
|
278
376
|
|
|
279
|
-
|
|
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.
|
|
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";
|
package/docs/schema/objects.md
CHANGED
|
@@ -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
|
-
|
|
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:
|
package/docs/schema/scalars.md
CHANGED