@gqlkit-ts/cli 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auto-type-generator/auto-type-generator.d.ts +10 -4
- package/dist/auto-type-generator/auto-type-generator.d.ts.map +1 -1
- package/dist/auto-type-generator/auto-type-generator.js +640 -133
- package/dist/auto-type-generator/auto-type-generator.js.map +1 -1
- package/dist/auto-type-generator/index.d.ts +8 -1
- package/dist/auto-type-generator/index.d.ts.map +1 -1
- package/dist/auto-type-generator/index.js +3 -0
- package/dist/auto-type-generator/index.js.map +1 -1
- package/dist/auto-type-generator/inline-enum-collector.d.ts +13 -5
- package/dist/auto-type-generator/inline-enum-collector.d.ts.map +1 -1
- package/dist/auto-type-generator/inline-enum-collector.js +107 -71
- package/dist/auto-type-generator/inline-enum-collector.js.map +1 -1
- package/dist/auto-type-generator/inline-object-traverser.d.ts +20 -0
- package/dist/auto-type-generator/inline-object-traverser.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-object-traverser.js +22 -0
- package/dist/auto-type-generator/inline-object-traverser.js.map +1 -0
- package/dist/auto-type-generator/inline-union-collector.d.ts +29 -0
- package/dist/auto-type-generator/inline-union-collector.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-collector.js +216 -0
- package/dist/auto-type-generator/inline-union-collector.js.map +1 -0
- package/dist/auto-type-generator/inline-union-types.d.ts +29 -0
- package/dist/auto-type-generator/inline-union-types.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-types.js +2 -0
- package/dist/auto-type-generator/inline-union-types.js.map +1 -0
- package/dist/auto-type-generator/inline-union-validator.d.ts +76 -0
- package/dist/auto-type-generator/inline-union-validator.d.ts.map +1 -0
- package/dist/auto-type-generator/inline-union-validator.js +329 -0
- package/dist/auto-type-generator/inline-union-validator.js.map +1 -0
- package/dist/auto-type-generator/naming-convention.d.ts +18 -1
- package/dist/auto-type-generator/naming-convention.d.ts.map +1 -1
- package/dist/auto-type-generator/naming-convention.js +16 -0
- package/dist/auto-type-generator/naming-convention.js.map +1 -1
- package/dist/auto-type-generator/resolve-type-generator.d.ts +20 -0
- package/dist/auto-type-generator/resolve-type-generator.d.ts.map +1 -0
- package/dist/auto-type-generator/resolve-type-generator.js +2 -0
- package/dist/auto-type-generator/resolve-type-generator.js.map +1 -0
- package/dist/auto-type-generator/resolver-field-iterator.d.ts +13 -0
- package/dist/auto-type-generator/resolver-field-iterator.d.ts.map +1 -0
- package/dist/auto-type-generator/resolver-field-iterator.js +22 -0
- package/dist/auto-type-generator/resolver-field-iterator.js.map +1 -0
- package/dist/auto-type-generator/typename-extractor.d.ts +26 -0
- package/dist/auto-type-generator/typename-extractor.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-extractor.js +142 -0
- package/dist/auto-type-generator/typename-extractor.js.map +1 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts +35 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.js +177 -0
- package/dist/auto-type-generator/typename-resolve-type-generator.js.map +1 -0
- package/dist/auto-type-generator/typename-types.d.ts +43 -0
- package/dist/auto-type-generator/typename-types.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-types.js +37 -0
- package/dist/auto-type-generator/typename-types.js.map +1 -0
- package/dist/auto-type-generator/typename-validator.d.ts +37 -0
- package/dist/auto-type-generator/typename-validator.d.ts.map +1 -0
- package/dist/auto-type-generator/typename-validator.js +206 -0
- package/dist/auto-type-generator/typename-validator.js.map +1 -0
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/docs.d.ts +51 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +154 -0
- package/dist/commands/docs.js.map +1 -0
- package/dist/gen-orchestrator/orchestrator.d.ts.map +1 -1
- package/dist/gen-orchestrator/orchestrator.js +13 -6
- package/dist/gen-orchestrator/orchestrator.js.map +1 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts +19 -1
- package/dist/resolver-extractor/extract-resolvers.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts +5 -0
- package/dist/resolver-extractor/extractor/define-api-extractor.d.ts.map +1 -1
- package/dist/resolver-extractor/extractor/define-api-extractor.js +14 -61
- package/dist/resolver-extractor/extractor/define-api-extractor.js.map +1 -1
- package/dist/resolver-extractor/index.d.ts +0 -1
- package/dist/resolver-extractor/index.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts +1 -0
- package/dist/resolver-extractor/validator/abstract-resolver-validator.d.ts.map +1 -1
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js +9 -5
- package/dist/resolver-extractor/validator/abstract-resolver-validator.js.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.d.ts.map +1 -1
- package/dist/schema-generator/emitter/code-emitter.js +20 -0
- package/dist/schema-generator/emitter/code-emitter.js.map +1 -1
- package/dist/schema-generator/generate-schema.d.ts +1 -0
- package/dist/schema-generator/generate-schema.d.ts.map +1 -1
- package/dist/schema-generator/generate-schema.js +72 -3
- package/dist/schema-generator/generate-schema.js.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.d.ts +14 -2
- package/dist/schema-generator/integrator/result-integrator.d.ts.map +1 -1
- package/dist/schema-generator/integrator/result-integrator.js +54 -1
- package/dist/schema-generator/integrator/result-integrator.js.map +1 -1
- package/dist/schema-generator/resolver-collector/resolver-collector.d.ts +2 -0
- package/dist/schema-generator/resolver-collector/resolver-collector.d.ts.map +1 -1
- package/dist/schema-generator/resolver-collector/resolver-collector.js +22 -0
- package/dist/schema-generator/resolver-collector/resolver-collector.js.map +1 -1
- package/dist/shared/enum-prefix-detector.d.ts +63 -0
- package/dist/shared/enum-prefix-detector.d.ts.map +1 -0
- package/dist/shared/enum-prefix-detector.js +80 -0
- package/dist/shared/enum-prefix-detector.js.map +1 -0
- package/dist/shared/ignore-fields-detector.d.ts +26 -0
- package/dist/shared/ignore-fields-detector.d.ts.map +1 -0
- package/dist/shared/ignore-fields-detector.js +83 -0
- package/dist/shared/ignore-fields-detector.js.map +1 -0
- package/dist/shared/ignore-fields-validator.d.ts +29 -0
- package/dist/shared/ignore-fields-validator.d.ts.map +1 -0
- package/dist/shared/ignore-fields-validator.js +43 -0
- package/dist/shared/ignore-fields-validator.js.map +1 -0
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/source-location.d.ts +5 -0
- package/dist/shared/source-location.d.ts.map +1 -1
- package/dist/shared/source-location.js +7 -0
- package/dist/shared/source-location.js.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.d.ts.map +1 -1
- package/dist/type-extractor/converter/graphql-converter.js +21 -7
- package/dist/type-extractor/converter/graphql-converter.js.map +1 -1
- package/dist/type-extractor/extractor/field-type-resolver.js +42 -3
- package/dist/type-extractor/extractor/field-type-resolver.js.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.d.ts.map +1 -1
- package/dist/type-extractor/extractor/type-extractor.js +88 -23
- package/dist/type-extractor/extractor/type-extractor.js.map +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts +1 -1
- package/dist/type-extractor/types/diagnostics.d.ts.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts +10 -2
- package/dist/type-extractor/types/ts-type-reference-factory.d.ts.map +1 -1
- package/dist/type-extractor/types/ts-type-reference-factory.js +8 -2
- package/dist/type-extractor/types/ts-type-reference-factory.js.map +1 -1
- package/dist/type-extractor/types/typescript.d.ts +4 -0
- package/dist/type-extractor/types/typescript.d.ts.map +1 -1
- package/docs/coding-agents.md +64 -0
- package/docs/configuration.md +6 -20
- package/docs/getting-started.md +15 -12
- package/docs/index.md +36 -22
- package/docs/integration/apollo.md +8 -40
- package/docs/integration/drizzle.md +6 -10
- package/docs/integration/prisma.md +196 -0
- package/docs/integration/yoga.md +8 -40
- package/docs/schema/abstract-resolvers.md +117 -0
- package/docs/schema/directives.md +5 -0
- package/docs/schema/documentation.md +5 -0
- package/docs/schema/enums.md +99 -0
- package/docs/schema/fields.md +64 -0
- package/docs/schema/index.md +21 -0
- package/docs/schema/inputs.md +115 -15
- package/docs/schema/interfaces.md +31 -1
- package/docs/schema/objects.md +40 -0
- package/docs/schema/queries-mutations.md +136 -22
- package/docs/schema/scalars.md +5 -0
- package/docs/schema/unions.md +208 -1
- package/docs/what-is-gqlkit.md +13 -8
- package/package.json +6 -4
- package/src/auto-type-generator/auto-type-generator.ts +946 -201
- package/src/auto-type-generator/index.ts +42 -0
- package/src/auto-type-generator/inline-enum-collector.ts +187 -139
- package/src/auto-type-generator/inline-object-traverser.ts +49 -0
- package/src/auto-type-generator/inline-union-collector.ts +402 -0
- package/src/auto-type-generator/inline-union-types.ts +33 -0
- package/src/auto-type-generator/inline-union-validator.ts +482 -0
- package/src/auto-type-generator/naming-convention.ts +38 -1
- package/src/auto-type-generator/resolve-type-generator.ts +21 -0
- package/src/auto-type-generator/resolver-field-iterator.ts +39 -0
- package/src/auto-type-generator/typename-extractor.ts +230 -0
- package/src/auto-type-generator/typename-resolve-type-generator.ts +281 -0
- package/src/auto-type-generator/typename-types.ts +66 -0
- package/src/auto-type-generator/typename-validator.ts +326 -0
- package/src/cli.ts +2 -0
- package/src/commands/docs.ts +211 -0
- package/src/gen-orchestrator/orchestrator.ts +20 -6
- package/src/resolver-extractor/extract-resolvers.ts +19 -0
- package/src/resolver-extractor/extractor/define-api-extractor.ts +23 -89
- package/src/resolver-extractor/index.ts +0 -6
- package/src/resolver-extractor/validator/abstract-resolver-validator.ts +16 -8
- package/src/schema-generator/emitter/code-emitter.ts +34 -0
- package/src/schema-generator/generate-schema.ts +99 -2
- package/src/schema-generator/integrator/result-integrator.ts +70 -1
- package/src/schema-generator/resolver-collector/resolver-collector.ts +34 -0
- package/src/shared/enum-prefix-detector.ts +99 -0
- package/src/shared/ignore-fields-detector.ts +109 -0
- package/src/shared/ignore-fields-validator.ts +66 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/source-location.ts +11 -0
- package/src/type-extractor/converter/graphql-converter.ts +31 -7
- package/src/type-extractor/extractor/field-type-resolver.ts +48 -3
- package/src/type-extractor/extractor/type-extractor.ts +103 -26
- package/src/type-extractor/types/diagnostics.ts +12 -2
- package/src/type-extractor/types/ts-type-reference-factory.ts +18 -5
- package/src/type-extractor/types/typescript.ts +4 -0
- package/dist/resolver-extractor/validator/only-validator.d.ts +0 -61
- package/dist/resolver-extractor/validator/only-validator.d.ts.map +0 -1
- package/dist/resolver-extractor/validator/only-validator.js +0 -76
- package/dist/resolver-extractor/validator/only-validator.js.map +0 -1
- package/src/resolver-extractor/validator/only-validator.ts +0 -158
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { getSourceLocationOrDefault } from "../shared/source-location.js";
|
|
2
|
+
import { traverseInlineObjectProperties } from "./inline-object-traverser.js";
|
|
3
|
+
import { buildFieldContext, isInputTypeName, } from "./naming-convention.js";
|
|
4
|
+
import { forEachResolverField, } from "./resolver-field-iterator.js";
|
|
5
|
+
function createMemberInfo(memberType, knownTypeNames) {
|
|
6
|
+
const isKnown = memberType.kind === "reference" &&
|
|
7
|
+
memberType.name !== null &&
|
|
8
|
+
knownTypeNames.has(memberType.name);
|
|
9
|
+
return {
|
|
10
|
+
memberType,
|
|
11
|
+
needsAutoGeneration: !isKnown,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Collect inline unions from ExtractedTypeInfo by traversing type fields.
|
|
16
|
+
*/
|
|
17
|
+
export function collectInlineUnionsFromTypes(params) {
|
|
18
|
+
const { extractedTypes, knownTypeNames } = params;
|
|
19
|
+
const results = [];
|
|
20
|
+
for (const typeInfo of extractedTypes) {
|
|
21
|
+
const isInput = isInputTypeName(typeInfo.metadata.name);
|
|
22
|
+
for (const field of typeInfo.fields) {
|
|
23
|
+
collectInlineUnionsFromField({
|
|
24
|
+
field,
|
|
25
|
+
parentTypeName: typeInfo.metadata.name,
|
|
26
|
+
parentPath: [],
|
|
27
|
+
isInput,
|
|
28
|
+
sourceFile: typeInfo.metadata.sourceFile,
|
|
29
|
+
knownTypeNames,
|
|
30
|
+
results,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
}
|
|
36
|
+
function collectInlineUnionsFromField(params) {
|
|
37
|
+
const { field, parentTypeName, parentPath, isInput, sourceFile, knownTypeNames, results, } = params;
|
|
38
|
+
const tsType = field.tsType;
|
|
39
|
+
const fieldPath = [...parentPath, field.name];
|
|
40
|
+
if (tsType.kind === "union" && tsType.members) {
|
|
41
|
+
const members = tsType.members.map((m) => createMemberInfo(m, knownTypeNames));
|
|
42
|
+
results.push({
|
|
43
|
+
members,
|
|
44
|
+
context: buildFieldContext(parentTypeName, fieldPath, isInput),
|
|
45
|
+
sourceLocation: getSourceLocationOrDefault(field.sourceLocation, sourceFile),
|
|
46
|
+
nullable: tsType.nullable,
|
|
47
|
+
isInputContext: isInput,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
if (tsType.kind === "array" &&
|
|
51
|
+
tsType.elementType?.kind === "union" &&
|
|
52
|
+
tsType.elementType.members) {
|
|
53
|
+
const members = tsType.elementType.members.map((m) => createMemberInfo(m, knownTypeNames));
|
|
54
|
+
results.push({
|
|
55
|
+
members,
|
|
56
|
+
context: buildFieldContext(parentTypeName, fieldPath, isInput),
|
|
57
|
+
sourceLocation: getSourceLocationOrDefault(field.sourceLocation, sourceFile),
|
|
58
|
+
nullable: tsType.elementType.nullable,
|
|
59
|
+
isInputContext: isInput,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (tsType.kind === "inlineObject" && tsType.inlineObjectProperties) {
|
|
63
|
+
traverseInlineObjectProperties({ properties: tsType.inlineObjectProperties, parentPath: fieldPath }, (prop, propPath) => {
|
|
64
|
+
const propTsType = prop.tsType;
|
|
65
|
+
if (propTsType.kind === "union" && propTsType.members) {
|
|
66
|
+
const members = propTsType.members.map((m) => createMemberInfo(m, knownTypeNames));
|
|
67
|
+
results.push({
|
|
68
|
+
members,
|
|
69
|
+
context: buildFieldContext(parentTypeName, propPath, isInput),
|
|
70
|
+
sourceLocation: getSourceLocationOrDefault(prop.sourceLocation, sourceFile),
|
|
71
|
+
nullable: propTsType.nullable,
|
|
72
|
+
isInputContext: isInput,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Collect inline unions from ExtractResolversResult by traversing resolver args.
|
|
80
|
+
*/
|
|
81
|
+
export function collectInlineUnionsFromResolvers(params) {
|
|
82
|
+
const { resolversResult, knownTypeNames } = params;
|
|
83
|
+
const results = [];
|
|
84
|
+
forEachResolverField(resolversResult, (info) => {
|
|
85
|
+
collectInlineUnionsFromResolverArgs({
|
|
86
|
+
...info,
|
|
87
|
+
knownTypeNames,
|
|
88
|
+
results,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return results;
|
|
92
|
+
}
|
|
93
|
+
function collectInlineUnionsFromResolverArgs(params) {
|
|
94
|
+
const { field, resolverType, parentTypeName, knownTypeNames, results } = params;
|
|
95
|
+
if (!field.args)
|
|
96
|
+
return;
|
|
97
|
+
for (const arg of field.args) {
|
|
98
|
+
if (arg.inlineUnionMembers) {
|
|
99
|
+
const members = arg.inlineUnionMembers.map((m) => createMemberInfo(m, knownTypeNames));
|
|
100
|
+
const context = {
|
|
101
|
+
kind: "resolverArg",
|
|
102
|
+
resolverType,
|
|
103
|
+
fieldName: field.name,
|
|
104
|
+
argName: arg.name,
|
|
105
|
+
parentTypeName,
|
|
106
|
+
fieldPath: [],
|
|
107
|
+
};
|
|
108
|
+
results.push({
|
|
109
|
+
members,
|
|
110
|
+
context,
|
|
111
|
+
sourceLocation: field.sourceLocation,
|
|
112
|
+
nullable: arg.type.nullable,
|
|
113
|
+
isInputContext: true,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
if (arg.inlineObjectProperties) {
|
|
117
|
+
collectInlineUnionsFromResolverProperties({
|
|
118
|
+
properties: arg.inlineObjectProperties,
|
|
119
|
+
resolverType,
|
|
120
|
+
fieldName: field.name,
|
|
121
|
+
parentTypeName,
|
|
122
|
+
parentPath: [],
|
|
123
|
+
sourceLocation: field.sourceLocation,
|
|
124
|
+
knownTypeNames,
|
|
125
|
+
contextKind: "resolverArg",
|
|
126
|
+
argName: arg.name,
|
|
127
|
+
results,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Unified function for collecting inline unions from nested object properties
|
|
134
|
+
* in both resolver args and payload return types.
|
|
135
|
+
*/
|
|
136
|
+
function collectInlineUnionsFromResolverProperties(params) {
|
|
137
|
+
const { properties, resolverType, fieldName, parentTypeName, parentPath, sourceLocation, knownTypeNames, results, } = params;
|
|
138
|
+
traverseInlineObjectProperties({ properties, parentPath }, (prop, propPath) => {
|
|
139
|
+
const tsType = prop.tsType;
|
|
140
|
+
if (tsType.kind === "union" && tsType.members) {
|
|
141
|
+
const members = tsType.members.map((m) => createMemberInfo(m, knownTypeNames));
|
|
142
|
+
const context = params.contextKind === "resolverArg"
|
|
143
|
+
? {
|
|
144
|
+
kind: "resolverArg",
|
|
145
|
+
resolverType,
|
|
146
|
+
fieldName,
|
|
147
|
+
argName: params.argName,
|
|
148
|
+
parentTypeName,
|
|
149
|
+
fieldPath: propPath,
|
|
150
|
+
}
|
|
151
|
+
: {
|
|
152
|
+
kind: "resolverPayload",
|
|
153
|
+
resolverType,
|
|
154
|
+
fieldName,
|
|
155
|
+
parentTypeName,
|
|
156
|
+
fieldPath: propPath,
|
|
157
|
+
};
|
|
158
|
+
results.push({
|
|
159
|
+
members,
|
|
160
|
+
context,
|
|
161
|
+
sourceLocation: prop.sourceLocation ?? sourceLocation,
|
|
162
|
+
nullable: tsType.nullable,
|
|
163
|
+
isInputContext: params.contextKind === "resolverArg",
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Collect inline unions from resolver return types (Payload types).
|
|
170
|
+
*/
|
|
171
|
+
export function collectInlineUnionsFromPayloads(params) {
|
|
172
|
+
const { resolversResult, knownTypeNames } = params;
|
|
173
|
+
const results = [];
|
|
174
|
+
forEachResolverField(resolversResult, (info) => {
|
|
175
|
+
collectInlineUnionsFromPayloadReturnType({
|
|
176
|
+
...info,
|
|
177
|
+
knownTypeNames,
|
|
178
|
+
results,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
return results;
|
|
182
|
+
}
|
|
183
|
+
function collectInlineUnionsFromPayloadReturnType(params) {
|
|
184
|
+
const { field, resolverType, parentTypeName, knownTypeNames, results } = params;
|
|
185
|
+
if (field.returnTypeInlineUnionMembers) {
|
|
186
|
+
const members = field.returnTypeInlineUnionMembers.map((m) => createMemberInfo(m, knownTypeNames));
|
|
187
|
+
const context = {
|
|
188
|
+
kind: "resolverPayload",
|
|
189
|
+
resolverType,
|
|
190
|
+
fieldName: field.name,
|
|
191
|
+
parentTypeName,
|
|
192
|
+
fieldPath: [],
|
|
193
|
+
};
|
|
194
|
+
results.push({
|
|
195
|
+
members,
|
|
196
|
+
context,
|
|
197
|
+
sourceLocation: field.sourceLocation,
|
|
198
|
+
nullable: field.type.nullable,
|
|
199
|
+
isInputContext: false,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
if (field.returnTypeInlineObjectProperties) {
|
|
203
|
+
collectInlineUnionsFromResolverProperties({
|
|
204
|
+
properties: field.returnTypeInlineObjectProperties,
|
|
205
|
+
resolverType,
|
|
206
|
+
fieldName: field.name,
|
|
207
|
+
parentTypeName,
|
|
208
|
+
parentPath: [],
|
|
209
|
+
sourceLocation: field.sourceLocation,
|
|
210
|
+
knownTypeNames,
|
|
211
|
+
contextKind: "resolverPayload",
|
|
212
|
+
results,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=inline-union-collector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-union-collector.js","sourceRoot":"","sources":["../../src/auto-type-generator/inline-union-collector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAQ1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAK9E,OAAO,EAEL,iBAAiB,EACjB,eAAe,GAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,oBAAoB,GAGrB,MAAM,8BAA8B,CAAC;AAOtC,SAAS,gBAAgB,CACvB,UAA2B,EAC3B,cAAmC;IAEnC,MAAM,OAAO,GACX,UAAU,CAAC,IAAI,KAAK,WAAW;QAC/B,UAAU,CAAC,IAAI,KAAK,IAAI;QACxB,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAEtC,OAAO;QACL,UAAU;QACV,mBAAmB,EAAE,CAAC,OAAO;KAC9B,CAAC;AACJ,CAAC;AAOD;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,MAA0C;IAE1C,MAAM,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;IAClD,MAAM,OAAO,GAA6B,EAAE,CAAC;IAE7C,KAAK,MAAM,QAAQ,IAAI,cAAc,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAExD,KAAK,MAAM,KAAK,IAAI,QAAQ,CAAC,MAAM,EAAE,CAAC;YACpC,4BAA4B,CAAC;gBAC3B,KAAK;gBACL,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI;gBACtC,UAAU,EAAE,EAAE;gBACd,OAAO;gBACP,UAAU,EAAE,QAAQ,CAAC,QAAQ,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,OAAO;SACR,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { SourceLocation, TSTypeReference } from "../type-extractor/types/index.js";
|
|
2
|
+
import type { AutoTypeNameContext } from "./naming-convention.js";
|
|
3
|
+
/**
|
|
4
|
+
* Information about a single member of an inline union type.
|
|
5
|
+
* Tracks the type reference and whether it needs auto-generation.
|
|
6
|
+
*/
|
|
7
|
+
export interface InlineUnionMemberInfo {
|
|
8
|
+
/** Member type reference (can be reference, inlineObject, etc.) */
|
|
9
|
+
readonly memberType: TSTypeReference;
|
|
10
|
+
/** True if this member needs to be auto-generated as a named type */
|
|
11
|
+
readonly needsAutoGeneration: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Inline union with context information for naming and generation.
|
|
15
|
+
* Used for both Union types (output context) and OneOf Input types (input context).
|
|
16
|
+
*/
|
|
17
|
+
export interface InlineUnionWithContext {
|
|
18
|
+
/** Union members with their type info and auto-generation requirements */
|
|
19
|
+
readonly members: ReadonlyArray<InlineUnionMemberInfo>;
|
|
20
|
+
/** Context for generating the auto type name */
|
|
21
|
+
readonly context: AutoTypeNameContext;
|
|
22
|
+
/** Source location for error reporting */
|
|
23
|
+
readonly sourceLocation: SourceLocation;
|
|
24
|
+
/** Whether this union type is nullable */
|
|
25
|
+
readonly nullable: boolean;
|
|
26
|
+
/** True if this union is in input context (should become @oneOf Input Object) */
|
|
27
|
+
readonly isInputContext: boolean;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=inline-union-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-union-types.d.ts","sourceRoot":"","sources":["../../src/auto-type-generator/inline-union-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC,mEAAmE;IACnE,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,qEAAqE;IACrE,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAC;CACvC;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,0EAA0E;IAC1E,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,qBAAqB,CAAC,CAAC;IACvD,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAC;IACtC,0CAA0C;IAC1C,QAAQ,CAAC,cAAc,EAAE,cAAc,CAAC;IACxC,0CAA0C;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,iFAAiF;IACjF,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-union-types.js","sourceRoot":"","sources":["../../src/auto-type-generator/inline-union-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Diagnostic, ExtractedTypeInfo, SourceLocation } from "../type-extractor/types/index.js";
|
|
2
|
+
import type { InlineUnionMemberInfo } from "./inline-union-types.js";
|
|
3
|
+
import { type TypenameFieldName } from "./typename-types.js";
|
|
4
|
+
export interface ValidateUnionResult {
|
|
5
|
+
readonly valid: boolean;
|
|
6
|
+
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
7
|
+
}
|
|
8
|
+
export interface ValidateUnionMembersParams {
|
|
9
|
+
readonly members: ReadonlyArray<InlineUnionMemberInfo>;
|
|
10
|
+
readonly typeName: string;
|
|
11
|
+
readonly sourceLocation: SourceLocation;
|
|
12
|
+
readonly typeMap: ReadonlyMap<string, ExtractedTypeInfo>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Validates that all union members are object types.
|
|
16
|
+
* GraphQL unions cannot contain primitives, enums, or scalars.
|
|
17
|
+
*
|
|
18
|
+
* Reports:
|
|
19
|
+
* - INLINE_UNION_PRIMITIVE_MEMBER for primitive types
|
|
20
|
+
* - INLINE_UNION_ENUM_MEMBER for enum types
|
|
21
|
+
* - INLINE_UNION_UNRESOLVABLE_MEMBER for unresolvable types
|
|
22
|
+
*/
|
|
23
|
+
export declare function validateUnionMembers(params: ValidateUnionMembersParams): ValidateUnionResult;
|
|
24
|
+
export interface ValidateOneOfMembersParams {
|
|
25
|
+
readonly members: ReadonlyArray<InlineUnionMemberInfo>;
|
|
26
|
+
readonly typeName: string;
|
|
27
|
+
readonly sourceLocation: SourceLocation;
|
|
28
|
+
readonly typeMap: ReadonlyMap<string, ExtractedTypeInfo>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Validates @oneOf input object constraints:
|
|
32
|
+
* - Each member must have exactly one property
|
|
33
|
+
* - Property names must be unique across all members
|
|
34
|
+
* - Field types must be scalar, enum, or input object
|
|
35
|
+
*
|
|
36
|
+
* Reports:
|
|
37
|
+
* - ONEOF_EMPTY_OBJECT for empty object members
|
|
38
|
+
* - ONEOF_MULTIPLE_PROPERTIES for members with multiple properties
|
|
39
|
+
* - ONEOF_DUPLICATE_PROPERTY for duplicate property names
|
|
40
|
+
* - ONEOF_INVALID_FIELD_TYPE for invalid field types
|
|
41
|
+
*/
|
|
42
|
+
export declare function validateOneOfMembers(params: ValidateOneOfMembersParams): ValidateUnionResult;
|
|
43
|
+
export interface ValidateUnionMemberTypenamesParams {
|
|
44
|
+
readonly members: ReadonlyArray<InlineUnionMemberInfo>;
|
|
45
|
+
readonly unionTypeName: string;
|
|
46
|
+
readonly sourceLocation: SourceLocation;
|
|
47
|
+
readonly typeMap: ReadonlyMap<string, ExtractedTypeInfo>;
|
|
48
|
+
}
|
|
49
|
+
export interface ValidatedTypenameInfo {
|
|
50
|
+
readonly typeName: string;
|
|
51
|
+
readonly fieldName: TypenameFieldName;
|
|
52
|
+
}
|
|
53
|
+
export interface ValidateUnionMemberTypenamesResult {
|
|
54
|
+
readonly valid: boolean;
|
|
55
|
+
readonly diagnostics: ReadonlyArray<Diagnostic>;
|
|
56
|
+
readonly memberTypenames: ReadonlyMap<number, ValidatedTypenameInfo>;
|
|
57
|
+
readonly allMembersHaveTypename: boolean;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Validates __typename or $typeName property on inline union members.
|
|
61
|
+
* Returns extracted typename values for valid members.
|
|
62
|
+
*
|
|
63
|
+
* Behavior:
|
|
64
|
+
* - For named types (needsAutoGeneration: false), extracts typename from typeMap
|
|
65
|
+
* - For inline types (needsAutoGeneration: true), validates and extracts typename
|
|
66
|
+
* - Only called for payload unions (context.kind === "resolverPayload")
|
|
67
|
+
* - __typename takes priority over $typeName if both are present
|
|
68
|
+
*
|
|
69
|
+
* Reports:
|
|
70
|
+
* - MISSING_TYPENAME_PROPERTY when neither __typename nor $typeName is present
|
|
71
|
+
* - INVALID_TYPENAME_TYPE when the property is not a string literal
|
|
72
|
+
* - OPTIONAL_TYPENAME_PROPERTY when the property is declared as optional
|
|
73
|
+
* - NULLABLE_TYPENAME_PROPERTY when the property is nullable
|
|
74
|
+
*/
|
|
75
|
+
export declare function validateUnionMemberTypenames(params: ValidateUnionMemberTypenamesParams): ValidateUnionMemberTypenamesResult;
|
|
76
|
+
//# sourceMappingURL=inline-union-validator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inline-union-validator.d.ts","sourceRoot":"","sources":["../../src/auto-type-generator/inline-union-validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EACjB,cAAc,EAEf,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAErE,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,EAAE,OAAO,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AAC;IACxB,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IAChD,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IACrE,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAC;CAC1C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,MAAM,EAAE,kCAAkC,GACzC,kCAAkC,CA2GpC"}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { isInputTypeName } from "./naming-convention.js";
|
|
2
|
+
import { findTypenameProperty, } from "./typename-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Validates that all union members are object types.
|
|
5
|
+
* GraphQL unions cannot contain primitives, enums, or scalars.
|
|
6
|
+
*
|
|
7
|
+
* Reports:
|
|
8
|
+
* - INLINE_UNION_PRIMITIVE_MEMBER for primitive types
|
|
9
|
+
* - INLINE_UNION_ENUM_MEMBER for enum types
|
|
10
|
+
* - INLINE_UNION_UNRESOLVABLE_MEMBER for unresolvable types
|
|
11
|
+
*/
|
|
12
|
+
export function validateUnionMembers(params) {
|
|
13
|
+
const { members, typeName, sourceLocation, typeMap } = params;
|
|
14
|
+
const diagnostics = [];
|
|
15
|
+
for (const member of members) {
|
|
16
|
+
const memberType = member.memberType;
|
|
17
|
+
const diagnostic = validateUnionMemberType({
|
|
18
|
+
memberType,
|
|
19
|
+
needsAutoGeneration: member.needsAutoGeneration,
|
|
20
|
+
typeName,
|
|
21
|
+
sourceLocation,
|
|
22
|
+
typeMap,
|
|
23
|
+
});
|
|
24
|
+
if (diagnostic) {
|
|
25
|
+
diagnostics.push(diagnostic);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
valid: diagnostics.length === 0,
|
|
30
|
+
diagnostics,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function validateUnionMemberType(params) {
|
|
34
|
+
const { memberType, needsAutoGeneration, typeName, sourceLocation, typeMap } = params;
|
|
35
|
+
if (memberType.kind === "primitive") {
|
|
36
|
+
return {
|
|
37
|
+
code: "INLINE_UNION_PRIMITIVE_MEMBER",
|
|
38
|
+
message: `Inline union '${typeName}' contains primitive type '${memberType.name}'. GraphQL unions can only contain object types.`,
|
|
39
|
+
severity: "error",
|
|
40
|
+
location: sourceLocation,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (memberType.kind === "inlineEnum") {
|
|
44
|
+
return {
|
|
45
|
+
code: "INLINE_UNION_ENUM_MEMBER",
|
|
46
|
+
message: `Inline union '${typeName}' contains an enum type. GraphQL unions can only contain object types.`,
|
|
47
|
+
severity: "error",
|
|
48
|
+
location: sourceLocation,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (memberType.kind === "literal") {
|
|
52
|
+
return {
|
|
53
|
+
code: "INLINE_UNION_ENUM_MEMBER",
|
|
54
|
+
message: `Inline union '${typeName}' contains a literal type '${memberType.name}'. GraphQL unions can only contain object types.`,
|
|
55
|
+
severity: "error",
|
|
56
|
+
location: sourceLocation,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (memberType.kind === "scalar") {
|
|
60
|
+
return {
|
|
61
|
+
code: "INLINE_UNION_UNRESOLVABLE_MEMBER",
|
|
62
|
+
message: `Inline union '${typeName}' contains scalar type '${memberType.scalarInfo?.scalarName ?? memberType.name}'. GraphQL unions can only contain object types.`,
|
|
63
|
+
severity: "error",
|
|
64
|
+
location: sourceLocation,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
if (memberType.kind === "reference" && memberType.name !== null) {
|
|
68
|
+
const referencedType = typeMap.get(memberType.name);
|
|
69
|
+
if (referencedType?.metadata.kind === "enum") {
|
|
70
|
+
return {
|
|
71
|
+
code: "INLINE_UNION_ENUM_MEMBER",
|
|
72
|
+
message: `Inline union '${typeName}' contains enum type '${memberType.name}'. GraphQL unions can only contain object types.`,
|
|
73
|
+
severity: "error",
|
|
74
|
+
location: sourceLocation,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!referencedType && needsAutoGeneration) {
|
|
78
|
+
return {
|
|
79
|
+
code: "INLINE_UNION_UNRESOLVABLE_MEMBER",
|
|
80
|
+
message: `Inline union '${typeName}' contains unresolvable type '${memberType.name}'. The type cannot be expanded as an object type.`,
|
|
81
|
+
severity: "error",
|
|
82
|
+
location: sourceLocation,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (memberType.kind === "inlineObject" ||
|
|
87
|
+
memberType.kind === "reference" ||
|
|
88
|
+
memberType.kind === "union") {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
code: "INLINE_UNION_UNRESOLVABLE_MEMBER",
|
|
93
|
+
message: `Inline union '${typeName}' contains a type that cannot be resolved as an object type.`,
|
|
94
|
+
severity: "error",
|
|
95
|
+
location: sourceLocation,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Validates @oneOf input object constraints:
|
|
100
|
+
* - Each member must have exactly one property
|
|
101
|
+
* - Property names must be unique across all members
|
|
102
|
+
* - Field types must be scalar, enum, or input object
|
|
103
|
+
*
|
|
104
|
+
* Reports:
|
|
105
|
+
* - ONEOF_EMPTY_OBJECT for empty object members
|
|
106
|
+
* - ONEOF_MULTIPLE_PROPERTIES for members with multiple properties
|
|
107
|
+
* - ONEOF_DUPLICATE_PROPERTY for duplicate property names
|
|
108
|
+
* - ONEOF_INVALID_FIELD_TYPE for invalid field types
|
|
109
|
+
*/
|
|
110
|
+
export function validateOneOfMembers(params) {
|
|
111
|
+
const { members, typeName, sourceLocation, typeMap } = params;
|
|
112
|
+
const diagnostics = [];
|
|
113
|
+
const seenPropertyNames = new Set();
|
|
114
|
+
for (let i = 0; i < members.length; i++) {
|
|
115
|
+
const member = members[i];
|
|
116
|
+
const memberType = member.memberType;
|
|
117
|
+
if (memberType.kind === "reference") {
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
if (memberType.kind !== "inlineObject" ||
|
|
121
|
+
!memberType.inlineObjectProperties) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const properties = memberType.inlineObjectProperties;
|
|
125
|
+
if (properties.length === 0) {
|
|
126
|
+
diagnostics.push({
|
|
127
|
+
code: "ONEOF_EMPTY_OBJECT",
|
|
128
|
+
message: `OneOf input '${typeName}' member at index ${i} is an empty object. Each member must have exactly one property.`,
|
|
129
|
+
severity: "error",
|
|
130
|
+
location: sourceLocation,
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (properties.length > 1) {
|
|
135
|
+
diagnostics.push({
|
|
136
|
+
code: "ONEOF_MULTIPLE_PROPERTIES",
|
|
137
|
+
message: `OneOf input '${typeName}' member at index ${i} has ${properties.length} properties. Each member must have exactly one property.`,
|
|
138
|
+
severity: "error",
|
|
139
|
+
location: sourceLocation,
|
|
140
|
+
});
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const prop = properties[0];
|
|
144
|
+
if (seenPropertyNames.has(prop.name)) {
|
|
145
|
+
diagnostics.push({
|
|
146
|
+
code: "ONEOF_DUPLICATE_PROPERTY",
|
|
147
|
+
message: `OneOf input '${typeName}' has duplicate property name '${prop.name}'.`,
|
|
148
|
+
severity: "error",
|
|
149
|
+
location: sourceLocation,
|
|
150
|
+
});
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
seenPropertyNames.add(prop.name);
|
|
154
|
+
const fieldTypeError = validateOneOfFieldType({
|
|
155
|
+
propertyName: prop.name,
|
|
156
|
+
propertyType: prop.tsType,
|
|
157
|
+
typeName,
|
|
158
|
+
sourceLocation,
|
|
159
|
+
typeMap,
|
|
160
|
+
});
|
|
161
|
+
if (fieldTypeError) {
|
|
162
|
+
diagnostics.push(fieldTypeError);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
valid: diagnostics.length === 0,
|
|
167
|
+
diagnostics,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function validateOneOfFieldType(params) {
|
|
171
|
+
const { propertyName, propertyType, typeName, sourceLocation, typeMap } = params;
|
|
172
|
+
if (propertyType.kind === "primitive" ||
|
|
173
|
+
propertyType.kind === "scalar" ||
|
|
174
|
+
propertyType.kind === "inlineEnum") {
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
if (propertyType.kind === "inlineObject") {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
if (propertyType.kind === "reference" && propertyType.name !== null) {
|
|
181
|
+
const referencedType = typeMap.get(propertyType.name);
|
|
182
|
+
if (!referencedType) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const isValidType = referencedType.metadata.kind === "enum" ||
|
|
186
|
+
isInputTypeName(referencedType.metadata.name);
|
|
187
|
+
if (isValidType) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
code: "ONEOF_INVALID_FIELD_TYPE",
|
|
192
|
+
message: `OneOf input '${typeName}' field '${propertyName}' has invalid type '${propertyType.name}'. Only scalar types, enum types, and Input Object types are allowed.`,
|
|
193
|
+
severity: "error",
|
|
194
|
+
location: sourceLocation,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Extract typename info from a named type by looking up its fields in the typeMap.
|
|
201
|
+
* Returns null if the type doesn't have a valid __typename or $typeName field.
|
|
202
|
+
*/
|
|
203
|
+
function extractTypenameFromNamedType(params) {
|
|
204
|
+
const { memberType, typeMap } = params;
|
|
205
|
+
if (memberType.kind !== "reference" || memberType.name === null) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
const referencedType = typeMap.get(memberType.name);
|
|
209
|
+
if (!referencedType) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
const found = findTypenameProperty(referencedType.fields, (f) => f.name);
|
|
213
|
+
if (!found) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const { property: field, fieldName } = found;
|
|
217
|
+
const { tsType } = field;
|
|
218
|
+
if (field.optional ||
|
|
219
|
+
tsType.nullable ||
|
|
220
|
+
tsType.kind !== "literal" ||
|
|
221
|
+
tsType.name === null) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
return { typeName: tsType.name, fieldName };
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Validates __typename or $typeName property on inline union members.
|
|
228
|
+
* Returns extracted typename values for valid members.
|
|
229
|
+
*
|
|
230
|
+
* Behavior:
|
|
231
|
+
* - For named types (needsAutoGeneration: false), extracts typename from typeMap
|
|
232
|
+
* - For inline types (needsAutoGeneration: true), validates and extracts typename
|
|
233
|
+
* - Only called for payload unions (context.kind === "resolverPayload")
|
|
234
|
+
* - __typename takes priority over $typeName if both are present
|
|
235
|
+
*
|
|
236
|
+
* Reports:
|
|
237
|
+
* - MISSING_TYPENAME_PROPERTY when neither __typename nor $typeName is present
|
|
238
|
+
* - INVALID_TYPENAME_TYPE when the property is not a string literal
|
|
239
|
+
* - OPTIONAL_TYPENAME_PROPERTY when the property is declared as optional
|
|
240
|
+
* - NULLABLE_TYPENAME_PROPERTY when the property is nullable
|
|
241
|
+
*/
|
|
242
|
+
export function validateUnionMemberTypenames(params) {
|
|
243
|
+
const { members, unionTypeName, sourceLocation, typeMap } = params;
|
|
244
|
+
const diagnostics = [];
|
|
245
|
+
const memberTypenames = new Map();
|
|
246
|
+
// Counters for determining allMembersHaveTypename
|
|
247
|
+
let inlineTypeCount = 0;
|
|
248
|
+
let inlineTypesWithTypename = 0;
|
|
249
|
+
let namedTypeCount = 0;
|
|
250
|
+
let namedTypesWithTypename = 0;
|
|
251
|
+
for (let i = 0; i < members.length; i++) {
|
|
252
|
+
const member = members[i];
|
|
253
|
+
const memberType = member.memberType;
|
|
254
|
+
if (!member.needsAutoGeneration) {
|
|
255
|
+
namedTypeCount++;
|
|
256
|
+
const typenameInfo = extractTypenameFromNamedType({
|
|
257
|
+
memberType,
|
|
258
|
+
typeMap,
|
|
259
|
+
});
|
|
260
|
+
if (typenameInfo) {
|
|
261
|
+
memberTypenames.set(i, typenameInfo);
|
|
262
|
+
namedTypesWithTypename++;
|
|
263
|
+
}
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (memberType.kind !== "inlineObject" ||
|
|
267
|
+
!memberType.inlineObjectProperties) {
|
|
268
|
+
continue;
|
|
269
|
+
}
|
|
270
|
+
inlineTypeCount++;
|
|
271
|
+
const found = findTypenameProperty(memberType.inlineObjectProperties, (prop) => prop.name);
|
|
272
|
+
if (!found) {
|
|
273
|
+
diagnostics.push({
|
|
274
|
+
code: "MISSING_TYPENAME_PROPERTY",
|
|
275
|
+
message: `Union '${unionTypeName}' member at index ${i} is missing '__typename' or '$typeName' property. Inline union members must have a '__typename' or '$typeName' property with a string literal type.`,
|
|
276
|
+
severity: "error",
|
|
277
|
+
location: sourceLocation,
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const { property: selectedProperty, fieldName: selectedFieldName } = found;
|
|
282
|
+
const typenameType = selectedProperty.tsType;
|
|
283
|
+
if (selectedProperty.optional) {
|
|
284
|
+
diagnostics.push({
|
|
285
|
+
code: "OPTIONAL_TYPENAME_PROPERTY",
|
|
286
|
+
message: `Union '${unionTypeName}' member at index ${i} has optional '${selectedFieldName}' property. The '${selectedFieldName}' property must be required for union type resolution.`,
|
|
287
|
+
severity: "error",
|
|
288
|
+
location: sourceLocation,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
if (typenameType.nullable) {
|
|
292
|
+
diagnostics.push({
|
|
293
|
+
code: "NULLABLE_TYPENAME_PROPERTY",
|
|
294
|
+
message: `Union '${unionTypeName}' member at index ${i} has nullable '${selectedFieldName}' property. The '${selectedFieldName}' property must not be nullable for union type resolution.`,
|
|
295
|
+
severity: "error",
|
|
296
|
+
location: sourceLocation,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (typenameType.kind !== "literal" || typenameType.name === null) {
|
|
300
|
+
diagnostics.push({
|
|
301
|
+
code: "INVALID_TYPENAME_TYPE",
|
|
302
|
+
message: `Union '${unionTypeName}' member at index ${i} has '${selectedFieldName}' that is not a string literal type. Expected a string literal like '${selectedFieldName}: "TypeName"'.`,
|
|
303
|
+
severity: "error",
|
|
304
|
+
location: sourceLocation,
|
|
305
|
+
});
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
if (!selectedProperty.optional && !typenameType.nullable) {
|
|
309
|
+
memberTypenames.set(i, {
|
|
310
|
+
typeName: typenameType.name,
|
|
311
|
+
fieldName: selectedFieldName,
|
|
312
|
+
});
|
|
313
|
+
inlineTypesWithTypename++;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Determine allMembersHaveTypename: all members (both inline and named) must have typename
|
|
317
|
+
// for resolveType to be auto-generated. This ensures the generated resolveType function
|
|
318
|
+
// can resolve all union members correctly at runtime.
|
|
319
|
+
const totalMemberCount = inlineTypeCount + namedTypeCount;
|
|
320
|
+
const totalMembersWithTypename = inlineTypesWithTypename + namedTypesWithTypename;
|
|
321
|
+
const allMembersHaveTypename = totalMemberCount > 0 && totalMembersWithTypename === totalMemberCount;
|
|
322
|
+
return {
|
|
323
|
+
valid: diagnostics.length === 0,
|
|
324
|
+
diagnostics,
|
|
325
|
+
memberTypenames,
|
|
326
|
+
allMembersHaveTypename,
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=inline-union-validator.js.map
|