@gqlkit-ts/cli 0.1.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 +26 -4
- package/dist/auto-type-generator/auto-type-generator.d.ts.map +1 -1
- package/dist/auto-type-generator/auto-type-generator.js +846 -152
- package/dist/auto-type-generator/auto-type-generator.js.map +1 -1
- package/dist/auto-type-generator/index.d.ts +9 -2
- 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 +39 -0
- package/dist/auto-type-generator/inline-enum-collector.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-enum-collector.js +193 -0
- package/dist/auto-type-generator/inline-enum-collector.js.map +1 -0
- 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 +22 -1
- package/dist/auto-type-generator/naming-convention.d.ts.map +1 -1
- package/dist/auto-type-generator/naming-convention.js +24 -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 +119 -14
- package/dist/gen-orchestrator/orchestrator.js.map +1 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts +28 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts +16 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.js +86 -309
- 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 +10 -2
- package/dist/schema-generator/emitter/code-emitter.d.ts.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.js +39 -4
- 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 +90 -4
- package/dist/schema-generator/generate-schema.js.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.d.ts +34 -2
- package/dist/schema-generator/integrator/result-integrator.d.ts.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.js +96 -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/constants.d.ts +0 -16
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +0 -19
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/directive-detector.d.ts.map +1 -1
- package/dist/shared/directive-detector.js +8 -15
- package/dist/shared/directive-detector.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/file-scanner.d.ts.map +1 -1
- package/dist/shared/file-scanner.js +5 -3
- package/dist/shared/file-scanner.js.map +1 -1
- 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 +3 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +1 -3
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/interface-detector.d.ts +3 -2
- package/dist/shared/interface-detector.d.ts.map +1 -1
- package/dist/shared/interface-detector.js +54 -11
- package/dist/shared/interface-detector.js.map +1 -1
- package/dist/shared/path-utils.d.ts +2 -0
- package/dist/shared/path-utils.d.ts.map +1 -0
- package/dist/shared/path-utils.js +4 -0
- package/dist/shared/path-utils.js.map +1 -0
- 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/shared/type-converter.d.ts.map +1 -1
- package/dist/shared/type-converter.js +11 -0
- package/dist/shared/type-converter.js.map +1 -1
- package/dist/shared/typescript-utils.d.ts +34 -7
- package/dist/shared/typescript-utils.d.ts.map +1 -1
- package/dist/shared/typescript-utils.js +72 -24
- package/dist/shared/typescript-utils.js.map +1 -1
- package/dist/type-extractor/collector/scalar-collector.d.ts.map +1 -1
- package/dist/type-extractor/collector/scalar-collector.js +4 -14
- package/dist/type-extractor/collector/scalar-collector.js.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.d.ts.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.js +57 -4
- package/dist/type-extractor/converter/graphql-converter.js.map +1 -1
- package/dist/type-extractor/extractor/field-type-resolver.d.ts +28 -0
- package/dist/type-extractor/extractor/field-type-resolver.d.ts.map +1 -0
- package/dist/type-extractor/extractor/field-type-resolver.js +433 -0
- package/dist/type-extractor/extractor/field-type-resolver.js.map +1 -0
- package/dist/type-extractor/extractor/type-extractor.d.ts +12 -3
- package/dist/type-extractor/extractor/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.js +260 -229
- package/dist/type-extractor/extractor/type-extractor.js.map +1 -1
- package/dist/type-extractor/extractor/type-name-collector.d.ts +24 -0
- package/dist/type-extractor/extractor/type-name-collector.d.ts.map +1 -0
- package/dist/type-extractor/extractor/type-name-collector.js +102 -0
- package/dist/type-extractor/extractor/type-name-collector.js.map +1 -0
- package/dist/type-extractor/mapper/scalar-base-type-mapper.d.ts +89 -0
- package/dist/type-extractor/mapper/scalar-base-type-mapper.d.ts.map +1 -0
- package/dist/type-extractor/mapper/scalar-base-type-mapper.js +158 -0
- package/dist/type-extractor/mapper/scalar-base-type-mapper.js.map +1 -0
- 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/graphql.d.ts +2 -0
- package/dist/type-extractor/types/graphql.d.ts.map +1 -1
- package/dist/type-extractor/types/index.d.ts +2 -1
- package/dist/type-extractor/types/index.d.ts.map +1 -1
- package/dist/type-extractor/types/index.js +1 -1
- package/dist/type-extractor/types/index.js.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts +47 -0
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts.map +1 -0
- package/dist/type-extractor/types/ts-type-reference-factory.js +75 -0
- package/dist/type-extractor/types/ts-type-reference-factory.js.map +1 -0
- package/dist/type-extractor/types/typescript.d.ts +25 -1
- package/dist/type-extractor/types/typescript.d.ts.map +1 -1
- package/dist/type-extractor/validator/type-validator.js +1 -1
- package/dist/type-extractor/validator/type-validator.js.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 -21
- package/docs/integration/apollo.md +8 -40
- package/docs/integration/drizzle.md +187 -0
- 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 +307 -0
- package/docs/schema/fields.md +66 -0
- package/docs/schema/index.md +21 -0
- package/docs/schema/inputs.md +117 -15
- package/docs/schema/interfaces.md +31 -1
- package/docs/schema/objects.md +42 -0
- package/docs/schema/queries-mutations.md +138 -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 +14 -5
- package/src/auto-type-generator/auto-type-generator.ts +1670 -0
- package/src/auto-type-generator/index.ts +63 -0
- package/src/auto-type-generator/inline-enum-collector.ts +338 -0
- 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/name-collision-validator.ts +119 -0
- package/src/auto-type-generator/naming-convention.ts +163 -0
- 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 +13 -0
- package/src/commands/docs.ts +211 -0
- package/src/commands/gen.ts +141 -0
- package/src/commands/main.ts +5 -0
- package/src/config/define-config.ts +28 -0
- package/src/config/index.ts +7 -0
- package/src/config/types.ts +144 -0
- package/src/config-loader/index.ts +14 -0
- package/src/config-loader/loader.ts +143 -0
- package/src/config-loader/validator.ts +672 -0
- package/src/gen-orchestrator/hook-executor/hook-executor.ts +117 -0
- package/src/gen-orchestrator/orchestrator.ts +798 -0
- package/src/gen-orchestrator/reporter/diagnostic-reporter.ts +44 -0
- package/src/gen-orchestrator/reporter/progress-reporter.ts +61 -0
- package/src/gen-orchestrator/writer/file-writer.ts +38 -0
- package/src/index.ts +2 -0
- package/src/resolver-extractor/extract-resolvers.ts +82 -0
- package/src/resolver-extractor/extractor/define-api-extractor.ts +740 -0
- package/src/resolver-extractor/index.ts +13 -0
- package/src/resolver-extractor/validator/abstract-resolver-validator.ts +259 -0
- package/src/schema-generator/builder/ast-builder.ts +706 -0
- package/src/schema-generator/emitter/code-emitter.ts +385 -0
- package/src/schema-generator/emitter/sdl-emitter.ts +13 -0
- package/src/schema-generator/generate-schema.ts +267 -0
- package/src/schema-generator/index.ts +19 -0
- package/src/schema-generator/integrator/result-integrator.ts +759 -0
- package/src/schema-generator/pruner/schema-pruner.ts +112 -0
- package/src/schema-generator/resolver-collector/resolver-collector.ts +157 -0
- package/src/shared/constants.ts +122 -0
- package/src/shared/default-value-detector.ts +172 -0
- package/src/shared/diagnostics.ts +35 -0
- package/src/shared/directive-definition-extractor.ts +564 -0
- package/src/shared/directive-detector.ts +556 -0
- package/src/shared/enum-prefix-detector.ts +99 -0
- package/src/shared/file-scanner.ts +170 -0
- package/src/shared/ignore-fields-detector.ts +109 -0
- package/src/shared/ignore-fields-validator.ts +66 -0
- package/src/shared/index.ts +34 -0
- package/src/shared/inline-object-extractor.ts +102 -0
- package/src/shared/inline-object-utils.ts +23 -0
- package/src/shared/interface-detector.ts +176 -0
- package/src/shared/interface-validator.ts +211 -0
- package/src/shared/metadata-detector.ts +443 -0
- package/src/shared/path-utils.ts +3 -0
- package/src/shared/program-factory.ts +51 -0
- package/src/shared/source-location.ts +38 -0
- package/src/shared/tsconfig-loader.ts +126 -0
- package/src/shared/tsdoc-parser.ts +155 -0
- package/src/shared/type-converter.ts +99 -0
- package/src/shared/typescript-utils.ts +246 -0
- package/src/type-extractor/collector/result-collector.ts +57 -0
- package/src/type-extractor/collector/scalar-collector.ts +254 -0
- package/src/type-extractor/converter/field-eligibility.ts +112 -0
- package/src/type-extractor/converter/graphql-converter.ts +483 -0
- package/src/type-extractor/extract-types.ts +1 -0
- package/src/type-extractor/extractor/field-type-resolver.ts +614 -0
- package/src/type-extractor/extractor/type-extractor.ts +1644 -0
- package/src/type-extractor/extractor/type-name-collector.ts +130 -0
- package/src/type-extractor/index.ts +20 -0
- package/src/type-extractor/mapper/scalar-base-type-mapper.ts +265 -0
- package/src/type-extractor/types/diagnostics.ts +109 -0
- package/src/type-extractor/types/graphql.ts +55 -0
- package/src/type-extractor/types/index.ts +37 -0
- package/src/type-extractor/types/ts-type-reference-factory.ts +150 -0
- package/src/type-extractor/types/typescript.ts +137 -0
- package/src/type-extractor/validator/type-validator.ts +77 -0
- package/dist/auto-type-generator/auto-type-generator.test.d.ts +0 -2
- package/dist/auto-type-generator/auto-type-generator.test.d.ts.map +0 -1
- package/dist/auto-type-generator/auto-type-generator.test.js +0 -613
- package/dist/auto-type-generator/auto-type-generator.test.js.map +0 -1
- package/dist/auto-type-generator/name-collision-validator.test.d.ts +0 -2
- package/dist/auto-type-generator/name-collision-validator.test.d.ts.map +0 -1
- package/dist/auto-type-generator/name-collision-validator.test.js +0 -358
- package/dist/auto-type-generator/name-collision-validator.test.js.map +0 -1
- package/dist/auto-type-generator/naming-convention.test.d.ts +0 -2
- package/dist/auto-type-generator/naming-convention.test.d.ts.map +0 -1
- package/dist/auto-type-generator/naming-convention.test.js +0 -132
- package/dist/auto-type-generator/naming-convention.test.js.map +0 -1
- package/dist/commands/gen.test.d.ts +0 -2
- package/dist/commands/gen.test.d.ts.map +0 -1
- package/dist/commands/gen.test.js +0 -226
- package/dist/commands/gen.test.js.map +0 -1
- package/dist/config-loader/loader.test.d.ts +0 -2
- package/dist/config-loader/loader.test.d.ts.map +0 -1
- package/dist/config-loader/loader.test.js +0 -123
- package/dist/config-loader/loader.test.js.map +0 -1
- package/dist/config-loader/validator.test.d.ts +0 -2
- package/dist/config-loader/validator.test.d.ts.map +0 -1
- package/dist/config-loader/validator.test.js +0 -846
- package/dist/config-loader/validator.test.js.map +0 -1
- package/dist/gen-orchestrator/golden.test.d.ts +0 -2
- package/dist/gen-orchestrator/golden.test.d.ts.map +0 -1
- package/dist/gen-orchestrator/golden.test.js +0 -102
- package/dist/gen-orchestrator/golden.test.js.map +0 -1
- package/dist/gen-orchestrator/hook-executor/hook-executor.test.d.ts +0 -2
- package/dist/gen-orchestrator/hook-executor/hook-executor.test.d.ts.map +0 -1
- package/dist/gen-orchestrator/hook-executor/hook-executor.test.js +0 -167
- package/dist/gen-orchestrator/hook-executor/hook-executor.test.js.map +0 -1
- package/dist/gen-orchestrator/reporter/progress-reporter.test.d.ts +0 -2
- package/dist/gen-orchestrator/reporter/progress-reporter.test.d.ts.map +0 -1
- package/dist/gen-orchestrator/reporter/progress-reporter.test.js +0 -74
- package/dist/gen-orchestrator/reporter/progress-reporter.test.js.map +0 -1
- 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/dist/resolver-extractor/validator/only-validator.test.d.ts +0 -8
- package/dist/resolver-extractor/validator/only-validator.test.d.ts.map +0 -1
- package/dist/resolver-extractor/validator/only-validator.test.js +0 -352
- package/dist/resolver-extractor/validator/only-validator.test.js.map +0 -1
- package/dist/schema-generator/builder/ast-builder.test.d.ts +0 -2
- package/dist/schema-generator/builder/ast-builder.test.d.ts.map +0 -1
- package/dist/schema-generator/builder/ast-builder.test.js +0 -469
- package/dist/schema-generator/builder/ast-builder.test.js.map +0 -1
- package/dist/shared/file-scanner.test.d.ts +0 -2
- package/dist/shared/file-scanner.test.d.ts.map +0 -1
- package/dist/shared/file-scanner.test.js +0 -138
- package/dist/shared/file-scanner.test.js.map +0 -1
- package/dist/shared/interface-validator.test.d.ts +0 -2
- package/dist/shared/interface-validator.test.d.ts.map +0 -1
- package/dist/shared/interface-validator.test.js +0 -145
- package/dist/shared/interface-validator.test.js.map +0 -1
- package/dist/type-extractor/types/typescript.test.d.ts +0 -2
- package/dist/type-extractor/types/typescript.test.d.ts.map +0 -1
- package/dist/type-extractor/types/typescript.test.js +0 -287
- package/dist/type-extractor/types/typescript.test.js.map +0 -1
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.
|
|
@@ -111,6 +116,308 @@ input UpdateUserInput {
|
|
|
111
116
|
}
|
|
112
117
|
```
|
|
113
118
|
|
|
119
|
+
## Inline Enums
|
|
120
|
+
|
|
121
|
+
When you define a string literal union or reference a TypeScript enum **inline** (without exporting it from the schema directory), gqlkit automatically generates a GraphQL enum type. This follows the same pattern as [inline objects](./objects.md#inline-objects).
|
|
122
|
+
|
|
123
|
+
### Inline String Literal Unions
|
|
124
|
+
|
|
125
|
+
String literal unions used directly in field or argument types generate enum types automatically:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
export type User = {
|
|
129
|
+
id: string;
|
|
130
|
+
name: string;
|
|
131
|
+
/** Current account status */
|
|
132
|
+
status: "active" | "inactive" | "pendingReview";
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Generates:
|
|
137
|
+
|
|
138
|
+
```graphql
|
|
139
|
+
type User {
|
|
140
|
+
id: String!
|
|
141
|
+
name: String!
|
|
142
|
+
"""Current account status"""
|
|
143
|
+
status: UserStatus!
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
enum UserStatus {
|
|
147
|
+
ACTIVE
|
|
148
|
+
INACTIVE
|
|
149
|
+
PENDING_REVIEW
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The generated enum type name follows the convention `{ParentTypeName}{PascalCaseFieldName}`.
|
|
154
|
+
|
|
155
|
+
### External TypeScript Enums
|
|
156
|
+
|
|
157
|
+
TypeScript enums defined outside the schema directory are also automatically converted:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
// src/types/order.ts (outside schema directory)
|
|
161
|
+
/**
|
|
162
|
+
* Order status in the system
|
|
163
|
+
*/
|
|
164
|
+
export enum OrderStatus {
|
|
165
|
+
/** Order is pending payment */
|
|
166
|
+
Pending = "pending",
|
|
167
|
+
/** Order is being processed */
|
|
168
|
+
Processing = "processing",
|
|
169
|
+
/** Order has been shipped */
|
|
170
|
+
Shipped = "shipped",
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/gqlkit/schema/order.ts
|
|
174
|
+
import { OrderStatus } from "../../types/order.js";
|
|
175
|
+
|
|
176
|
+
export type Order = {
|
|
177
|
+
id: string;
|
|
178
|
+
status: OrderStatus;
|
|
179
|
+
};
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Generates:
|
|
183
|
+
|
|
184
|
+
```graphql
|
|
185
|
+
type Order {
|
|
186
|
+
id: String!
|
|
187
|
+
status: OrderStatus!
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
"""Order status in the system"""
|
|
191
|
+
enum OrderStatus {
|
|
192
|
+
"""Order is pending payment"""
|
|
193
|
+
PENDING
|
|
194
|
+
"""Order is being processed"""
|
|
195
|
+
PROCESSING
|
|
196
|
+
"""Order has been shipped"""
|
|
197
|
+
SHIPPED
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
TSDoc comments on the enum and its values are preserved as GraphQL descriptions. The `@deprecated` tag is also supported.
|
|
202
|
+
|
|
203
|
+
When the same external TypeScript enum is referenced in multiple places, gqlkit generates a single GraphQL enum type and reuses it across all references.
|
|
204
|
+
|
|
205
|
+
### Inline Enum Naming Convention
|
|
206
|
+
|
|
207
|
+
The naming convention for auto-generated enum types matches [inline objects](./objects.md#inline-objects):
|
|
208
|
+
|
|
209
|
+
| Context | Naming Pattern | Example |
|
|
210
|
+
|---------|----------------|---------|
|
|
211
|
+
| Object field | `{ParentTypeName}{PascalCaseFieldName}` | `User.status` → `UserStatus` |
|
|
212
|
+
| Input field | `{ParentTypeNameWithoutInputSuffix}{PascalCaseFieldName}Input` | `CreateUserInput.role` → `CreateUserRoleInput` |
|
|
213
|
+
| Query/Mutation argument | `{PascalCaseFieldName}{PascalCaseArgName}Input` | `searchUsers(status: ...)` → `SearchUsersStatusInput` |
|
|
214
|
+
| Field resolver argument | `{ParentTypeName}{PascalCaseFieldName}{PascalCaseArgName}Input` | `User.posts(filter: ...)` → `UserPostsFilterInput` |
|
|
215
|
+
|
|
216
|
+
### Nullable Inline Enums
|
|
217
|
+
|
|
218
|
+
Nullable inline enums are supported:
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
export type User = {
|
|
222
|
+
id: string;
|
|
223
|
+
status: "active" | "inactive" | null;
|
|
224
|
+
};
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Generates:
|
|
228
|
+
|
|
229
|
+
```graphql
|
|
230
|
+
type User {
|
|
231
|
+
id: String!
|
|
232
|
+
status: UserStatus
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
enum UserStatus {
|
|
236
|
+
ACTIVE
|
|
237
|
+
INACTIVE
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Arrays of Inline Enums
|
|
242
|
+
|
|
243
|
+
Inline enums in array types are also supported:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
export type User = {
|
|
247
|
+
id: string;
|
|
248
|
+
roles: ("admin" | "editor" | "viewer")[];
|
|
249
|
+
};
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Generates:
|
|
253
|
+
|
|
254
|
+
```graphql
|
|
255
|
+
type User {
|
|
256
|
+
id: String!
|
|
257
|
+
roles: [UserRoles!]!
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
enum UserRoles {
|
|
261
|
+
ADMIN
|
|
262
|
+
EDITOR
|
|
263
|
+
VIEWER
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### When Enums Are NOT Auto-Generated
|
|
268
|
+
|
|
269
|
+
If you export a type from the schema directory, it is treated as an explicit type declaration and not auto-generated:
|
|
270
|
+
|
|
271
|
+
```typescript
|
|
272
|
+
// Exported from schema - used as-is, not auto-generated
|
|
273
|
+
export type UserStatus = "active" | "inactive" | "pending";
|
|
274
|
+
|
|
275
|
+
export type User = {
|
|
276
|
+
id: string;
|
|
277
|
+
status: UserStatus; // References the exported type
|
|
278
|
+
};
|
|
279
|
+
```
|
|
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
|
+
|
|
329
|
+
## Automatic Case Conversion
|
|
330
|
+
|
|
331
|
+
gqlkit automatically converts enum values to `SCREAMING_SNAKE_CASE` format, which is the GraphQL convention:
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
export type UserStatus = "active" | "inProgress" | "pending_review" | "on-hold";
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Generates:
|
|
338
|
+
|
|
339
|
+
```graphql
|
|
340
|
+
enum UserStatus {
|
|
341
|
+
ACTIVE
|
|
342
|
+
IN_PROGRESS
|
|
343
|
+
PENDING_REVIEW
|
|
344
|
+
ON_HOLD
|
|
345
|
+
}
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
When conversion changes the original value, gqlkit generates resolver mappings to translate between GraphQL and TypeScript values:
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// Generated resolvers.ts
|
|
352
|
+
export function createResolvers() {
|
|
353
|
+
return {
|
|
354
|
+
UserStatus: {
|
|
355
|
+
ACTIVE: "active",
|
|
356
|
+
IN_PROGRESS: "inProgress",
|
|
357
|
+
PENDING_REVIEW: "pending_review",
|
|
358
|
+
ON_HOLD: "on-hold",
|
|
359
|
+
},
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
If values are already in `SCREAMING_SNAKE_CASE`, no resolver mapping is generated.
|
|
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
|
+
|
|
412
|
+
### Duplicate Value Detection
|
|
413
|
+
|
|
414
|
+
If multiple TypeScript values convert to the same GraphQL enum value, gqlkit reports a `DUPLICATE_ENUM_VALUE_AFTER_CONVERSION` error:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// Error: 'activeUser' and 'active_user' both convert to ACTIVE_USER
|
|
418
|
+
export type Status = "activeUser" | "active_user" | "pending";
|
|
419
|
+
```
|
|
420
|
+
|
|
114
421
|
## Invalid Enum Values
|
|
115
422
|
|
|
116
423
|
Enum values that are not valid GraphQL identifiers are automatically skipped with a warning. gqlkit converts enum values to `SCREAMING_SNAKE_CASE`, and the converted name must:
|
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.
|
|
@@ -120,6 +125,67 @@ input UserPostsFilterInput {
|
|
|
120
125
|
}
|
|
121
126
|
```
|
|
122
127
|
|
|
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.
|
|
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
|
+
|
|
123
189
|
## Default Values in Arguments
|
|
124
190
|
|
|
125
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.
|
|
@@ -58,6 +63,8 @@ input CreateUserProfileInput {
|
|
|
58
63
|
|
|
59
64
|
Nested inline objects generate types with concatenated names (e.g., `UserProfileInput.address` → `UserProfileAddressInput`).
|
|
60
65
|
|
|
66
|
+
Similarly, inline string literal unions and external TypeScript enums are automatically converted to GraphQL enum types. See [Inline Enums](./enums.md#inline-enums) for details.
|
|
67
|
+
|
|
61
68
|
## @oneOf Input Objects
|
|
62
69
|
|
|
63
70
|
Union types with `Input` suffix using inline object literals generate `@oneOf` input objects. Each union member must be an inline object literal with exactly one property. Property values can be scalar types, enum types, or references to Input Object types:
|
|
@@ -89,6 +96,94 @@ input ProductInput @oneOf {
|
|
|
89
96
|
|
|
90
97
|
Each property becomes a nullable field in the generated input type. The `@oneOf` directive ensures exactly one field is provided at runtime.
|
|
91
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
|
+
|
|
92
187
|
## Default Values
|
|
93
188
|
|
|
94
189
|
Specify default values for Input Object fields using `GqlField` with the `defaultValue` option.
|
|
@@ -248,30 +343,37 @@ export type BadInput = {
|
|
|
248
343
|
};
|
|
249
344
|
```
|
|
250
345
|
|
|
251
|
-
##
|
|
252
|
-
|
|
253
|
-
Input field names that are not valid GraphQL identifiers are automatically skipped with a warning. Valid GraphQL names must:
|
|
346
|
+
## Excluding Fields
|
|
254
347
|
|
|
255
|
-
|
|
256
|
-
- 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:
|
|
257
349
|
|
|
258
350
|
```typescript
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
+
>;
|
|
266
365
|
```
|
|
267
366
|
|
|
268
|
-
Generates
|
|
367
|
+
Generates:
|
|
269
368
|
|
|
270
369
|
```graphql
|
|
370
|
+
"""Input for creating a user."""
|
|
271
371
|
input CreateUserInput {
|
|
272
372
|
name: String!
|
|
273
|
-
|
|
373
|
+
email: String!
|
|
274
374
|
}
|
|
275
375
|
```
|
|
276
376
|
|
|
277
|
-
|
|
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.
|
|
@@ -102,6 +107,8 @@ type UserProfile {
|
|
|
102
107
|
|
|
103
108
|
Nested inline objects generate types with concatenated names (e.g., `User.profile.address` → `UserProfileAddress`).
|
|
104
109
|
|
|
110
|
+
Similarly, inline string literal unions and external TypeScript enums are automatically converted to GraphQL enum types. See [Inline Enums](./enums.md#inline-enums) for details.
|
|
111
|
+
|
|
105
112
|
## Implementing Interfaces
|
|
106
113
|
|
|
107
114
|
Use `GqlObject` with the `implements` option to declare that a type implements interfaces:
|
|
@@ -155,6 +162,41 @@ export type Post = GqlObject<
|
|
|
155
162
|
|
|
156
163
|
See [Interfaces](./interfaces.md) for more details on defining interface types.
|
|
157
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
|
+
|
|
158
200
|
## Invalid Field Names
|
|
159
201
|
|
|
160
202
|
Field names that are not valid GraphQL identifiers are automatically skipped with a warning. Valid GraphQL names must:
|