@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
|
@@ -1,8 +1,45 @@
|
|
|
1
|
+
import { detectEnumPrefix, stripEnumPrefix, } from "../shared/enum-prefix-detector.js";
|
|
2
|
+
import { getSourceLocationOrDefault } from "../shared/source-location.js";
|
|
1
3
|
import { convertTsTypeToGraphQLType } from "../shared/type-converter.js";
|
|
2
4
|
import { isEligibleAsInputObjectField, isEligibleAsObjectField, } from "../type-extractor/converter/field-eligibility.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import { createReferenceType, } from "../type-extractor/types/index.js";
|
|
6
|
+
import { collectInlineEnumsFromPayloads, collectInlineEnumsFromResolvers, collectInlineEnumsFromTypes, } from "./inline-enum-collector.js";
|
|
7
|
+
import { collectInlineUnionsFromPayloads, collectInlineUnionsFromResolvers, collectInlineUnionsFromTypes, } from "./inline-union-collector.js";
|
|
8
|
+
import { validateOneOfMembers, validateUnionMembers, validateUnionMemberTypenames, } from "./inline-union-validator.js";
|
|
9
|
+
import { buildFieldContext, generateAutoTypeName, isInputTypeName, } from "./naming-convention.js";
|
|
10
|
+
import { forEachResolverField } from "./resolver-field-iterator.js";
|
|
11
|
+
import { createFieldNameSet, findTypenameProperty, } from "./typename-types.js";
|
|
12
|
+
function extractNestedInlineObjectsRecursively(params) {
|
|
13
|
+
const { properties, currentPath, sourceLocation, buildContext, preserveDocumentation, results, } = params;
|
|
14
|
+
for (const prop of properties) {
|
|
15
|
+
if (prop.tsType.kind === "inlineObject" &&
|
|
16
|
+
prop.tsType.inlineObjectProperties) {
|
|
17
|
+
const nestedPath = [...currentPath, prop.name];
|
|
18
|
+
const nestedContext = buildContext(nestedPath);
|
|
19
|
+
// Use property's source location if available for more accurate diagnostics
|
|
20
|
+
const nestedSourceLocation = prop.sourceLocation ?? sourceLocation;
|
|
21
|
+
results.push({
|
|
22
|
+
properties: prop.tsType.inlineObjectProperties,
|
|
23
|
+
context: nestedContext,
|
|
24
|
+
sourceLocation: nestedSourceLocation,
|
|
25
|
+
nullable: prop.tsType.nullable,
|
|
26
|
+
description: preserveDocumentation
|
|
27
|
+
? prop.tsType.inlineObjectDescription
|
|
28
|
+
: null,
|
|
29
|
+
deprecated: preserveDocumentation
|
|
30
|
+
? prop.tsType.inlineObjectDeprecated
|
|
31
|
+
: null,
|
|
32
|
+
});
|
|
33
|
+
extractNestedInlineObjectsRecursively({
|
|
34
|
+
properties: prop.tsType.inlineObjectProperties,
|
|
35
|
+
currentPath: nestedPath,
|
|
36
|
+
sourceLocation: nestedSourceLocation,
|
|
37
|
+
buildContext,
|
|
38
|
+
preserveDocumentation,
|
|
39
|
+
results,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
6
43
|
}
|
|
7
44
|
function getContextKey(context) {
|
|
8
45
|
switch (context.kind) {
|
|
@@ -12,8 +49,32 @@ function getContextKey(context) {
|
|
|
12
49
|
return `inputField:${context.parentTypeName}:${context.fieldPath.join(".")}`;
|
|
13
50
|
case "resolverArg":
|
|
14
51
|
return `resolverArg:${context.resolverType}:${context.parentTypeName ?? ""}:${context.fieldName}:${context.argName}:${context.fieldPath.join(".")}`;
|
|
52
|
+
case "resolverPayload":
|
|
53
|
+
return `resolverPayload:${context.resolverType}:${context.parentTypeName ?? ""}:${context.fieldName}:${context.fieldPath.join(".")}`;
|
|
15
54
|
}
|
|
16
55
|
}
|
|
56
|
+
function mapContextKindToGeneratedFromContext(kind) {
|
|
57
|
+
switch (kind) {
|
|
58
|
+
case "objectField":
|
|
59
|
+
return "typeField";
|
|
60
|
+
case "inputField":
|
|
61
|
+
return "inputField";
|
|
62
|
+
case "resolverArg":
|
|
63
|
+
return "resolverArg";
|
|
64
|
+
case "resolverPayload":
|
|
65
|
+
return "resolverPayload";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function buildGeneratedFromInfo(context) {
|
|
69
|
+
const fieldPath = context.kind === "resolverArg" && context.fieldPath.length === 0
|
|
70
|
+
? [context.argName]
|
|
71
|
+
: context.fieldPath;
|
|
72
|
+
return {
|
|
73
|
+
parentTypeName: context.parentTypeName,
|
|
74
|
+
fieldPath,
|
|
75
|
+
context: mapContextKindToGeneratedFromContext(context.kind),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
17
78
|
function collectInlineObjectsFromType(typeInfo) {
|
|
18
79
|
const results = [];
|
|
19
80
|
const isInput = isInputTypeName(typeInfo.metadata.name);
|
|
@@ -39,78 +100,31 @@ function collectInlineObjectsFromField(field, parentTypeName, parentPath, isInpu
|
|
|
39
100
|
parentTypeName,
|
|
40
101
|
fieldPath,
|
|
41
102
|
};
|
|
103
|
+
const sourceLocation = getSourceLocationOrDefault(field.sourceLocation, sourceFile);
|
|
42
104
|
results.push({
|
|
43
105
|
properties: tsType.inlineObjectProperties,
|
|
44
106
|
context,
|
|
45
|
-
sourceLocation
|
|
46
|
-
file: sourceFile,
|
|
47
|
-
line: 1,
|
|
48
|
-
column: 1,
|
|
49
|
-
},
|
|
107
|
+
sourceLocation,
|
|
50
108
|
nullable: tsType.nullable,
|
|
109
|
+
description: tsType.inlineObjectDescription,
|
|
110
|
+
deprecated: tsType.inlineObjectDeprecated,
|
|
51
111
|
});
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
: {
|
|
63
|
-
kind: "objectField",
|
|
64
|
-
parentTypeName,
|
|
65
|
-
fieldPath: nestedPath,
|
|
66
|
-
};
|
|
67
|
-
extractNestedInlineObjects(prop.tsType.inlineObjectProperties, nestedContext, nestedPath, parentTypeName, isInput, sourceFile, prop.sourceLocation, results);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
function extractNestedInlineObjects(properties, context, currentPath, parentTypeName, isInput, sourceFile, parentSourceLocation, results) {
|
|
72
|
-
results.push({
|
|
73
|
-
properties,
|
|
74
|
-
context,
|
|
75
|
-
sourceLocation: parentSourceLocation ?? {
|
|
76
|
-
file: sourceFile,
|
|
77
|
-
line: 1,
|
|
78
|
-
column: 1,
|
|
79
|
-
},
|
|
80
|
-
nullable: false,
|
|
112
|
+
extractNestedInlineObjectsRecursively({
|
|
113
|
+
properties: tsType.inlineObjectProperties,
|
|
114
|
+
currentPath: fieldPath,
|
|
115
|
+
sourceLocation,
|
|
116
|
+
buildContext: (nestedPath) => isInput
|
|
117
|
+
? { kind: "inputField", parentTypeName, fieldPath: nestedPath }
|
|
118
|
+
: { kind: "objectField", parentTypeName, fieldPath: nestedPath },
|
|
119
|
+
preserveDocumentation: true,
|
|
120
|
+
results,
|
|
81
121
|
});
|
|
82
|
-
for (const prop of properties) {
|
|
83
|
-
if (prop.tsType.kind === "inlineObject" &&
|
|
84
|
-
prop.tsType.inlineObjectProperties) {
|
|
85
|
-
const nestedPath = [...currentPath, prop.name];
|
|
86
|
-
const nestedContext = isInput
|
|
87
|
-
? {
|
|
88
|
-
kind: "inputField",
|
|
89
|
-
parentTypeName,
|
|
90
|
-
fieldPath: nestedPath,
|
|
91
|
-
}
|
|
92
|
-
: {
|
|
93
|
-
kind: "objectField",
|
|
94
|
-
parentTypeName,
|
|
95
|
-
fieldPath: nestedPath,
|
|
96
|
-
};
|
|
97
|
-
extractNestedInlineObjects(prop.tsType.inlineObjectProperties, nestedContext, nestedPath, parentTypeName, isInput, sourceFile, prop.sourceLocation, results);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
122
|
}
|
|
101
123
|
function collectInlineObjectsFromResolvers(resolversResult) {
|
|
102
124
|
const results = [];
|
|
103
|
-
|
|
104
|
-
collectInlineObjectsFromResolverArgs(field,
|
|
105
|
-
}
|
|
106
|
-
for (const field of resolversResult.mutationFields.fields) {
|
|
107
|
-
collectInlineObjectsFromResolverArgs(field, "mutation", null, results);
|
|
108
|
-
}
|
|
109
|
-
for (const ext of resolversResult.typeExtensions) {
|
|
110
|
-
for (const field of ext.fields) {
|
|
111
|
-
collectInlineObjectsFromResolverArgs(field, "field", ext.targetTypeName, results);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
125
|
+
forEachResolverField(resolversResult, ({ field, resolverType, parentTypeName }) => {
|
|
126
|
+
collectInlineObjectsFromResolverArgs(field, resolverType, parentTypeName, results);
|
|
127
|
+
});
|
|
114
128
|
return results;
|
|
115
129
|
}
|
|
116
130
|
function collectInlineObjectsFromResolverArgs(field, resolverType, parentTypeName, results) {
|
|
@@ -132,34 +146,68 @@ function collectInlineObjectsFromResolverArgs(field, resolverType, parentTypeNam
|
|
|
132
146
|
context,
|
|
133
147
|
sourceLocation: field.sourceLocation,
|
|
134
148
|
nullable: arg.type.nullable,
|
|
149
|
+
description: null,
|
|
150
|
+
deprecated: null,
|
|
135
151
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (prop.tsType.kind === "inlineObject" &&
|
|
142
|
-
prop.tsType.inlineObjectProperties) {
|
|
143
|
-
const nestedPath = [...currentPath, prop.name];
|
|
144
|
-
const nestedContext = {
|
|
152
|
+
extractNestedInlineObjectsRecursively({
|
|
153
|
+
properties: arg.inlineObjectProperties,
|
|
154
|
+
currentPath: [],
|
|
155
|
+
sourceLocation: field.sourceLocation,
|
|
156
|
+
buildContext: (nestedPath) => ({
|
|
145
157
|
kind: "resolverArg",
|
|
146
158
|
resolverType,
|
|
147
|
-
fieldName,
|
|
148
|
-
argName,
|
|
159
|
+
fieldName: field.name,
|
|
160
|
+
argName: arg.name,
|
|
149
161
|
parentTypeName,
|
|
150
162
|
fieldPath: nestedPath,
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
sourceLocation,
|
|
156
|
-
nullable: prop.tsType.nullable,
|
|
157
|
-
});
|
|
158
|
-
extractNestedInlineObjectsFromArg(prop.tsType.inlineObjectProperties, resolverType, fieldName, argName, parentTypeName, nestedPath, sourceLocation, results);
|
|
159
|
-
}
|
|
163
|
+
}),
|
|
164
|
+
preserveDocumentation: false,
|
|
165
|
+
results,
|
|
166
|
+
});
|
|
160
167
|
}
|
|
161
168
|
}
|
|
162
|
-
function
|
|
169
|
+
function collectInlinePayloadsFromResolvers(resolversResult) {
|
|
170
|
+
const results = [];
|
|
171
|
+
forEachResolverField(resolversResult, ({ field, resolverType, parentTypeName }) => {
|
|
172
|
+
collectInlinePayloadFromReturnType(field, resolverType, parentTypeName, results);
|
|
173
|
+
});
|
|
174
|
+
return results;
|
|
175
|
+
}
|
|
176
|
+
function collectInlinePayloadFromReturnType(field, resolverType, parentTypeName, results) {
|
|
177
|
+
if (!field.returnTypeInlineObjectProperties)
|
|
178
|
+
return;
|
|
179
|
+
const context = {
|
|
180
|
+
kind: "resolverPayload",
|
|
181
|
+
resolverType,
|
|
182
|
+
fieldName: field.name,
|
|
183
|
+
parentTypeName,
|
|
184
|
+
fieldPath: [],
|
|
185
|
+
};
|
|
186
|
+
results.push({
|
|
187
|
+
properties: field.returnTypeInlineObjectProperties,
|
|
188
|
+
context,
|
|
189
|
+
sourceLocation: field.sourceLocation,
|
|
190
|
+
nullable: field.type.nullable,
|
|
191
|
+
description: field.returnTypeInlineObjectDescription,
|
|
192
|
+
deprecated: field.returnTypeInlineObjectDeprecated,
|
|
193
|
+
});
|
|
194
|
+
extractNestedInlineObjectsRecursively({
|
|
195
|
+
properties: field.returnTypeInlineObjectProperties,
|
|
196
|
+
currentPath: [],
|
|
197
|
+
sourceLocation: field.sourceLocation,
|
|
198
|
+
buildContext: (nestedPath) => ({
|
|
199
|
+
kind: "resolverPayload",
|
|
200
|
+
resolverType,
|
|
201
|
+
fieldName: field.name,
|
|
202
|
+
parentTypeName,
|
|
203
|
+
fieldPath: nestedPath,
|
|
204
|
+
}),
|
|
205
|
+
preserveDocumentation: true,
|
|
206
|
+
results,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
function generateAutoType(params) {
|
|
210
|
+
const { inlineObj, generatedTypeNames, enumTypeNames, unionTypeNames } = params;
|
|
163
211
|
const name = generateAutoTypeName(inlineObj.context);
|
|
164
212
|
const isInput = inlineObj.context.kind === "inputField" ||
|
|
165
213
|
inlineObj.context.kind === "resolverArg";
|
|
@@ -178,7 +226,13 @@ function generateAutoType(inlineObj, generatedTypeNames) {
|
|
|
178
226
|
});
|
|
179
227
|
continue;
|
|
180
228
|
}
|
|
181
|
-
const fieldType = resolveFieldType(
|
|
229
|
+
const fieldType = resolveFieldType({
|
|
230
|
+
prop,
|
|
231
|
+
generatedTypeNames,
|
|
232
|
+
enumTypeNames,
|
|
233
|
+
unionTypeNames,
|
|
234
|
+
parentContext: inlineObj.context,
|
|
235
|
+
});
|
|
182
236
|
fields.push({
|
|
183
237
|
name: prop.name,
|
|
184
238
|
type: fieldType,
|
|
@@ -188,106 +242,195 @@ function generateAutoType(inlineObj, generatedTypeNames) {
|
|
|
188
242
|
defaultValue: prop.defaultValue,
|
|
189
243
|
});
|
|
190
244
|
}
|
|
191
|
-
const generatedFrom = {
|
|
192
|
-
parentTypeName: inlineObj.context.parentTypeName,
|
|
193
|
-
fieldPath: inlineObj.context.kind === "resolverArg" &&
|
|
194
|
-
inlineObj.context.fieldPath.length === 0
|
|
195
|
-
? [inlineObj.context.argName]
|
|
196
|
-
: inlineObj.context.fieldPath,
|
|
197
|
-
context: inlineObj.context.kind === "objectField"
|
|
198
|
-
? "typeField"
|
|
199
|
-
: inlineObj.context.kind === "inputField"
|
|
200
|
-
? "inputField"
|
|
201
|
-
: "resolverArg",
|
|
202
|
-
};
|
|
203
245
|
return {
|
|
204
246
|
type: {
|
|
205
247
|
name,
|
|
206
248
|
kind: isInput ? "InputObject" : "Object",
|
|
207
249
|
fields,
|
|
250
|
+
enumValues: null,
|
|
251
|
+
unionMembers: null,
|
|
252
|
+
needsStringEnumMapping: false,
|
|
208
253
|
sourceLocation: inlineObj.sourceLocation,
|
|
209
|
-
generatedFrom,
|
|
210
|
-
description:
|
|
254
|
+
generatedFrom: buildGeneratedFromInfo(inlineObj.context),
|
|
255
|
+
description: inlineObj.description,
|
|
256
|
+
resolveTypeFieldPattern: null,
|
|
211
257
|
},
|
|
212
258
|
diagnostics,
|
|
213
259
|
};
|
|
214
260
|
}
|
|
215
|
-
function
|
|
261
|
+
function tryResolveNestedType(prop, parentContext, typeNamesMap) {
|
|
262
|
+
const nestedPath = [...parentContext.fieldPath, prop.name];
|
|
263
|
+
const nestedContext = {
|
|
264
|
+
...parentContext,
|
|
265
|
+
fieldPath: nestedPath,
|
|
266
|
+
};
|
|
267
|
+
const contextKey = getContextKey(nestedContext);
|
|
268
|
+
const resolvedTypeName = typeNamesMap.get(contextKey);
|
|
269
|
+
if (resolvedTypeName) {
|
|
270
|
+
return {
|
|
271
|
+
typeName: resolvedTypeName,
|
|
272
|
+
nullable: prop.tsType.nullable || prop.optional,
|
|
273
|
+
list: false,
|
|
274
|
+
listItemNullable: null,
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
function resolveFieldType(params) {
|
|
280
|
+
const { prop, generatedTypeNames, enumTypeNames, unionTypeNames, parentContext, } = params;
|
|
216
281
|
if (prop.tsType.kind === "inlineObject" &&
|
|
217
282
|
prop.tsType.inlineObjectProperties) {
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
};
|
|
232
|
-
}
|
|
283
|
+
const result = tryResolveNestedType(prop, parentContext, generatedTypeNames);
|
|
284
|
+
if (result)
|
|
285
|
+
return result;
|
|
286
|
+
}
|
|
287
|
+
if (prop.tsType.kind === "inlineEnum" && prop.tsType.inlineEnumMembers) {
|
|
288
|
+
const result = tryResolveNestedType(prop, parentContext, enumTypeNames);
|
|
289
|
+
if (result)
|
|
290
|
+
return result;
|
|
291
|
+
}
|
|
292
|
+
if (prop.tsType.kind === "union" && prop.tsType.members) {
|
|
293
|
+
const result = tryResolveNestedType(prop, parentContext, unionTypeNames);
|
|
294
|
+
if (result)
|
|
295
|
+
return result;
|
|
233
296
|
}
|
|
234
297
|
return convertTsTypeToGraphQLType(prop.tsType, prop.optional);
|
|
235
298
|
}
|
|
236
|
-
function updateExtractedTypes(extractedTypes,
|
|
299
|
+
function updateExtractedTypes(extractedTypes, params) {
|
|
237
300
|
return extractedTypes.map((typeInfo) => {
|
|
238
301
|
const isInput = isInputTypeName(typeInfo.metadata.name);
|
|
239
302
|
return {
|
|
240
303
|
...typeInfo,
|
|
241
|
-
fields: typeInfo.fields.map((field) => updateField(field,
|
|
304
|
+
fields: typeInfo.fields.map((field) => updateField(field, params, typeInfo.metadata.name, isInput)),
|
|
242
305
|
};
|
|
243
306
|
});
|
|
244
307
|
}
|
|
245
|
-
function updateField(field,
|
|
308
|
+
function updateField(field, params, parentTypeName, isInput) {
|
|
309
|
+
const { generatedTypeNames, enumTypeNames, unionTypeNames } = params;
|
|
310
|
+
const context = buildFieldContext(parentTypeName, [field.name], isInput);
|
|
311
|
+
const contextKey = getContextKey(context);
|
|
312
|
+
// Handle inline objects
|
|
246
313
|
if (field.tsType.kind === "inlineObject" &&
|
|
247
314
|
field.tsType.inlineObjectProperties) {
|
|
248
|
-
const context = isInput
|
|
249
|
-
? { kind: "inputField", parentTypeName, fieldPath: [field.name] }
|
|
250
|
-
: { kind: "objectField", parentTypeName, fieldPath: [field.name] };
|
|
251
|
-
const contextKey = getContextKey(context);
|
|
252
315
|
const resolvedTypeName = generatedTypeNames.get(contextKey);
|
|
253
316
|
if (resolvedTypeName) {
|
|
254
317
|
return {
|
|
255
318
|
...field,
|
|
256
|
-
tsType: {
|
|
257
|
-
|
|
319
|
+
tsType: createReferenceType({
|
|
320
|
+
name: resolvedTypeName,
|
|
321
|
+
nullable: field.tsType.nullable,
|
|
322
|
+
}),
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// Handle inline enums
|
|
327
|
+
if (field.tsType.kind === "inlineEnum" && field.tsType.inlineEnumMembers) {
|
|
328
|
+
const resolvedTypeName = enumTypeNames.get(contextKey);
|
|
329
|
+
if (resolvedTypeName) {
|
|
330
|
+
return {
|
|
331
|
+
...field,
|
|
332
|
+
tsType: createReferenceType({
|
|
258
333
|
name: resolvedTypeName,
|
|
259
|
-
elementType: null,
|
|
260
|
-
members: null,
|
|
261
334
|
nullable: field.tsType.nullable,
|
|
262
|
-
|
|
263
|
-
|
|
335
|
+
}),
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
// Handle array of inline enums
|
|
340
|
+
if (field.tsType.kind === "array" &&
|
|
341
|
+
field.tsType.elementType?.kind === "inlineEnum" &&
|
|
342
|
+
field.tsType.elementType.inlineEnumMembers) {
|
|
343
|
+
const resolvedTypeName = enumTypeNames.get(contextKey);
|
|
344
|
+
if (resolvedTypeName) {
|
|
345
|
+
return {
|
|
346
|
+
...field,
|
|
347
|
+
tsType: {
|
|
348
|
+
...field.tsType,
|
|
349
|
+
elementType: createReferenceType({
|
|
350
|
+
name: resolvedTypeName,
|
|
351
|
+
nullable: field.tsType.elementType.nullable,
|
|
352
|
+
}),
|
|
264
353
|
},
|
|
265
354
|
};
|
|
266
355
|
}
|
|
267
356
|
}
|
|
357
|
+
// Handle inline union types
|
|
358
|
+
if (field.tsType.kind === "union" && field.tsType.members) {
|
|
359
|
+
const resolvedTypeName = unionTypeNames.get(contextKey);
|
|
360
|
+
if (resolvedTypeName) {
|
|
361
|
+
return {
|
|
362
|
+
...field,
|
|
363
|
+
tsType: createReferenceType({
|
|
364
|
+
name: resolvedTypeName,
|
|
365
|
+
nullable: field.tsType.nullable,
|
|
366
|
+
}),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
}
|
|
268
370
|
return field;
|
|
269
371
|
}
|
|
270
|
-
function updateResolversResult(resolversResult,
|
|
372
|
+
function updateResolversResult(resolversResult, params) {
|
|
271
373
|
return {
|
|
272
374
|
...resolversResult,
|
|
273
375
|
queryFields: {
|
|
274
|
-
fields: resolversResult.queryFields.fields.map((field) => updateResolverField(field,
|
|
376
|
+
fields: resolversResult.queryFields.fields.map((field) => updateResolverField(field, params, "query", null)),
|
|
275
377
|
},
|
|
276
378
|
mutationFields: {
|
|
277
|
-
fields: resolversResult.mutationFields.fields.map((field) => updateResolverField(field,
|
|
379
|
+
fields: resolversResult.mutationFields.fields.map((field) => updateResolverField(field, params, "mutation", null)),
|
|
278
380
|
},
|
|
279
381
|
typeExtensions: resolversResult.typeExtensions.map((ext) => ({
|
|
280
382
|
...ext,
|
|
281
|
-
fields: ext.fields.map((field) => updateResolverField(field,
|
|
383
|
+
fields: ext.fields.map((field) => updateResolverField(field, params, "field", ext.targetTypeName)),
|
|
282
384
|
})),
|
|
283
385
|
};
|
|
284
386
|
}
|
|
285
|
-
function updateResolverField(field,
|
|
286
|
-
|
|
287
|
-
|
|
387
|
+
function updateResolverField(field, params, resolverType, parentTypeName) {
|
|
388
|
+
const { generatedTypeNames, enumTypeNames, unionTypeNames } = params;
|
|
389
|
+
let updatedType = field.type;
|
|
390
|
+
// Create payload context once for all inline return type checks
|
|
391
|
+
const hasInlinePayload = field.returnTypeInlineObjectProperties ||
|
|
392
|
+
field.returnTypeInlineEnumMembers ||
|
|
393
|
+
field.returnTypeInlineUnionMembers;
|
|
394
|
+
if (hasInlinePayload) {
|
|
395
|
+
const payloadContext = {
|
|
396
|
+
kind: "resolverPayload",
|
|
397
|
+
resolverType,
|
|
398
|
+
fieldName: field.name,
|
|
399
|
+
parentTypeName,
|
|
400
|
+
fieldPath: [],
|
|
401
|
+
};
|
|
402
|
+
const payloadContextKey = getContextKey(payloadContext);
|
|
403
|
+
// These are mutually exclusive - a return type can only be one of:
|
|
404
|
+
// inline object, inline enum, or inline union
|
|
405
|
+
if (field.returnTypeInlineObjectProperties) {
|
|
406
|
+
// Handle inline payload objects in return type
|
|
407
|
+
const resolvedTypeName = generatedTypeNames.get(payloadContextKey);
|
|
408
|
+
if (resolvedTypeName) {
|
|
409
|
+
updatedType = { ...field.type, typeName: resolvedTypeName };
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else if (field.returnTypeInlineEnumMembers) {
|
|
413
|
+
// Handle inline enum in return type
|
|
414
|
+
const resolvedTypeName = enumTypeNames.get(payloadContextKey);
|
|
415
|
+
if (resolvedTypeName) {
|
|
416
|
+
updatedType = { ...field.type, typeName: resolvedTypeName };
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
else if (field.returnTypeInlineUnionMembers) {
|
|
420
|
+
// Handle inline union in return type
|
|
421
|
+
const resolvedTypeName = unionTypeNames.get(payloadContextKey);
|
|
422
|
+
if (resolvedTypeName) {
|
|
423
|
+
updatedType = { ...field.type, typeName: resolvedTypeName };
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
if (!field.args) {
|
|
428
|
+
return {
|
|
429
|
+
...field,
|
|
430
|
+
type: updatedType,
|
|
431
|
+
};
|
|
432
|
+
}
|
|
288
433
|
const updatedArgs = field.args.map((arg) => {
|
|
289
|
-
if (!arg.inlineObjectProperties)
|
|
290
|
-
return arg;
|
|
291
434
|
const context = {
|
|
292
435
|
kind: "resolverArg",
|
|
293
436
|
resolverType,
|
|
@@ -297,20 +440,50 @@ function updateResolverField(field, generatedTypeNames, resolverType, parentType
|
|
|
297
440
|
fieldPath: [],
|
|
298
441
|
};
|
|
299
442
|
const contextKey = getContextKey(context);
|
|
300
|
-
|
|
301
|
-
if (
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
...arg
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
443
|
+
// Handle inline objects
|
|
444
|
+
if (arg.inlineObjectProperties) {
|
|
445
|
+
const resolvedTypeName = generatedTypeNames.get(contextKey);
|
|
446
|
+
if (resolvedTypeName) {
|
|
447
|
+
return {
|
|
448
|
+
...arg,
|
|
449
|
+
type: {
|
|
450
|
+
...arg.type,
|
|
451
|
+
typeName: resolvedTypeName,
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// Handle inline enums
|
|
457
|
+
if (arg.inlineEnumMembers) {
|
|
458
|
+
const resolvedTypeName = enumTypeNames.get(contextKey);
|
|
459
|
+
if (resolvedTypeName) {
|
|
460
|
+
return {
|
|
461
|
+
...arg,
|
|
462
|
+
type: {
|
|
463
|
+
...arg.type,
|
|
464
|
+
typeName: resolvedTypeName,
|
|
465
|
+
},
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
// Handle inline unions (OneOf input objects)
|
|
470
|
+
if (arg.inlineUnionMembers) {
|
|
471
|
+
const resolvedTypeName = unionTypeNames.get(contextKey);
|
|
472
|
+
if (resolvedTypeName) {
|
|
473
|
+
return {
|
|
474
|
+
...arg,
|
|
475
|
+
type: {
|
|
476
|
+
...arg.type,
|
|
477
|
+
typeName: resolvedTypeName,
|
|
478
|
+
},
|
|
479
|
+
};
|
|
480
|
+
}
|
|
309
481
|
}
|
|
310
482
|
return arg;
|
|
311
483
|
});
|
|
312
484
|
return {
|
|
313
485
|
...field,
|
|
486
|
+
type: updatedType,
|
|
314
487
|
args: updatedArgs,
|
|
315
488
|
};
|
|
316
489
|
}
|
|
@@ -323,26 +496,547 @@ function buildGeneratedTypeNamesMap(inlineObjects) {
|
|
|
323
496
|
}
|
|
324
497
|
return map;
|
|
325
498
|
}
|
|
499
|
+
function toScreamingSnakeCase(value) {
|
|
500
|
+
return value
|
|
501
|
+
.replace(/[-\s]+/g, "_")
|
|
502
|
+
.replace(/([a-z])([A-Z])/g, "$1_$2")
|
|
503
|
+
.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2")
|
|
504
|
+
.toUpperCase();
|
|
505
|
+
}
|
|
506
|
+
function convertInlineEnumMembers(params) {
|
|
507
|
+
const { members, enumName, sourceLocation } = params;
|
|
508
|
+
let needsStringEnumMapping = false;
|
|
509
|
+
const enumValues = [];
|
|
510
|
+
const diagnostics = [];
|
|
511
|
+
const convertedMembers = [];
|
|
512
|
+
for (const member of members) {
|
|
513
|
+
const convertedName = toScreamingSnakeCase(member.value);
|
|
514
|
+
convertedMembers.push({ convertedName, member });
|
|
515
|
+
}
|
|
516
|
+
const prefixDetectionResult = detectEnumPrefix({
|
|
517
|
+
enumName,
|
|
518
|
+
memberValues: convertedMembers.map((m) => m.convertedName),
|
|
519
|
+
});
|
|
520
|
+
const finalNameToOriginals = new Map();
|
|
521
|
+
for (const { convertedName, member } of convertedMembers) {
|
|
522
|
+
let finalName = convertedName;
|
|
523
|
+
if (prefixDetectionResult.shouldStrip && prefixDetectionResult.prefix) {
|
|
524
|
+
finalName = stripEnumPrefix(convertedName, prefixDetectionResult.prefix);
|
|
525
|
+
needsStringEnumMapping = true;
|
|
526
|
+
}
|
|
527
|
+
else if (convertedName !== member.value) {
|
|
528
|
+
needsStringEnumMapping = true;
|
|
529
|
+
}
|
|
530
|
+
const originals = finalNameToOriginals.get(finalName) ?? [];
|
|
531
|
+
originals.push(member.value);
|
|
532
|
+
finalNameToOriginals.set(finalName, originals);
|
|
533
|
+
enumValues.push({
|
|
534
|
+
name: finalName,
|
|
535
|
+
originalValue: member.value,
|
|
536
|
+
description: member.description,
|
|
537
|
+
deprecated: member.deprecated,
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
for (const [finalName, originals] of finalNameToOriginals) {
|
|
541
|
+
if (originals.length > 1) {
|
|
542
|
+
diagnostics.push({
|
|
543
|
+
code: "DUPLICATE_ENUM_VALUE_AFTER_CONVERSION",
|
|
544
|
+
message: `Enum '${enumName}' has duplicate value '${finalName}' after conversion (from '${originals.join("' and '")}')`,
|
|
545
|
+
severity: "error",
|
|
546
|
+
location: sourceLocation,
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return { enumValues, needsStringEnumMapping, diagnostics };
|
|
551
|
+
}
|
|
552
|
+
function generateAutoEnumType(inlineEnum, typeName) {
|
|
553
|
+
const { enumValues, needsStringEnumMapping, diagnostics } = convertInlineEnumMembers({
|
|
554
|
+
members: inlineEnum.members,
|
|
555
|
+
enumName: typeName,
|
|
556
|
+
sourceLocation: inlineEnum.sourceLocation,
|
|
557
|
+
});
|
|
558
|
+
return {
|
|
559
|
+
type: {
|
|
560
|
+
name: typeName,
|
|
561
|
+
kind: "Enum",
|
|
562
|
+
fields: null,
|
|
563
|
+
enumValues,
|
|
564
|
+
unionMembers: null,
|
|
565
|
+
needsStringEnumMapping,
|
|
566
|
+
sourceLocation: inlineEnum.sourceLocation,
|
|
567
|
+
generatedFrom: buildGeneratedFromInfo(inlineEnum.context),
|
|
568
|
+
description: inlineEnum.externalEnumDescription,
|
|
569
|
+
resolveTypeFieldPattern: null,
|
|
570
|
+
},
|
|
571
|
+
diagnostics,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
function buildEnumTypeNamesMap(inlineEnums) {
|
|
575
|
+
const enumTypeNames = new Map();
|
|
576
|
+
const symbolToTypeName = new Map();
|
|
577
|
+
const symbolToContextKey = new Map();
|
|
578
|
+
const uniqueInlineEnums = [];
|
|
579
|
+
for (const inlineEnum of inlineEnums) {
|
|
580
|
+
const contextKey = getContextKey(inlineEnum.context);
|
|
581
|
+
if (inlineEnum.externalEnumSymbol !== null) {
|
|
582
|
+
const existingTypeName = symbolToTypeName.get(inlineEnum.externalEnumSymbol);
|
|
583
|
+
if (existingTypeName) {
|
|
584
|
+
enumTypeNames.set(contextKey, existingTypeName);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
const typeName = generateAutoTypeName(inlineEnum.context);
|
|
588
|
+
symbolToTypeName.set(inlineEnum.externalEnumSymbol, typeName);
|
|
589
|
+
symbolToContextKey.set(inlineEnum.externalEnumSymbol, contextKey);
|
|
590
|
+
enumTypeNames.set(contextKey, typeName);
|
|
591
|
+
uniqueInlineEnums.push(inlineEnum);
|
|
592
|
+
}
|
|
593
|
+
else {
|
|
594
|
+
const typeName = generateAutoTypeName(inlineEnum.context);
|
|
595
|
+
enumTypeNames.set(contextKey, typeName);
|
|
596
|
+
uniqueInlineEnums.push(inlineEnum);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return {
|
|
600
|
+
enumTypeNames,
|
|
601
|
+
externalEnumRegistry: { symbolToTypeName, symbolToContextKey },
|
|
602
|
+
uniqueInlineEnums,
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
function buildUnionTypeNamesMap(inlineUnions) {
|
|
606
|
+
const unionTypeNames = new Map();
|
|
607
|
+
for (const inlineUnion of inlineUnions) {
|
|
608
|
+
const contextKey = getContextKey(inlineUnion.context);
|
|
609
|
+
const typeName = generateAutoTypeName(inlineUnion.context);
|
|
610
|
+
unionTypeNames.set(contextKey, typeName);
|
|
611
|
+
}
|
|
612
|
+
return unionTypeNames;
|
|
613
|
+
}
|
|
614
|
+
function processOneOfInputObjects(params) {
|
|
615
|
+
const { inlineUnions, knownTypeNames, typeMap, unionTypeNames } = params;
|
|
616
|
+
const types = [];
|
|
617
|
+
const diagnostics = [];
|
|
618
|
+
for (const inlineUnion of inlineUnions) {
|
|
619
|
+
const contextKey = getContextKey(inlineUnion.context);
|
|
620
|
+
const typeName = generateAutoTypeName(inlineUnion.context);
|
|
621
|
+
const validationResult = validateOneOfMembers({
|
|
622
|
+
members: inlineUnion.members,
|
|
623
|
+
typeName,
|
|
624
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
625
|
+
typeMap,
|
|
626
|
+
});
|
|
627
|
+
diagnostics.push(...validationResult.diagnostics);
|
|
628
|
+
if (!validationResult.valid) {
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
const fields = generateOneOfFields({
|
|
632
|
+
members: inlineUnion.members,
|
|
633
|
+
knownTypeNames,
|
|
634
|
+
});
|
|
635
|
+
types.push({
|
|
636
|
+
name: typeName,
|
|
637
|
+
kind: "OneOfInputObject",
|
|
638
|
+
fields,
|
|
639
|
+
enumValues: null,
|
|
640
|
+
unionMembers: null,
|
|
641
|
+
needsStringEnumMapping: false,
|
|
642
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
643
|
+
generatedFrom: buildGeneratedFromInfo(inlineUnion.context),
|
|
644
|
+
description: null,
|
|
645
|
+
resolveTypeFieldPattern: null,
|
|
646
|
+
});
|
|
647
|
+
unionTypeNames.set(contextKey, typeName);
|
|
648
|
+
}
|
|
649
|
+
return { types, diagnostics };
|
|
650
|
+
}
|
|
651
|
+
function processUnionTypes(params) {
|
|
652
|
+
const { inlineUnions, knownTypeNames, generatedTypeNames, enumTypeNames, unionTypeNames, typeMap, } = params;
|
|
653
|
+
const types = [];
|
|
654
|
+
const diagnostics = [];
|
|
655
|
+
const generatedTypenameTypes = new Map();
|
|
656
|
+
for (const inlineUnion of inlineUnions) {
|
|
657
|
+
const contextKey = getContextKey(inlineUnion.context);
|
|
658
|
+
const typeName = generateAutoTypeName(inlineUnion.context);
|
|
659
|
+
const validationResult = validateUnionMembers({
|
|
660
|
+
members: inlineUnion.members,
|
|
661
|
+
typeName,
|
|
662
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
663
|
+
typeMap,
|
|
664
|
+
});
|
|
665
|
+
diagnostics.push(...validationResult.diagnostics);
|
|
666
|
+
if (!validationResult.valid) {
|
|
667
|
+
continue;
|
|
668
|
+
}
|
|
669
|
+
let resolveTypeFieldPattern = null;
|
|
670
|
+
if (inlineUnion.context.kind === "resolverPayload") {
|
|
671
|
+
const typenameValidationResult = validateUnionMemberTypenames({
|
|
672
|
+
members: inlineUnion.members,
|
|
673
|
+
unionTypeName: typeName,
|
|
674
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
675
|
+
typeMap,
|
|
676
|
+
});
|
|
677
|
+
diagnostics.push(...typenameValidationResult.diagnostics);
|
|
678
|
+
if (!typenameValidationResult.valid) {
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
if (typenameValidationResult.allMembersHaveTypename) {
|
|
682
|
+
resolveTypeFieldPattern = determineFieldPattern(typenameValidationResult.memberTypenames);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
const memberNames = resolveMemberNames({
|
|
686
|
+
members: inlineUnion.members,
|
|
687
|
+
knownTypeNames,
|
|
688
|
+
generatedTypeNames,
|
|
689
|
+
enumTypeNames,
|
|
690
|
+
parentContext: inlineUnion.context,
|
|
691
|
+
unionTypeNames,
|
|
692
|
+
types,
|
|
693
|
+
diagnostics,
|
|
694
|
+
generatedTypenameTypes,
|
|
695
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
696
|
+
});
|
|
697
|
+
types.push({
|
|
698
|
+
name: typeName,
|
|
699
|
+
kind: "Union",
|
|
700
|
+
fields: null,
|
|
701
|
+
enumValues: null,
|
|
702
|
+
unionMembers: memberNames,
|
|
703
|
+
needsStringEnumMapping: false,
|
|
704
|
+
sourceLocation: inlineUnion.sourceLocation,
|
|
705
|
+
generatedFrom: buildGeneratedFromInfo(inlineUnion.context),
|
|
706
|
+
description: null,
|
|
707
|
+
resolveTypeFieldPattern,
|
|
708
|
+
});
|
|
709
|
+
unionTypeNames.set(contextKey, typeName);
|
|
710
|
+
}
|
|
711
|
+
return { types, diagnostics };
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Determine the field pattern for resolveType based on the typename fields used by members.
|
|
715
|
+
*/
|
|
716
|
+
function determineFieldPattern(memberTypenames) {
|
|
717
|
+
const fieldNames = new Set();
|
|
718
|
+
for (const info of memberTypenames.values()) {
|
|
719
|
+
fieldNames.add(info.fieldName);
|
|
720
|
+
}
|
|
721
|
+
if (fieldNames.size === 0) {
|
|
722
|
+
return { usedFieldNames: createFieldNameSet(["__typename"]) };
|
|
723
|
+
}
|
|
724
|
+
return { usedFieldNames: fieldNames };
|
|
725
|
+
}
|
|
726
|
+
function processInlineUnions(params) {
|
|
727
|
+
const { inlineUnions, knownTypeNames, generatedTypeNames, enumTypeNames, unionTypeNames, extractedTypes, } = params;
|
|
728
|
+
const typeMap = new Map();
|
|
729
|
+
for (const typeInfo of extractedTypes) {
|
|
730
|
+
typeMap.set(typeInfo.metadata.name, typeInfo);
|
|
731
|
+
}
|
|
732
|
+
const inputUnions = inlineUnions.filter((u) => u.isInputContext);
|
|
733
|
+
const outputUnions = inlineUnions.filter((u) => !u.isInputContext);
|
|
734
|
+
const oneOfResult = processOneOfInputObjects({
|
|
735
|
+
inlineUnions: inputUnions,
|
|
736
|
+
knownTypeNames,
|
|
737
|
+
typeMap,
|
|
738
|
+
unionTypeNames,
|
|
739
|
+
});
|
|
740
|
+
const unionResult = processUnionTypes({
|
|
741
|
+
inlineUnions: outputUnions,
|
|
742
|
+
knownTypeNames,
|
|
743
|
+
generatedTypeNames,
|
|
744
|
+
enumTypeNames,
|
|
745
|
+
unionTypeNames,
|
|
746
|
+
typeMap,
|
|
747
|
+
});
|
|
748
|
+
return {
|
|
749
|
+
types: [...oneOfResult.types, ...unionResult.types],
|
|
750
|
+
diagnostics: [...oneOfResult.diagnostics, ...unionResult.diagnostics],
|
|
751
|
+
};
|
|
752
|
+
}
|
|
753
|
+
function generateOneOfFields(params) {
|
|
754
|
+
const { members, knownTypeNames } = params;
|
|
755
|
+
const fields = [];
|
|
756
|
+
for (const member of members) {
|
|
757
|
+
const memberType = member.memberType;
|
|
758
|
+
if (memberType.kind === "inlineObject" &&
|
|
759
|
+
memberType.inlineObjectProperties) {
|
|
760
|
+
for (const prop of memberType.inlineObjectProperties) {
|
|
761
|
+
const fieldType = convertTsTypeToGraphQLType(prop.tsType, prop.optional);
|
|
762
|
+
fields.push({
|
|
763
|
+
name: prop.name,
|
|
764
|
+
type: {
|
|
765
|
+
...fieldType,
|
|
766
|
+
nullable: true,
|
|
767
|
+
},
|
|
768
|
+
description: prop.description,
|
|
769
|
+
deprecated: prop.deprecated,
|
|
770
|
+
directives: prop.directives,
|
|
771
|
+
defaultValue: prop.defaultValue,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
else if (memberType.kind === "reference" && memberType.name) {
|
|
776
|
+
if (knownTypeNames.has(memberType.name)) {
|
|
777
|
+
const camelCaseName = memberType.name.charAt(0).toLowerCase() + memberType.name.slice(1);
|
|
778
|
+
fields.push({
|
|
779
|
+
name: camelCaseName,
|
|
780
|
+
type: {
|
|
781
|
+
typeName: memberType.name,
|
|
782
|
+
nullable: true,
|
|
783
|
+
list: false,
|
|
784
|
+
listItemNullable: null,
|
|
785
|
+
},
|
|
786
|
+
description: null,
|
|
787
|
+
deprecated: null,
|
|
788
|
+
directives: null,
|
|
789
|
+
defaultValue: null,
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return fields;
|
|
795
|
+
}
|
|
796
|
+
/**
|
|
797
|
+
* Extract __typename or $typeName property value from inline object properties.
|
|
798
|
+
* Returns null if neither is found or neither is a valid string literal.
|
|
799
|
+
* __typename takes priority over $typeName if both are present.
|
|
800
|
+
*/
|
|
801
|
+
function extractTypenameFromInlineObject(properties) {
|
|
802
|
+
const found = findTypenameProperty(properties, (p) => p.name);
|
|
803
|
+
if (!found) {
|
|
804
|
+
return null;
|
|
805
|
+
}
|
|
806
|
+
const { property, fieldName } = found;
|
|
807
|
+
const { tsType } = property;
|
|
808
|
+
if (tsType.kind === "literal" && tsType.name !== null) {
|
|
809
|
+
return { typeName: tsType.name, fieldName };
|
|
810
|
+
}
|
|
811
|
+
return null;
|
|
812
|
+
}
|
|
813
|
+
function resolveMemberNames(params) {
|
|
814
|
+
const { members, generatedTypeNames, parentContext, types, generatedTypenameTypes, diagnostics, sourceLocation, } = params;
|
|
815
|
+
const memberNames = [];
|
|
816
|
+
for (let i = 0; i < members.length; i++) {
|
|
817
|
+
const member = members[i];
|
|
818
|
+
const memberType = member.memberType;
|
|
819
|
+
if (memberType.kind === "reference" && memberType.name) {
|
|
820
|
+
memberNames.push(memberType.name);
|
|
821
|
+
}
|
|
822
|
+
else if (memberType.kind === "inlineObject" &&
|
|
823
|
+
memberType.inlineObjectProperties) {
|
|
824
|
+
// Only extract __typename or $typeName for resolverPayload context
|
|
825
|
+
// For other contexts (resolverArg, objectField, inputField), these fields
|
|
826
|
+
// should be treated as regular fields, not as type discriminators
|
|
827
|
+
const extractedInfo = parentContext.kind === "resolverPayload"
|
|
828
|
+
? extractTypenameFromInlineObject(memberType.inlineObjectProperties)
|
|
829
|
+
: null;
|
|
830
|
+
let memberTypeName;
|
|
831
|
+
let contextKey;
|
|
832
|
+
if (extractedInfo !== null) {
|
|
833
|
+
memberTypeName = extractedInfo.typeName;
|
|
834
|
+
const nestedContext = {
|
|
835
|
+
...parentContext,
|
|
836
|
+
fieldPath: [...parentContext.fieldPath, extractedInfo.typeName],
|
|
837
|
+
};
|
|
838
|
+
contextKey = getContextKey(nestedContext);
|
|
839
|
+
}
|
|
840
|
+
else {
|
|
841
|
+
const nestedContext = {
|
|
842
|
+
...parentContext,
|
|
843
|
+
fieldPath: [...parentContext.fieldPath, `member${i}`],
|
|
844
|
+
};
|
|
845
|
+
memberTypeName = generateAutoTypeName(nestedContext);
|
|
846
|
+
contextKey = getContextKey(nestedContext);
|
|
847
|
+
}
|
|
848
|
+
// Only filter out __typename or $typeName for resolverPayload context
|
|
849
|
+
// For other contexts, these are regular fields that should be preserved
|
|
850
|
+
const typenameFieldToFilter = extractedInfo?.fieldName ?? null;
|
|
851
|
+
const fields = memberType.inlineObjectProperties
|
|
852
|
+
.filter((prop) => parentContext.kind !== "resolverPayload" ||
|
|
853
|
+
prop.name !== typenameFieldToFilter)
|
|
854
|
+
.map((prop) => {
|
|
855
|
+
const fieldType = convertTsTypeToGraphQLType(prop.tsType, prop.optional);
|
|
856
|
+
return {
|
|
857
|
+
name: prop.name,
|
|
858
|
+
type: fieldType,
|
|
859
|
+
description: prop.description,
|
|
860
|
+
deprecated: prop.deprecated,
|
|
861
|
+
directives: prop.directives,
|
|
862
|
+
defaultValue: prop.defaultValue,
|
|
863
|
+
};
|
|
864
|
+
});
|
|
865
|
+
// Check if this typename was already seen with a different field structure
|
|
866
|
+
if (extractedInfo !== null) {
|
|
867
|
+
const existingFields = generatedTypenameTypes.get(extractedInfo.typeName);
|
|
868
|
+
if (existingFields !== undefined) {
|
|
869
|
+
// Compare field structures
|
|
870
|
+
if (!areFieldStructuresEqual(existingFields, fields)) {
|
|
871
|
+
diagnostics.push({
|
|
872
|
+
code: "TYPENAME_FIELD_STRUCTURE_MISMATCH",
|
|
873
|
+
message: `Type with ${extractedInfo.fieldName} '${extractedInfo.typeName}' has inconsistent field structures across different union members. All types with the same ${extractedInfo.fieldName} must have identical field definitions.`,
|
|
874
|
+
severity: "error",
|
|
875
|
+
location: sourceLocation,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
// Skip generating duplicate type and avoid adding duplicate union member
|
|
879
|
+
if (!memberNames.includes(memberTypeName)) {
|
|
880
|
+
memberNames.push(memberTypeName);
|
|
881
|
+
}
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
const nestedContext = {
|
|
886
|
+
...parentContext,
|
|
887
|
+
fieldPath: [
|
|
888
|
+
...parentContext.fieldPath,
|
|
889
|
+
extractedInfo?.typeName ?? `member${i}`,
|
|
890
|
+
],
|
|
891
|
+
};
|
|
892
|
+
types.push({
|
|
893
|
+
name: memberTypeName,
|
|
894
|
+
kind: "Object",
|
|
895
|
+
fields,
|
|
896
|
+
enumValues: null,
|
|
897
|
+
unionMembers: null,
|
|
898
|
+
needsStringEnumMapping: false,
|
|
899
|
+
sourceLocation: {
|
|
900
|
+
file: "",
|
|
901
|
+
line: 1,
|
|
902
|
+
column: 1,
|
|
903
|
+
},
|
|
904
|
+
generatedFrom: buildGeneratedFromInfo(nestedContext),
|
|
905
|
+
description: memberType.inlineObjectDescription,
|
|
906
|
+
resolveTypeFieldPattern: null,
|
|
907
|
+
});
|
|
908
|
+
generatedTypeNames.set(contextKey, memberTypeName);
|
|
909
|
+
if (extractedInfo !== null) {
|
|
910
|
+
generatedTypenameTypes.set(extractedInfo.typeName, fields);
|
|
911
|
+
}
|
|
912
|
+
memberNames.push(memberTypeName);
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return memberNames;
|
|
916
|
+
}
|
|
917
|
+
/**
|
|
918
|
+
* Compare two field structures for equality.
|
|
919
|
+
* Returns true if both have the same fields with the same types.
|
|
920
|
+
*/
|
|
921
|
+
function areFieldStructuresEqual(fields1, fields2) {
|
|
922
|
+
if (fields1.length !== fields2.length) {
|
|
923
|
+
return false;
|
|
924
|
+
}
|
|
925
|
+
const sorted1 = [...fields1].sort((a, b) => a.name.localeCompare(b.name));
|
|
926
|
+
const sorted2 = [...fields2].sort((a, b) => a.name.localeCompare(b.name));
|
|
927
|
+
for (let i = 0; i < sorted1.length; i++) {
|
|
928
|
+
const f1 = sorted1[i];
|
|
929
|
+
const f2 = sorted2[i];
|
|
930
|
+
if (f1.name !== f2.name) {
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
if (!areGraphQLTypesEqual(f1.type, f2.type)) {
|
|
934
|
+
return false;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
return true;
|
|
938
|
+
}
|
|
939
|
+
/**
|
|
940
|
+
* Compare two GraphQL type references for equality.
|
|
941
|
+
*/
|
|
942
|
+
function areGraphQLTypesEqual(type1, type2) {
|
|
943
|
+
if (type1.typeName !== type2.typeName) {
|
|
944
|
+
return false;
|
|
945
|
+
}
|
|
946
|
+
if (type1.nullable !== type2.nullable) {
|
|
947
|
+
return false;
|
|
948
|
+
}
|
|
949
|
+
if (type1.list !== type2.list) {
|
|
950
|
+
return false;
|
|
951
|
+
}
|
|
952
|
+
if (type1.listItemNullable !== type2.listItemNullable) {
|
|
953
|
+
return false;
|
|
954
|
+
}
|
|
955
|
+
return true;
|
|
956
|
+
}
|
|
326
957
|
export function generateAutoTypes(input) {
|
|
327
958
|
const inlineObjectsFromTypes = [];
|
|
328
959
|
for (const typeInfo of input.extractedTypes) {
|
|
329
960
|
inlineObjectsFromTypes.push(...collectInlineObjectsFromType(typeInfo));
|
|
330
961
|
}
|
|
331
962
|
const inlineObjectsFromResolvers = collectInlineObjectsFromResolvers(input.resolversResult);
|
|
963
|
+
const inlinePayloadsFromResolvers = collectInlinePayloadsFromResolvers(input.resolversResult);
|
|
332
964
|
const allInlineObjects = [
|
|
333
965
|
...inlineObjectsFromTypes,
|
|
334
966
|
...inlineObjectsFromResolvers,
|
|
967
|
+
...inlinePayloadsFromResolvers,
|
|
335
968
|
];
|
|
336
969
|
const generatedTypeNames = buildGeneratedTypeNamesMap(allInlineObjects);
|
|
970
|
+
const inlineEnumsFromTypes = collectInlineEnumsFromTypes(input.extractedTypes);
|
|
971
|
+
const inlineEnumsFromResolvers = collectInlineEnumsFromResolvers({
|
|
972
|
+
resolversResult: input.resolversResult,
|
|
973
|
+
});
|
|
974
|
+
const inlineEnumsFromPayloads = collectInlineEnumsFromPayloads({
|
|
975
|
+
resolversResult: input.resolversResult,
|
|
976
|
+
});
|
|
977
|
+
const allInlineEnums = [
|
|
978
|
+
...inlineEnumsFromTypes,
|
|
979
|
+
...inlineEnumsFromResolvers,
|
|
980
|
+
...inlineEnumsFromPayloads,
|
|
981
|
+
];
|
|
982
|
+
const { enumTypeNames, uniqueInlineEnums } = buildEnumTypeNamesMap(allInlineEnums);
|
|
983
|
+
// Collect inline unions from types, resolvers, and payloads
|
|
984
|
+
const inlineUnionsFromTypes = collectInlineUnionsFromTypes({
|
|
985
|
+
extractedTypes: input.extractedTypes,
|
|
986
|
+
knownTypeNames: input.knownTypeNames,
|
|
987
|
+
});
|
|
988
|
+
const inlineUnionsFromResolvers = collectInlineUnionsFromResolvers({
|
|
989
|
+
resolversResult: input.resolversResult,
|
|
990
|
+
knownTypeNames: input.knownTypeNames,
|
|
991
|
+
});
|
|
992
|
+
const inlineUnionsFromPayloads = collectInlineUnionsFromPayloads({
|
|
993
|
+
resolversResult: input.resolversResult,
|
|
994
|
+
knownTypeNames: input.knownTypeNames,
|
|
995
|
+
});
|
|
996
|
+
const allInlineUnions = [
|
|
997
|
+
...inlineUnionsFromTypes,
|
|
998
|
+
...inlineUnionsFromResolvers,
|
|
999
|
+
...inlineUnionsFromPayloads,
|
|
1000
|
+
];
|
|
1001
|
+
// Build union type names map before generating auto types
|
|
1002
|
+
const unionTypeNames = buildUnionTypeNamesMap(allInlineUnions);
|
|
337
1003
|
const autoGeneratedTypes = [];
|
|
338
1004
|
const diagnostics = [];
|
|
339
1005
|
for (const inlineObj of allInlineObjects) {
|
|
340
|
-
const result = generateAutoType(
|
|
1006
|
+
const result = generateAutoType({
|
|
1007
|
+
inlineObj,
|
|
1008
|
+
generatedTypeNames,
|
|
1009
|
+
enumTypeNames,
|
|
1010
|
+
unionTypeNames,
|
|
1011
|
+
});
|
|
341
1012
|
autoGeneratedTypes.push(result.type);
|
|
342
1013
|
diagnostics.push(...result.diagnostics);
|
|
343
1014
|
}
|
|
344
|
-
const
|
|
345
|
-
|
|
1015
|
+
for (const inlineEnum of uniqueInlineEnums) {
|
|
1016
|
+
const contextKey = getContextKey(inlineEnum.context);
|
|
1017
|
+
const typeName = enumTypeNames.get(contextKey);
|
|
1018
|
+
const result = generateAutoEnumType(inlineEnum, typeName);
|
|
1019
|
+
autoGeneratedTypes.push(result.type);
|
|
1020
|
+
diagnostics.push(...result.diagnostics);
|
|
1021
|
+
}
|
|
1022
|
+
// Process inline unions
|
|
1023
|
+
const { types: unionTypes, diagnostics: unionDiagnostics } = processInlineUnions({
|
|
1024
|
+
inlineUnions: allInlineUnions,
|
|
1025
|
+
knownTypeNames: input.knownTypeNames,
|
|
1026
|
+
generatedTypeNames,
|
|
1027
|
+
enumTypeNames,
|
|
1028
|
+
unionTypeNames,
|
|
1029
|
+
extractedTypes: input.extractedTypes,
|
|
1030
|
+
});
|
|
1031
|
+
autoGeneratedTypes.push(...unionTypes);
|
|
1032
|
+
diagnostics.push(...unionDiagnostics);
|
|
1033
|
+
const updateParams = {
|
|
1034
|
+
generatedTypeNames,
|
|
1035
|
+
enumTypeNames,
|
|
1036
|
+
unionTypeNames,
|
|
1037
|
+
};
|
|
1038
|
+
const updatedExtractedTypes = updateExtractedTypes(input.extractedTypes, updateParams);
|
|
1039
|
+
const updatedResolversResult = updateResolversResult(input.resolversResult, updateParams);
|
|
346
1040
|
return {
|
|
347
1041
|
autoGeneratedTypes,
|
|
348
1042
|
updatedExtractedTypes,
|