@gqlkit-ts/cli 0.5.1 → 0.7.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 +7 -0
- package/dist/auto-type-generator/auto-type-generator.d.ts.map +1 -1
- package/dist/auto-type-generator/auto-type-generator.js +379 -56
- package/dist/auto-type-generator/auto-type-generator.js.map +1 -1
- package/dist/auto-type-generator/discriminator-field-validator.d.ts +26 -0
- package/dist/auto-type-generator/discriminator-field-validator.d.ts.map +1 -0
- package/dist/auto-type-generator/discriminator-field-validator.js +242 -0
- package/dist/auto-type-generator/discriminator-field-validator.js.map +1 -0
- package/dist/auto-type-generator/discriminator-naming.d.ts +11 -0
- package/dist/auto-type-generator/discriminator-naming.d.ts.map +1 -0
- package/dist/auto-type-generator/discriminator-naming.js +15 -0
- package/dist/auto-type-generator/discriminator-naming.js.map +1 -0
- package/dist/auto-type-generator/discriminator-resolve-type-generator.d.ts +44 -0
- package/dist/auto-type-generator/discriminator-resolve-type-generator.d.ts.map +1 -0
- package/dist/auto-type-generator/discriminator-resolve-type-generator.js +77 -0
- package/dist/auto-type-generator/discriminator-resolve-type-generator.js.map +1 -0
- package/dist/auto-type-generator/index.d.ts +3 -0
- 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.map +1 -1
- package/dist/auto-type-generator/inline-enum-collector.js +14 -7
- package/dist/auto-type-generator/inline-enum-collector.js.map +1 -1
- package/dist/auto-type-generator/inline-object-converter.d.ts +12 -0
- package/dist/auto-type-generator/inline-object-converter.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-object-converter.js +72 -0
- package/dist/auto-type-generator/inline-object-converter.js.map +1 -0
- package/dist/auto-type-generator/inline-object-traverser.d.ts +2 -1
- package/dist/auto-type-generator/inline-object-traverser.d.ts.map +1 -1
- package/dist/auto-type-generator/inline-object-traverser.js +22 -4
- package/dist/auto-type-generator/inline-object-traverser.js.map +1 -1
- package/dist/auto-type-generator/inline-union-collector.d.ts.map +1 -1
- package/dist/auto-type-generator/inline-union-collector.js +20 -6
- package/dist/auto-type-generator/inline-union-collector.js.map +1 -1
- package/dist/auto-type-generator/inline-union-types.d.ts +2 -0
- package/dist/auto-type-generator/inline-union-types.d.ts.map +1 -1
- package/dist/auto-type-generator/inline-union-validator.js +3 -3
- package/dist/auto-type-generator/inline-union-validator.js.map +1 -1
- package/dist/auto-type-generator/intersection-flattener.d.ts +44 -0
- package/dist/auto-type-generator/intersection-flattener.d.ts.map +1 -0
- package/dist/auto-type-generator/intersection-flattener.js +398 -0
- package/dist/auto-type-generator/intersection-flattener.js.map +1 -0
- package/dist/auto-type-generator/naming-convention.d.ts +23 -2
- package/dist/auto-type-generator/naming-convention.d.ts.map +1 -1
- package/dist/auto-type-generator/naming-convention.js +145 -1
- package/dist/auto-type-generator/naming-convention.js.map +1 -1
- package/dist/auto-type-generator/resolver-field-iterator.d.ts +1 -1
- package/dist/auto-type-generator/resolver-field-iterator.d.ts.map +1 -1
- package/dist/auto-type-generator/resolver-field-iterator.js +3 -0
- package/dist/auto-type-generator/resolver-field-iterator.js.map +1 -1
- package/dist/auto-type-generator/typename-extractor.d.ts +2 -0
- package/dist/auto-type-generator/typename-extractor.d.ts.map +1 -1
- package/dist/auto-type-generator/typename-extractor.js +11 -3
- package/dist/auto-type-generator/typename-extractor.js.map +1 -1
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts +2 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts.map +1 -1
- package/dist/auto-type-generator/typename-resolve-type-generator.js +12 -84
- package/dist/auto-type-generator/typename-resolve-type-generator.js.map +1 -1
- package/dist/auto-type-generator/typename-types.d.ts +4 -0
- package/dist/auto-type-generator/typename-types.d.ts.map +1 -1
- package/dist/auto-type-generator/typename-types.js +6 -0
- package/dist/auto-type-generator/typename-types.js.map +1 -1
- package/dist/auto-type-generator/typename-validator.d.ts.map +1 -1
- package/dist/auto-type-generator/typename-validator.js +4 -3
- package/dist/auto-type-generator/typename-validator.js.map +1 -1
- package/dist/commands/docs.d.ts +1 -0
- package/dist/commands/docs.d.ts.map +1 -1
- package/dist/commands/gen.d.ts +1 -0
- package/dist/commands/gen.d.ts.map +1 -1
- package/dist/commands/gen.js +2 -1
- package/dist/commands/gen.js.map +1 -1
- package/dist/commands/main.d.ts +1 -0
- package/dist/commands/main.d.ts.map +1 -1
- package/dist/config/types.d.ts +7 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config-loader/index.d.ts +1 -1
- package/dist/config-loader/index.d.ts.map +1 -1
- package/dist/config-loader/index.js.map +1 -1
- package/dist/config-loader/loader.d.ts +6 -0
- package/dist/config-loader/loader.d.ts.map +1 -1
- package/dist/config-loader/loader.js +1 -0
- package/dist/config-loader/loader.js.map +1 -1
- package/dist/config-loader/validator.d.ts.map +1 -1
- package/dist/config-loader/validator.js +84 -1
- package/dist/config-loader/validator.js.map +1 -1
- package/dist/gen-orchestrator/orchestrator.d.ts +2 -1
- package/dist/gen-orchestrator/orchestrator.d.ts.map +1 -1
- package/dist/gen-orchestrator/orchestrator.js +43 -3
- package/dist/gen-orchestrator/orchestrator.js.map +1 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts +4 -0
- package/dist/resolver-extractor/extract-resolvers.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts +2 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.js +35 -6
- package/dist/resolver-extractor/extractor/define-api-extractor.js.map +1 -1
- package/dist/resolver-extractor/index.d.ts +1 -1
- package/dist/resolver-extractor/index.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts +2 -0
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js +16 -3
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.d.ts.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.js +24 -4
- package/dist/schema-generator/emitter/code-emitter.js.map +1 -1
- package/dist/schema-generator/emitter/discriminator-resolve-type-emitter.d.ts +18 -0
- package/dist/schema-generator/emitter/discriminator-resolve-type-emitter.d.ts.map +1 -0
- package/dist/schema-generator/emitter/discriminator-resolve-type-emitter.js +89 -0
- package/dist/schema-generator/emitter/discriminator-resolve-type-emitter.js.map +1 -0
- package/dist/schema-generator/generate-schema.d.ts +2 -0
- package/dist/schema-generator/generate-schema.d.ts.map +1 -1
- package/dist/schema-generator/generate-schema.js +69 -10
- package/dist/schema-generator/generate-schema.js.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.d.ts +5 -0
- package/dist/schema-generator/integrator/result-integrator.d.ts.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.js +44 -3
- 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 +4 -0
- package/dist/schema-generator/resolver-collector/resolver-collector.js.map +1 -1
- package/dist/shared/constants.d.ts.map +1 -1
- package/dist/shared/constants.js +14 -1
- package/dist/shared/constants.js.map +1 -1
- package/dist/shared/enum-prefix-detector.d.ts.map +1 -1
- package/dist/shared/enum-prefix-detector.js +78 -8
- package/dist/shared/enum-prefix-detector.js.map +1 -1
- package/dist/shared/inline-object-utils.js +1 -1
- package/dist/shared/inline-object-utils.js.map +1 -1
- package/dist/shared/type-converter.d.ts.map +1 -1
- package/dist/shared/type-converter.js +55 -0
- package/dist/shared/type-converter.js.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.d.ts.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.js +11 -1
- package/dist/type-extractor/converter/graphql-converter.js.map +1 -1
- package/dist/type-extractor/extractor/field-type-resolver.d.ts +18 -0
- package/dist/type-extractor/extractor/field-type-resolver.d.ts.map +1 -1
- package/dist/type-extractor/extractor/field-type-resolver.js +198 -15
- package/dist/type-extractor/extractor/field-type-resolver.js.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.d.ts +1 -0
- package/dist/type-extractor/extractor/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.js +100 -9
- package/dist/type-extractor/extractor/type-extractor.js.map +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts.map +1 -1
- package/dist/type-extractor/types/index.d.ts +1 -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 +7 -1
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.js +18 -3
- package/dist/type-extractor/types/ts-type-reference-factory.js.map +1 -1
- package/dist/type-extractor/types/typescript.d.ts +3 -1
- package/dist/type-extractor/types/typescript.d.ts.map +1 -1
- package/dist/type-extractor/validator/type-validator.d.ts.map +1 -1
- package/dist/type-extractor/validator/type-validator.js +6 -1
- package/dist/type-extractor/validator/type-validator.js.map +1 -1
- package/docs/configuration.md +19 -0
- package/docs/getting-started.md +2 -1
- package/docs/index.md +2 -0
- package/docs/integration/ai-sdk.md +189 -0
- package/docs/schema/conventions.md +7 -0
- package/docs/schema/fields.md +15 -0
- package/docs/schema/queries-mutations.md +21 -2
- package/docs/schema/subscriptions.md +173 -0
- package/docs/schema/unions.md +117 -0
- package/package.json +4 -4
- package/src/auto-type-generator/auto-type-generator.ts +588 -62
- package/src/auto-type-generator/discriminator-field-validator.ts +368 -0
- package/src/auto-type-generator/discriminator-naming.ts +24 -0
- package/src/auto-type-generator/discriminator-resolve-type-generator.ts +136 -0
- package/src/auto-type-generator/index.ts +17 -0
- package/src/auto-type-generator/inline-enum-collector.ts +19 -4
- package/src/auto-type-generator/inline-object-converter.ts +100 -0
- package/src/auto-type-generator/inline-object-traverser.ts +33 -7
- package/src/auto-type-generator/inline-union-collector.ts +26 -4
- package/src/auto-type-generator/inline-union-types.ts +2 -0
- package/src/auto-type-generator/inline-union-validator.ts +3 -3
- package/src/auto-type-generator/intersection-flattener.ts +554 -0
- package/src/auto-type-generator/naming-convention.ts +207 -3
- package/src/auto-type-generator/resolver-field-iterator.ts +5 -1
- package/src/auto-type-generator/typename-extractor.ts +17 -3
- package/src/auto-type-generator/typename-resolve-type-generator.ts +19 -108
- package/src/auto-type-generator/typename-types.ts +7 -0
- package/src/auto-type-generator/typename-validator.ts +4 -3
- package/src/commands/gen.ts +9 -2
- package/src/config/types.ts +10 -0
- package/src/config-loader/index.ts +1 -0
- package/src/config-loader/loader.ts +11 -0
- package/src/config-loader/validator.ts +100 -1
- package/src/gen-orchestrator/orchestrator.ts +50 -3
- package/src/resolver-extractor/extract-resolvers.ts +5 -0
- package/src/resolver-extractor/extractor/define-api-extractor.ts +47 -7
- package/src/resolver-extractor/index.ts +1 -0
- package/src/resolver-extractor/validator/abstract-resolver-validator.ts +20 -6
- package/src/schema-generator/emitter/code-emitter.ts +43 -5
- package/src/schema-generator/emitter/discriminator-resolve-type-emitter.ts +125 -0
- package/src/schema-generator/generate-schema.ts +100 -13
- package/src/schema-generator/integrator/result-integrator.ts +55 -2
- package/src/schema-generator/resolver-collector/resolver-collector.ts +7 -0
- package/src/shared/constants.ts +15 -1
- package/src/shared/enum-prefix-detector.ts +96 -8
- package/src/shared/inline-object-utils.ts +1 -1
- package/src/shared/type-converter.ts +63 -0
- package/src/type-extractor/converter/graphql-converter.ts +17 -1
- package/src/type-extractor/extractor/field-type-resolver.ts +241 -16
- package/src/type-extractor/extractor/type-extractor.ts +119 -5
- package/src/type-extractor/types/diagnostics.ts +10 -1
- package/src/type-extractor/types/index.ts +2 -1
- package/src/type-extractor/types/ts-type-reference-factory.ts +24 -3
- package/src/type-extractor/types/typescript.ts +6 -2
- package/src/type-extractor/validator/type-validator.ts +6 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { ResolvedDiscriminatorFieldsMap } from "../config-loader/index.js";
|
|
1
2
|
import type { ExtractResolversResult } from "../resolver-extractor/index.js";
|
|
2
3
|
import type { DirectiveArgumentValue, DirectiveInfo } from "../shared/directive-detector.js";
|
|
3
4
|
import type { DeprecationInfo } from "../shared/tsdoc-parser.js";
|
|
4
5
|
import { type Diagnostic, type ExtractedTypeInfo, type GraphQLFieldType, type SourceLocation } from "../type-extractor/types/index.js";
|
|
6
|
+
import { type InlineDiscriminatorResolveType } from "./intersection-flattener.js";
|
|
5
7
|
import type { ResolveTypeFieldPattern } from "./resolve-type-generator.js";
|
|
6
8
|
/**
|
|
7
9
|
* Information about where an auto-generated type was generated from.
|
|
@@ -57,12 +59,17 @@ export interface AutoTypeGeneratorInput {
|
|
|
57
59
|
readonly extractedTypes: ReadonlyArray<ExtractedTypeInfo>;
|
|
58
60
|
readonly resolversResult: ExtractResolversResult;
|
|
59
61
|
readonly knownTypeNames: ReadonlySet<string>;
|
|
62
|
+
readonly discriminatorFields: ResolvedDiscriminatorFieldsMap;
|
|
60
63
|
}
|
|
61
64
|
export interface AutoTypeGeneratorResult {
|
|
62
65
|
readonly autoGeneratedTypes: ReadonlyArray<AutoGeneratedType>;
|
|
63
66
|
readonly updatedExtractedTypes: ReadonlyArray<ExtractedTypeInfo>;
|
|
64
67
|
readonly updatedResolversResult: ExtractResolversResult;
|
|
65
68
|
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
69
|
+
/** Mapping from TypeScript type alias names to auto-generated GraphQL union names */
|
|
70
|
+
readonly tsAliasToGraphQLNameMap: ReadonlyMap<string, string>;
|
|
71
|
+
/** Discriminator resolveType info for inline unions that were flattened by discriminator fields */
|
|
72
|
+
readonly inlineDiscriminatorResolveTypes: ReadonlyArray<InlineDiscriminatorResolveType>;
|
|
66
73
|
}
|
|
67
74
|
export declare function generateAutoTypes(input: AutoTypeGeneratorInput): AutoTypeGeneratorResult;
|
|
68
75
|
//# sourceMappingURL=auto-type-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auto-type-generator.d.ts","sourceRoot":"","sources":["../../src/auto-type-generator/auto-type-generator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EAEvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,sBAAsB,EACtB,aAAa,EACd,MAAM,iCAAiC,CAAC;AAOzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,iBAAiB,EAEtB,KAAK,gBAAgB,EAGrB,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"auto-type-generator.d.ts","sourceRoot":"","sources":["../../src/auto-type-generator/auto-type-generator.ts"],"names":[],"mappings":"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"}
|
|
@@ -7,32 +7,60 @@ import { createReferenceType, } from "../type-extractor/types/index.js";
|
|
|
7
7
|
import { collectInlineEnumsFromPayloads, collectInlineEnumsFromResolvers, collectInlineEnumsFromTypes, } from "./inline-enum-collector.js";
|
|
8
8
|
import { collectInlineUnionsFromPayloads, collectInlineUnionsFromResolvers, collectInlineUnionsFromTypes, } from "./inline-union-collector.js";
|
|
9
9
|
import { validateOneOfMembers, validateUnionMembers, validateUnionMemberTypenames, } from "./inline-union-validator.js";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
10
|
+
import { flattenInlineUnionMembers, } from "./intersection-flattener.js";
|
|
11
|
+
import { appendFieldPath, buildFieldContext, generateAutoTypeName, isInputTypeName, } from "./naming-convention.js";
|
|
12
|
+
import { forEachResolverField, } from "./resolver-field-iterator.js";
|
|
13
|
+
import { createFieldNameSet, findTypenameProperty, isTypenameFieldName, } from "./typename-types.js";
|
|
14
|
+
function getInlineObjectTypeInfo(tsType) {
|
|
15
|
+
if (tsType.kind === "inlineObject" && tsType.inlineObjectProperties) {
|
|
16
|
+
return {
|
|
17
|
+
properties: tsType.inlineObjectProperties,
|
|
18
|
+
nullable: tsType.nullable,
|
|
19
|
+
description: tsType.inlineObjectDescription,
|
|
20
|
+
deprecated: tsType.inlineObjectDeprecated,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (tsType.kind === "array" &&
|
|
24
|
+
tsType.elementType?.kind === "inlineObject" &&
|
|
25
|
+
tsType.elementType.inlineObjectProperties) {
|
|
26
|
+
return {
|
|
27
|
+
properties: tsType.elementType.inlineObjectProperties,
|
|
28
|
+
nullable: tsType.elementType.nullable,
|
|
29
|
+
description: tsType.elementType.inlineObjectDescription,
|
|
30
|
+
deprecated: tsType.elementType.inlineObjectDeprecated,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
13
35
|
function extractNestedInlineObjectsRecursively(params) {
|
|
14
36
|
const { properties, currentPath, sourceLocation, buildContext, preserveDocumentation, results, } = params;
|
|
37
|
+
const siblingFieldNames = new Set(properties.map((prop) => prop.name));
|
|
15
38
|
for (const prop of properties) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const nestedPath =
|
|
39
|
+
const inlineObjectTypeInfo = getInlineObjectTypeInfo(prop.tsType);
|
|
40
|
+
if (inlineObjectTypeInfo) {
|
|
41
|
+
const nestedPath = appendFieldPath({
|
|
42
|
+
parentPath: currentPath,
|
|
43
|
+
fieldName: prop.name,
|
|
44
|
+
singularize: prop.tsType.kind === "array",
|
|
45
|
+
siblingFieldNames,
|
|
46
|
+
});
|
|
19
47
|
const nestedContext = buildContext(nestedPath);
|
|
20
48
|
// Use property's source location if available for more accurate diagnostics
|
|
21
49
|
const nestedSourceLocation = prop.sourceLocation ?? sourceLocation;
|
|
22
50
|
results.push({
|
|
23
|
-
properties:
|
|
51
|
+
properties: inlineObjectTypeInfo.properties,
|
|
24
52
|
context: nestedContext,
|
|
25
53
|
sourceLocation: nestedSourceLocation,
|
|
26
|
-
nullable:
|
|
54
|
+
nullable: inlineObjectTypeInfo.nullable,
|
|
27
55
|
description: preserveDocumentation
|
|
28
|
-
?
|
|
56
|
+
? inlineObjectTypeInfo.description
|
|
29
57
|
: null,
|
|
30
58
|
deprecated: preserveDocumentation
|
|
31
|
-
?
|
|
59
|
+
? inlineObjectTypeInfo.deprecated
|
|
32
60
|
: null,
|
|
33
61
|
});
|
|
34
62
|
extractNestedInlineObjectsRecursively({
|
|
35
|
-
properties:
|
|
63
|
+
properties: inlineObjectTypeInfo.properties,
|
|
36
64
|
currentPath: nestedPath,
|
|
37
65
|
sourceLocation: nestedSourceLocation,
|
|
38
66
|
buildContext,
|
|
@@ -79,6 +107,7 @@ function buildGeneratedFromInfo(context) {
|
|
|
79
107
|
function collectInlineObjectsFromType(typeInfo) {
|
|
80
108
|
const results = [];
|
|
81
109
|
const isInput = isInputTypeName(typeInfo.metadata.name);
|
|
110
|
+
const siblingFieldNames = new Set(typeInfo.fields.map((field) => field.name));
|
|
82
111
|
for (const field of typeInfo.fields) {
|
|
83
112
|
collectInlineObjectsFromField({
|
|
84
113
|
field,
|
|
@@ -86,18 +115,24 @@ function collectInlineObjectsFromType(typeInfo) {
|
|
|
86
115
|
parentPath: [],
|
|
87
116
|
isInput,
|
|
88
117
|
sourceFile: typeInfo.metadata.sourceFile,
|
|
118
|
+
siblingFieldNames,
|
|
89
119
|
results,
|
|
90
120
|
});
|
|
91
121
|
}
|
|
92
122
|
return results;
|
|
93
123
|
}
|
|
94
124
|
function collectInlineObjectsFromField(params) {
|
|
95
|
-
const { field, parentTypeName, parentPath, isInput, sourceFile, results } = params;
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
125
|
+
const { field, parentTypeName, parentPath, isInput, sourceFile, siblingFieldNames, results, } = params;
|
|
126
|
+
const inlineObjectTypeInfo = getInlineObjectTypeInfo(field.tsType);
|
|
127
|
+
if (!inlineObjectTypeInfo) {
|
|
98
128
|
return;
|
|
99
129
|
}
|
|
100
|
-
const fieldPath =
|
|
130
|
+
const fieldPath = appendFieldPath({
|
|
131
|
+
parentPath,
|
|
132
|
+
fieldName: field.name,
|
|
133
|
+
singularize: field.tsType.kind === "array",
|
|
134
|
+
siblingFieldNames,
|
|
135
|
+
});
|
|
101
136
|
const context = isInput
|
|
102
137
|
? {
|
|
103
138
|
kind: "inputField",
|
|
@@ -111,15 +146,15 @@ function collectInlineObjectsFromField(params) {
|
|
|
111
146
|
};
|
|
112
147
|
const sourceLocation = getSourceLocationOrDefault(field.sourceLocation, sourceFile);
|
|
113
148
|
results.push({
|
|
114
|
-
properties:
|
|
149
|
+
properties: inlineObjectTypeInfo.properties,
|
|
115
150
|
context,
|
|
116
151
|
sourceLocation,
|
|
117
|
-
nullable:
|
|
118
|
-
description:
|
|
119
|
-
deprecated:
|
|
152
|
+
nullable: inlineObjectTypeInfo.nullable,
|
|
153
|
+
description: inlineObjectTypeInfo.description,
|
|
154
|
+
deprecated: inlineObjectTypeInfo.deprecated,
|
|
120
155
|
});
|
|
121
156
|
extractNestedInlineObjectsRecursively({
|
|
122
|
-
properties:
|
|
157
|
+
properties: inlineObjectTypeInfo.properties,
|
|
123
158
|
currentPath: fieldPath,
|
|
124
159
|
sourceLocation,
|
|
125
160
|
buildContext: (nestedPath) => isInput
|
|
@@ -222,7 +257,12 @@ function generateAutoType(params) {
|
|
|
222
257
|
inlineObj.context.kind === "resolverArg";
|
|
223
258
|
const fields = [];
|
|
224
259
|
const diagnostics = [];
|
|
260
|
+
const siblingFieldNames = new Set(inlineObj.properties.map((prop) => prop.name));
|
|
225
261
|
for (const prop of inlineObj.properties) {
|
|
262
|
+
// Typename discrimination fields are silently excluded from the schema
|
|
263
|
+
if (isTypenameFieldName(prop.name)) {
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
226
266
|
const eligibility = isEligibleField({
|
|
227
267
|
fieldName: prop.name,
|
|
228
268
|
kind: isInput ? "input" : "object",
|
|
@@ -242,7 +282,12 @@ function generateAutoType(params) {
|
|
|
242
282
|
enumTypeNames,
|
|
243
283
|
unionTypeNames,
|
|
244
284
|
parentContext: inlineObj.context,
|
|
285
|
+
siblingFieldNames,
|
|
245
286
|
});
|
|
287
|
+
// Skip fields with never type — they represent impossible values
|
|
288
|
+
if (fieldType.typeName === "__NEVER__") {
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
246
291
|
fields.push({
|
|
247
292
|
name: prop.name,
|
|
248
293
|
type: fieldType,
|
|
@@ -268,8 +313,13 @@ function generateAutoType(params) {
|
|
|
268
313
|
diagnostics,
|
|
269
314
|
};
|
|
270
315
|
}
|
|
271
|
-
function tryResolveNestedType(prop, parentContext, typeNamesMap) {
|
|
272
|
-
const nestedPath =
|
|
316
|
+
function tryResolveNestedType(prop, parentContext, typeNamesMap, siblingFieldNames) {
|
|
317
|
+
const nestedPath = appendFieldPath({
|
|
318
|
+
parentPath: parentContext.fieldPath,
|
|
319
|
+
fieldName: prop.name,
|
|
320
|
+
singularize: prop.tsType.kind === "array",
|
|
321
|
+
siblingFieldNames,
|
|
322
|
+
});
|
|
273
323
|
const nestedContext = {
|
|
274
324
|
...parentContext,
|
|
275
325
|
fieldPath: nestedPath,
|
|
@@ -278,29 +328,36 @@ function tryResolveNestedType(prop, parentContext, typeNamesMap) {
|
|
|
278
328
|
const resolvedTypeName = typeNamesMap.get(contextKey);
|
|
279
329
|
if (resolvedTypeName) {
|
|
280
330
|
return {
|
|
331
|
+
...convertTsTypeToGraphQLType(prop.tsType, prop.optional),
|
|
281
332
|
typeName: resolvedTypeName,
|
|
282
|
-
nullable: prop.tsType.nullable || prop.optional,
|
|
283
|
-
list: false,
|
|
284
|
-
listItemNullable: null,
|
|
285
333
|
};
|
|
286
334
|
}
|
|
287
335
|
return null;
|
|
288
336
|
}
|
|
289
337
|
function resolveFieldType(params) {
|
|
290
|
-
const { prop, generatedTypeNames, enumTypeNames, unionTypeNames, parentContext, } = params;
|
|
291
|
-
if (prop.tsType.kind === "inlineObject" &&
|
|
292
|
-
prop.tsType.inlineObjectProperties)
|
|
293
|
-
|
|
338
|
+
const { prop, generatedTypeNames, enumTypeNames, unionTypeNames, parentContext, siblingFieldNames, } = params;
|
|
339
|
+
if ((prop.tsType.kind === "inlineObject" &&
|
|
340
|
+
prop.tsType.inlineObjectProperties) ||
|
|
341
|
+
(prop.tsType.kind === "array" &&
|
|
342
|
+
prop.tsType.elementType?.kind === "inlineObject" &&
|
|
343
|
+
prop.tsType.elementType.inlineObjectProperties)) {
|
|
344
|
+
const result = tryResolveNestedType(prop, parentContext, generatedTypeNames, siblingFieldNames);
|
|
294
345
|
if (result)
|
|
295
346
|
return result;
|
|
296
347
|
}
|
|
297
|
-
if (prop.tsType.kind === "inlineEnum" && prop.tsType.inlineEnumMembers)
|
|
298
|
-
|
|
348
|
+
if ((prop.tsType.kind === "inlineEnum" && prop.tsType.inlineEnumMembers) ||
|
|
349
|
+
(prop.tsType.kind === "array" &&
|
|
350
|
+
prop.tsType.elementType?.kind === "inlineEnum" &&
|
|
351
|
+
prop.tsType.elementType.inlineEnumMembers)) {
|
|
352
|
+
const result = tryResolveNestedType(prop, parentContext, enumTypeNames, siblingFieldNames);
|
|
299
353
|
if (result)
|
|
300
354
|
return result;
|
|
301
355
|
}
|
|
302
|
-
if (prop.tsType.kind === "union" && prop.tsType.members)
|
|
303
|
-
|
|
356
|
+
if ((prop.tsType.kind === "union" && prop.tsType.members) ||
|
|
357
|
+
(prop.tsType.kind === "array" &&
|
|
358
|
+
prop.tsType.elementType?.kind === "union" &&
|
|
359
|
+
prop.tsType.elementType.members)) {
|
|
360
|
+
const result = tryResolveNestedType(prop, parentContext, unionTypeNames, siblingFieldNames);
|
|
304
361
|
if (result)
|
|
305
362
|
return result;
|
|
306
363
|
}
|
|
@@ -309,15 +366,21 @@ function resolveFieldType(params) {
|
|
|
309
366
|
function updateExtractedTypes(extractedTypes, params) {
|
|
310
367
|
return extractedTypes.map((typeInfo) => {
|
|
311
368
|
const isInput = isInputTypeName(typeInfo.metadata.name);
|
|
369
|
+
const siblingFieldNames = new Set(typeInfo.fields.map((field) => field.name));
|
|
312
370
|
return {
|
|
313
371
|
...typeInfo,
|
|
314
|
-
fields: typeInfo.fields.map((field) => updateField(field, params, typeInfo.metadata.name, isInput)),
|
|
372
|
+
fields: typeInfo.fields.map((field) => updateField(field, params, typeInfo.metadata.name, isInput, siblingFieldNames)),
|
|
315
373
|
};
|
|
316
374
|
});
|
|
317
375
|
}
|
|
318
|
-
function updateField(field, params, parentTypeName, isInput) {
|
|
376
|
+
function updateField(field, params, parentTypeName, isInput, siblingFieldNames) {
|
|
319
377
|
const { generatedTypeNames, enumTypeNames, unionTypeNames } = params;
|
|
320
|
-
const context = buildFieldContext(parentTypeName,
|
|
378
|
+
const context = buildFieldContext(parentTypeName, appendFieldPath({
|
|
379
|
+
parentPath: [],
|
|
380
|
+
fieldName: field.name,
|
|
381
|
+
singularize: field.tsType.kind === "array",
|
|
382
|
+
siblingFieldNames,
|
|
383
|
+
}), isInput);
|
|
321
384
|
const contextKey = getContextKey(context);
|
|
322
385
|
// Handle inline objects
|
|
323
386
|
if (field.tsType.kind === "inlineObject" &&
|
|
@@ -333,6 +396,24 @@ function updateField(field, params, parentTypeName, isInput) {
|
|
|
333
396
|
};
|
|
334
397
|
}
|
|
335
398
|
}
|
|
399
|
+
// Handle array of inline objects
|
|
400
|
+
if (field.tsType.kind === "array" &&
|
|
401
|
+
field.tsType.elementType?.kind === "inlineObject" &&
|
|
402
|
+
field.tsType.elementType.inlineObjectProperties) {
|
|
403
|
+
const resolvedTypeName = generatedTypeNames.get(contextKey);
|
|
404
|
+
if (resolvedTypeName) {
|
|
405
|
+
return {
|
|
406
|
+
...field,
|
|
407
|
+
tsType: {
|
|
408
|
+
...field.tsType,
|
|
409
|
+
elementType: createReferenceType({
|
|
410
|
+
name: resolvedTypeName,
|
|
411
|
+
nullable: field.tsType.elementType.nullable,
|
|
412
|
+
}),
|
|
413
|
+
},
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
}
|
|
336
417
|
// Handle inline enums
|
|
337
418
|
if (field.tsType.kind === "inlineEnum" && field.tsType.inlineEnumMembers) {
|
|
338
419
|
const resolvedTypeName = enumTypeNames.get(contextKey);
|
|
@@ -377,6 +458,24 @@ function updateField(field, params, parentTypeName, isInput) {
|
|
|
377
458
|
};
|
|
378
459
|
}
|
|
379
460
|
}
|
|
461
|
+
// Handle array of inline union types
|
|
462
|
+
if (field.tsType.kind === "array" &&
|
|
463
|
+
field.tsType.elementType?.kind === "union" &&
|
|
464
|
+
field.tsType.elementType.members) {
|
|
465
|
+
const resolvedTypeName = unionTypeNames.get(contextKey);
|
|
466
|
+
if (resolvedTypeName) {
|
|
467
|
+
return {
|
|
468
|
+
...field,
|
|
469
|
+
tsType: {
|
|
470
|
+
...field.tsType,
|
|
471
|
+
elementType: createReferenceType({
|
|
472
|
+
name: resolvedTypeName,
|
|
473
|
+
nullable: field.tsType.elementType.nullable,
|
|
474
|
+
}),
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}
|
|
380
479
|
return field;
|
|
381
480
|
}
|
|
382
481
|
function updateResolversResult(resolversResult, params) {
|
|
@@ -388,6 +487,9 @@ function updateResolversResult(resolversResult, params) {
|
|
|
388
487
|
mutationFields: {
|
|
389
488
|
fields: resolversResult.mutationFields.fields.map((field) => updateResolverField(field, params, "mutation", null)),
|
|
390
489
|
},
|
|
490
|
+
subscriptionFields: {
|
|
491
|
+
fields: resolversResult.subscriptionFields.fields.map((field) => updateResolverField(field, params, "subscription", null)),
|
|
492
|
+
},
|
|
391
493
|
typeExtensions: resolversResult.typeExtensions.map((ext) => ({
|
|
392
494
|
...ext,
|
|
393
495
|
fields: ext.fields.map((field) => updateResolverField(field, params, "field", ext.targetTypeName)),
|
|
@@ -762,6 +864,9 @@ function generateOneOfFields(params) {
|
|
|
762
864
|
memberType.inlineObjectProperties) {
|
|
763
865
|
for (const prop of memberType.inlineObjectProperties) {
|
|
764
866
|
const fieldType = convertTsTypeToGraphQLType(prop.tsType, prop.optional);
|
|
867
|
+
if (fieldType.typeName === "__NEVER__") {
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
765
870
|
fields.push({
|
|
766
871
|
name: prop.name,
|
|
767
872
|
type: {
|
|
@@ -808,11 +913,195 @@ function extractTypenameFromInlineObject(properties) {
|
|
|
808
913
|
}
|
|
809
914
|
const { property, fieldName } = found;
|
|
810
915
|
const { tsType } = property;
|
|
811
|
-
if (tsType.kind === "
|
|
916
|
+
if (tsType.kind === "stringLiteral" && tsType.name !== null) {
|
|
812
917
|
return { typeName: tsType.name, fieldName };
|
|
813
918
|
}
|
|
814
919
|
return null;
|
|
815
920
|
}
|
|
921
|
+
/**
|
|
922
|
+
* Convert inline object/enum/union properties within a union member to AutoGeneratedFields.
|
|
923
|
+
* Handles __INLINE_OBJECT__, __INLINE_ENUM__, and inline union (kind: "union") sentinels
|
|
924
|
+
* by generating appropriate auto types and replacing sentinel type names.
|
|
925
|
+
*/
|
|
926
|
+
function convertMemberPropertiesToFields(properties, parentTypeName, ctx) {
|
|
927
|
+
const siblingFieldNames = new Set(properties.map((prop) => prop.name));
|
|
928
|
+
return properties.flatMap((prop) => {
|
|
929
|
+
const fieldType = convertTsTypeToGraphQLType(prop.tsType, prop.optional);
|
|
930
|
+
if (fieldType.typeName === "__NEVER__") {
|
|
931
|
+
return [];
|
|
932
|
+
}
|
|
933
|
+
const resolvedTypeName = resolveInlineTypeInMember(prop, fieldType, parentTypeName, siblingFieldNames, ctx);
|
|
934
|
+
return {
|
|
935
|
+
name: prop.name,
|
|
936
|
+
type: resolvedTypeName
|
|
937
|
+
? { ...fieldType, typeName: resolvedTypeName }
|
|
938
|
+
: fieldType,
|
|
939
|
+
description: prop.description,
|
|
940
|
+
deprecated: prop.deprecated,
|
|
941
|
+
directives: prop.directives,
|
|
942
|
+
defaultValue: prop.defaultValue,
|
|
943
|
+
};
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
/**
|
|
947
|
+
* Resolve an inline type (object, enum, or union) within a union member property.
|
|
948
|
+
* Returns the generated type name if resolved, or null if no resolution is needed.
|
|
949
|
+
*/
|
|
950
|
+
function resolveInlineTypeInMember(prop, fieldType, parentTypeName, siblingFieldNames, ctx) {
|
|
951
|
+
// Determine the inline TS type (direct or array element)
|
|
952
|
+
const inlineTsType = prop.tsType.kind === "array" ? prop.tsType.elementType : prop.tsType;
|
|
953
|
+
const singularizeArrayFieldName = prop.tsType.kind === "array";
|
|
954
|
+
if (!inlineTsType)
|
|
955
|
+
return null;
|
|
956
|
+
// Resolve nested inline objects
|
|
957
|
+
if (fieldType.typeName === "__INLINE_OBJECT__" &&
|
|
958
|
+
inlineTsType.kind === "inlineObject" &&
|
|
959
|
+
inlineTsType.inlineObjectProperties) {
|
|
960
|
+
return resolveNestedInlineObjectInMember(inlineTsType.inlineObjectProperties, prop.name, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx, inlineTsType.inlineObjectDescription);
|
|
961
|
+
}
|
|
962
|
+
// Resolve inline enums (string literal unions)
|
|
963
|
+
if (fieldType.typeName === "__INLINE_ENUM__" &&
|
|
964
|
+
inlineTsType.kind === "inlineEnum" &&
|
|
965
|
+
inlineTsType.inlineEnumMembers) {
|
|
966
|
+
return resolveInlineEnumInMember(inlineTsType.inlineEnumMembers, prop.name, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx, inlineTsType.externalEnumDescription);
|
|
967
|
+
}
|
|
968
|
+
// Resolve inline unions (reference type unions like User | Bot)
|
|
969
|
+
if (inlineTsType.kind === "union" && inlineTsType.members) {
|
|
970
|
+
return resolveInlineUnionInMember(inlineTsType.members, prop.name, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx);
|
|
971
|
+
}
|
|
972
|
+
return null;
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* Resolve a nested inline object within an inline union member.
|
|
976
|
+
* Generates an AutoGeneratedType using objectField context and recurses
|
|
977
|
+
* into deeper nesting levels.
|
|
978
|
+
*/
|
|
979
|
+
function resolveNestedInlineObjectInMember(properties, fieldName, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx, description) {
|
|
980
|
+
const context = {
|
|
981
|
+
kind: "objectField",
|
|
982
|
+
parentTypeName,
|
|
983
|
+
fieldPath: appendFieldPath({
|
|
984
|
+
parentPath: [],
|
|
985
|
+
fieldName,
|
|
986
|
+
singularize: singularizeArrayFieldName,
|
|
987
|
+
siblingFieldNames,
|
|
988
|
+
}),
|
|
989
|
+
};
|
|
990
|
+
const typeName = generateAutoTypeName(context);
|
|
991
|
+
const contextKey = getContextKey(context);
|
|
992
|
+
if (ctx.generatedTypeNames.has(contextKey)) {
|
|
993
|
+
return ctx.generatedTypeNames.get(contextKey);
|
|
994
|
+
}
|
|
995
|
+
const fields = convertMemberPropertiesToFields(properties, typeName, ctx);
|
|
996
|
+
ctx.types.push({
|
|
997
|
+
name: typeName,
|
|
998
|
+
kind: "Object",
|
|
999
|
+
fields,
|
|
1000
|
+
enumValues: null,
|
|
1001
|
+
unionMembers: null,
|
|
1002
|
+
needsStringEnumMapping: false,
|
|
1003
|
+
sourceLocation: ctx.sourceLocation,
|
|
1004
|
+
generatedFrom: buildGeneratedFromInfo(context),
|
|
1005
|
+
description,
|
|
1006
|
+
resolveTypeFieldPattern: null,
|
|
1007
|
+
});
|
|
1008
|
+
ctx.generatedTypeNames.set(contextKey, typeName);
|
|
1009
|
+
return typeName;
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Resolve an inline enum (string literal union) within an inline union member.
|
|
1013
|
+
*/
|
|
1014
|
+
function resolveInlineEnumInMember(members, fieldName, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx, description) {
|
|
1015
|
+
const context = {
|
|
1016
|
+
kind: "objectField",
|
|
1017
|
+
parentTypeName,
|
|
1018
|
+
fieldPath: appendFieldPath({
|
|
1019
|
+
parentPath: [],
|
|
1020
|
+
fieldName,
|
|
1021
|
+
singularize: singularizeArrayFieldName,
|
|
1022
|
+
siblingFieldNames,
|
|
1023
|
+
}),
|
|
1024
|
+
};
|
|
1025
|
+
const typeName = generateAutoTypeName(context);
|
|
1026
|
+
const contextKey = getContextKey(context);
|
|
1027
|
+
if (ctx.generatedTypeNames.has(contextKey)) {
|
|
1028
|
+
return ctx.generatedTypeNames.get(contextKey);
|
|
1029
|
+
}
|
|
1030
|
+
const { enumValues, needsStringEnumMapping, diagnostics: enumDiagnostics, } = convertInlineEnumMembers({
|
|
1031
|
+
members,
|
|
1032
|
+
enumName: typeName,
|
|
1033
|
+
sourceLocation: ctx.sourceLocation,
|
|
1034
|
+
});
|
|
1035
|
+
ctx.diagnostics.push(...enumDiagnostics);
|
|
1036
|
+
ctx.types.push({
|
|
1037
|
+
name: typeName,
|
|
1038
|
+
kind: "Enum",
|
|
1039
|
+
fields: null,
|
|
1040
|
+
enumValues,
|
|
1041
|
+
unionMembers: null,
|
|
1042
|
+
needsStringEnumMapping,
|
|
1043
|
+
sourceLocation: ctx.sourceLocation,
|
|
1044
|
+
generatedFrom: buildGeneratedFromInfo(context),
|
|
1045
|
+
description,
|
|
1046
|
+
resolveTypeFieldPattern: null,
|
|
1047
|
+
});
|
|
1048
|
+
ctx.generatedTypeNames.set(contextKey, typeName);
|
|
1049
|
+
return typeName;
|
|
1050
|
+
}
|
|
1051
|
+
/**
|
|
1052
|
+
* Resolve an inline union of reference types within an inline union member.
|
|
1053
|
+
*/
|
|
1054
|
+
function resolveInlineUnionInMember(members, fieldName, singularizeArrayFieldName, parentTypeName, siblingFieldNames, ctx) {
|
|
1055
|
+
const context = {
|
|
1056
|
+
kind: "objectField",
|
|
1057
|
+
parentTypeName,
|
|
1058
|
+
fieldPath: appendFieldPath({
|
|
1059
|
+
parentPath: [],
|
|
1060
|
+
fieldName,
|
|
1061
|
+
singularize: singularizeArrayFieldName,
|
|
1062
|
+
siblingFieldNames,
|
|
1063
|
+
}),
|
|
1064
|
+
};
|
|
1065
|
+
const typeName = generateAutoTypeName(context);
|
|
1066
|
+
const contextKey = getContextKey(context);
|
|
1067
|
+
if (ctx.generatedTypeNames.has(contextKey)) {
|
|
1068
|
+
return ctx.generatedTypeNames.get(contextKey);
|
|
1069
|
+
}
|
|
1070
|
+
const memberNames = [];
|
|
1071
|
+
for (const member of members) {
|
|
1072
|
+
if (member.kind === "reference" && member.name) {
|
|
1073
|
+
if (ctx.knownTypeNames.has(member.name)) {
|
|
1074
|
+
memberNames.push(member.name);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
if (memberNames.length === 0) {
|
|
1079
|
+
const memberDescriptions = members
|
|
1080
|
+
.map((m) => m.name ?? "(anonymous)")
|
|
1081
|
+
.join(", ");
|
|
1082
|
+
ctx.diagnostics.push({
|
|
1083
|
+
code: "INLINE_UNION_UNRESOLVABLE_MEMBER",
|
|
1084
|
+
message: `Could not resolve any members of inline union '${typeName}' in '${parentTypeName}.${fieldName}'. None of the member types [${memberDescriptions}] are known schema types.`,
|
|
1085
|
+
severity: "error",
|
|
1086
|
+
location: ctx.sourceLocation,
|
|
1087
|
+
});
|
|
1088
|
+
return typeName;
|
|
1089
|
+
}
|
|
1090
|
+
ctx.types.push({
|
|
1091
|
+
name: typeName,
|
|
1092
|
+
kind: "Union",
|
|
1093
|
+
fields: null,
|
|
1094
|
+
enumValues: null,
|
|
1095
|
+
unionMembers: memberNames,
|
|
1096
|
+
needsStringEnumMapping: false,
|
|
1097
|
+
sourceLocation: ctx.sourceLocation,
|
|
1098
|
+
generatedFrom: buildGeneratedFromInfo(context),
|
|
1099
|
+
description: null,
|
|
1100
|
+
resolveTypeFieldPattern: null,
|
|
1101
|
+
});
|
|
1102
|
+
ctx.generatedTypeNames.set(contextKey, typeName);
|
|
1103
|
+
return typeName;
|
|
1104
|
+
}
|
|
816
1105
|
function resolveMemberNames(params) {
|
|
817
1106
|
const { members, generatedTypeNames, parentContext, types, generatedTypenameTypes, diagnostics, sourceLocation, } = params;
|
|
818
1107
|
const memberNames = [];
|
|
@@ -840,31 +1129,39 @@ function resolveMemberNames(params) {
|
|
|
840
1129
|
};
|
|
841
1130
|
contextKey = getContextKey(nestedContext);
|
|
842
1131
|
}
|
|
843
|
-
else {
|
|
1132
|
+
else if (memberType.inlineObjectHintName !== null) {
|
|
844
1133
|
const nestedContext = {
|
|
845
1134
|
...parentContext,
|
|
846
|
-
fieldPath: [
|
|
1135
|
+
fieldPath: [
|
|
1136
|
+
...parentContext.fieldPath,
|
|
1137
|
+
memberType.inlineObjectHintName,
|
|
1138
|
+
],
|
|
847
1139
|
};
|
|
848
|
-
memberTypeName =
|
|
1140
|
+
memberTypeName = memberType.inlineObjectHintName;
|
|
849
1141
|
contextKey = getContextKey(nestedContext);
|
|
850
1142
|
}
|
|
1143
|
+
else {
|
|
1144
|
+
diagnostics.push({
|
|
1145
|
+
code: "UNNAMEABLE_UNION_MEMBER",
|
|
1146
|
+
message: `Inline object union member at index ${i} cannot be named. Use a named type (type alias or interface) for each union member, or add a '__typename' property with a string literal type.`,
|
|
1147
|
+
severity: "error",
|
|
1148
|
+
location: sourceLocation,
|
|
1149
|
+
});
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
851
1152
|
// Only filter out __typename or $typeName for resolverPayload context
|
|
852
1153
|
// For other contexts, these are regular fields that should be preserved
|
|
853
1154
|
const typenameFieldToFilter = extractedInfo?.fieldName ?? null;
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
directives: prop.directives,
|
|
865
|
-
defaultValue: prop.defaultValue,
|
|
866
|
-
};
|
|
867
|
-
});
|
|
1155
|
+
const filteredProperties = memberType.inlineObjectProperties.filter((prop) => parentContext.kind !== "resolverPayload" ||
|
|
1156
|
+
prop.name !== typenameFieldToFilter);
|
|
1157
|
+
const fieldCtx = {
|
|
1158
|
+
types,
|
|
1159
|
+
generatedTypeNames,
|
|
1160
|
+
diagnostics,
|
|
1161
|
+
sourceLocation,
|
|
1162
|
+
knownTypeNames: params.knownTypeNames,
|
|
1163
|
+
};
|
|
1164
|
+
const fields = convertMemberPropertiesToFields(filteredProperties, memberTypeName, fieldCtx);
|
|
868
1165
|
// Check if this typename was already seen with a different field structure
|
|
869
1166
|
if (extractedInfo !== null) {
|
|
870
1167
|
const existingFields = generatedTypenameTypes.get(extractedInfo.typeName);
|
|
@@ -889,7 +1186,7 @@ function resolveMemberNames(params) {
|
|
|
889
1186
|
...parentContext,
|
|
890
1187
|
fieldPath: [
|
|
891
1188
|
...parentContext.fieldPath,
|
|
892
|
-
extractedInfo?.typeName ??
|
|
1189
|
+
extractedInfo?.typeName ?? memberType.inlineObjectHintName,
|
|
893
1190
|
],
|
|
894
1191
|
};
|
|
895
1192
|
types.push({
|
|
@@ -996,11 +1293,19 @@ export function generateAutoTypes(input) {
|
|
|
996
1293
|
resolversResult: input.resolversResult,
|
|
997
1294
|
knownTypeNames: input.knownTypeNames,
|
|
998
1295
|
});
|
|
999
|
-
const
|
|
1296
|
+
const allInlineUnionsRaw = [
|
|
1000
1297
|
...inlineUnionsFromTypes,
|
|
1001
1298
|
...inlineUnionsFromResolvers,
|
|
1002
1299
|
...inlineUnionsFromPayloads,
|
|
1003
1300
|
];
|
|
1301
|
+
// Apply discriminator-aware flattening to inline unions before processing.
|
|
1302
|
+
// This resolves the case where TypeScript distributes intersections over unions
|
|
1303
|
+
// within field types, creating many anonymous inline objects.
|
|
1304
|
+
const flattenResult = flattenInlineUnionMembers({
|
|
1305
|
+
inlineUnions: allInlineUnionsRaw,
|
|
1306
|
+
discriminatorFields: input.discriminatorFields,
|
|
1307
|
+
});
|
|
1308
|
+
const allInlineUnions = [...flattenResult.inlineUnions];
|
|
1004
1309
|
// Build union type names map before generating auto types
|
|
1005
1310
|
const unionTypeNames = buildUnionTypeNamesMap(allInlineUnions);
|
|
1006
1311
|
const autoGeneratedTypes = [];
|
|
@@ -1040,11 +1345,29 @@ export function generateAutoTypes(input) {
|
|
|
1040
1345
|
};
|
|
1041
1346
|
const updatedExtractedTypes = updateExtractedTypes(input.extractedTypes, updateParams);
|
|
1042
1347
|
const updatedResolversResult = updateResolversResult(input.resolversResult, updateParams);
|
|
1348
|
+
// Build mapping from TS type alias names to auto-generated GraphQL union names
|
|
1349
|
+
const tsAliasToGraphQLNameMap = buildTsAliasToGraphQLNameMap(allInlineUnions, unionTypeNames);
|
|
1043
1350
|
return {
|
|
1044
1351
|
autoGeneratedTypes,
|
|
1045
1352
|
updatedExtractedTypes,
|
|
1046
1353
|
updatedResolversResult,
|
|
1047
1354
|
diagnostics,
|
|
1355
|
+
tsAliasToGraphQLNameMap,
|
|
1356
|
+
inlineDiscriminatorResolveTypes: flattenResult.inlineDiscriminatorResolveTypes,
|
|
1048
1357
|
};
|
|
1049
1358
|
}
|
|
1359
|
+
function buildTsAliasToGraphQLNameMap(inlineUnions, unionTypeNames) {
|
|
1360
|
+
const result = new Map();
|
|
1361
|
+
for (const inlineUnion of inlineUnions) {
|
|
1362
|
+
if (inlineUnion.unionAliasName === null) {
|
|
1363
|
+
continue;
|
|
1364
|
+
}
|
|
1365
|
+
const contextKey = getContextKey(inlineUnion.context);
|
|
1366
|
+
const generatedName = unionTypeNames.get(contextKey);
|
|
1367
|
+
if (generatedName !== undefined) {
|
|
1368
|
+
result.set(inlineUnion.unionAliasName, generatedName);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
return result;
|
|
1372
|
+
}
|
|
1050
1373
|
//# sourceMappingURL=auto-type-generator.js.map
|