@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
|
@@ -73,7 +73,6 @@ export type DiagnosticCode =
|
|
|
73
73
|
| "MODULE_RESOLUTION_ERROR"
|
|
74
74
|
| "SKIPPED_FIELD"
|
|
75
75
|
| "SKIPPED_ENUM_VALUE"
|
|
76
|
-
| "EMPTY_TYPE_PROPERTIES"
|
|
77
76
|
| "INDEX_SIGNATURE_ONLY"
|
|
78
77
|
| "UNKNOWN_ABSTRACT_TYPE"
|
|
79
78
|
| "INVALID_ABSTRACT_TYPE_KIND"
|
|
@@ -84,7 +83,18 @@ export type DiagnosticCode =
|
|
|
84
83
|
| "DUPLICATE_ENUM_VALUE"
|
|
85
84
|
| "DUPLICATE_ENUM_VALUE_AFTER_CONVERSION"
|
|
86
85
|
| "INVALID_ENUM_MEMBER_NAME"
|
|
87
|
-
| "AMBIGUOUS_SCALAR_BASE_TYPE"
|
|
86
|
+
| "AMBIGUOUS_SCALAR_BASE_TYPE"
|
|
87
|
+
| "INLINE_UNION_PRIMITIVE_MEMBER"
|
|
88
|
+
| "INLINE_UNION_ENUM_MEMBER"
|
|
89
|
+
| "INLINE_UNION_UNRESOLVABLE_MEMBER"
|
|
90
|
+
| "MISSING_TYPENAME_PROPERTY"
|
|
91
|
+
| "INVALID_TYPENAME_TYPE"
|
|
92
|
+
| "OPTIONAL_TYPENAME_PROPERTY"
|
|
93
|
+
| "NULLABLE_TYPENAME_PROPERTY"
|
|
94
|
+
| "TYPENAME_FIELD_STRUCTURE_MISMATCH"
|
|
95
|
+
| "DUPLICATE_TYPENAME_VALUE"
|
|
96
|
+
| "IGNORE_FIELD_NOT_FOUND"
|
|
97
|
+
| "IGNORE_ALL_FIELDS";
|
|
88
98
|
|
|
89
99
|
export interface Diagnostic {
|
|
90
100
|
readonly code: DiagnosticCode;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type ts from "typescript";
|
|
2
|
+
import type { DeprecationInfo } from "../../shared/tsdoc-parser.js";
|
|
2
3
|
import type {
|
|
3
4
|
InlineEnumMemberInfo,
|
|
4
5
|
InlineObjectPropertyDef,
|
|
@@ -22,6 +23,8 @@ function createTSTypeReference(
|
|
|
22
23
|
nullable: false,
|
|
23
24
|
scalarInfo: null,
|
|
24
25
|
inlineObjectProperties: null,
|
|
26
|
+
inlineObjectDescription: null,
|
|
27
|
+
inlineObjectDeprecated: null,
|
|
25
28
|
inlineEnumMembers: null,
|
|
26
29
|
externalEnumSymbol: null,
|
|
27
30
|
externalEnumDescription: null,
|
|
@@ -76,12 +79,24 @@ export function createUnionType(
|
|
|
76
79
|
});
|
|
77
80
|
}
|
|
78
81
|
|
|
82
|
+
interface CreateInlineObjectTypeParams {
|
|
83
|
+
readonly properties: ReadonlyArray<InlineObjectPropertyDef>;
|
|
84
|
+
/** TSDoc description from the type alias (null for true inline objects) */
|
|
85
|
+
readonly description: string | null;
|
|
86
|
+
/** @deprecated tag from the type alias (null for true inline objects) */
|
|
87
|
+
readonly deprecated: DeprecationInfo | null;
|
|
88
|
+
}
|
|
89
|
+
|
|
79
90
|
export function createInlineObjectType(
|
|
80
|
-
|
|
91
|
+
params: CreateInlineObjectTypeParams,
|
|
81
92
|
): TSTypeReference {
|
|
82
93
|
return createTSTypeReference({
|
|
83
94
|
kind: "inlineObject",
|
|
84
|
-
overrides: {
|
|
95
|
+
overrides: {
|
|
96
|
+
inlineObjectProperties: params.properties,
|
|
97
|
+
inlineObjectDescription: params.description,
|
|
98
|
+
inlineObjectDeprecated: params.deprecated,
|
|
99
|
+
},
|
|
85
100
|
});
|
|
86
101
|
}
|
|
87
102
|
|
|
@@ -116,9 +131,7 @@ interface CreateInlineEnumTypeParams {
|
|
|
116
131
|
/** TSDoc description from the external enum type itself (null for string literal unions) */
|
|
117
132
|
readonly externalEnumDescription: string | null;
|
|
118
133
|
/** @deprecated tag from the external enum type itself (null for string literal unions) */
|
|
119
|
-
readonly externalEnumDeprecated:
|
|
120
|
-
| import("../../shared/tsdoc-parser.js").DeprecationInfo
|
|
121
|
-
| null;
|
|
134
|
+
readonly externalEnumDeprecated: DeprecationInfo | null;
|
|
122
135
|
}
|
|
123
136
|
|
|
124
137
|
export function createInlineEnumType(
|
|
@@ -70,6 +70,10 @@ export interface TSTypeReference {
|
|
|
70
70
|
readonly nullable: boolean;
|
|
71
71
|
readonly scalarInfo: ScalarTypeInfo | null;
|
|
72
72
|
readonly inlineObjectProperties: ReadonlyArray<InlineObjectPropertyDef> | null;
|
|
73
|
+
/** TSDoc description from the inline object type alias (Requirement 7.2) */
|
|
74
|
+
readonly inlineObjectDescription: string | null;
|
|
75
|
+
/** @deprecated tag from the inline object type alias (Requirement 7.3) */
|
|
76
|
+
readonly inlineObjectDeprecated: DeprecationInfo | null;
|
|
73
77
|
/** Inline enum members when kind is "inlineEnum" */
|
|
74
78
|
readonly inlineEnumMembers: ReadonlyArray<InlineEnumMemberInfo> | null;
|
|
75
79
|
/** External TypeScript enum symbol for deduplication (Requirement 5.2) */
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OnlyValidator validates that scalar types with only constraints
|
|
3
|
-
* are used in the correct position (input or output).
|
|
4
|
-
*
|
|
5
|
-
* - Scalars with only: "output" can only be used in output positions
|
|
6
|
-
* - Scalars with only: "input" can only be used in input positions
|
|
7
|
-
* - Scalars without only constraint can be used in both positions
|
|
8
|
-
*/
|
|
9
|
-
import type { TSTypeReference } from "../../type-extractor/types/index.js";
|
|
10
|
-
export type OnlyConstraintViolationCode = "OUTPUT_ONLY_IN_INPUT_POSITION" | "INPUT_ONLY_IN_OUTPUT_POSITION";
|
|
11
|
-
export interface OnlyConstraintViolation {
|
|
12
|
-
readonly code: OnlyConstraintViolationCode;
|
|
13
|
-
readonly message: string;
|
|
14
|
-
readonly scalarName: string;
|
|
15
|
-
readonly only: "input" | "output";
|
|
16
|
-
readonly position: "input" | "output";
|
|
17
|
-
readonly context: ValidationContext;
|
|
18
|
-
}
|
|
19
|
-
interface InputTypeFieldContext {
|
|
20
|
-
readonly kind: "inputTypeField";
|
|
21
|
-
readonly typeName: string;
|
|
22
|
-
readonly fieldName: string;
|
|
23
|
-
readonly sourceFile: string;
|
|
24
|
-
readonly line: number;
|
|
25
|
-
}
|
|
26
|
-
interface ObjectTypeFieldContext {
|
|
27
|
-
readonly kind: "objectTypeField";
|
|
28
|
-
readonly typeName: string;
|
|
29
|
-
readonly fieldName: string;
|
|
30
|
-
readonly sourceFile: string;
|
|
31
|
-
readonly line: number;
|
|
32
|
-
}
|
|
33
|
-
interface ResolverArgumentContext {
|
|
34
|
-
readonly kind: "resolverArgument";
|
|
35
|
-
readonly resolverName: string;
|
|
36
|
-
readonly argumentName: string;
|
|
37
|
-
readonly sourceFile: string;
|
|
38
|
-
readonly line: number;
|
|
39
|
-
}
|
|
40
|
-
interface ResolverReturnTypeContext {
|
|
41
|
-
readonly kind: "resolverReturnType";
|
|
42
|
-
readonly resolverName: string;
|
|
43
|
-
readonly sourceFile: string;
|
|
44
|
-
readonly line: number;
|
|
45
|
-
}
|
|
46
|
-
export type ValidationContext = InputTypeFieldContext | ObjectTypeFieldContext | ResolverArgumentContext | ResolverReturnTypeContext;
|
|
47
|
-
export interface ValidateOnlyConstraintsOptions {
|
|
48
|
-
readonly typeRef: TSTypeReference;
|
|
49
|
-
readonly position: "input" | "output";
|
|
50
|
-
readonly context: ValidationContext;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Validates that only constraints are not violated.
|
|
54
|
-
* Returns diagnostics for each violation.
|
|
55
|
-
*
|
|
56
|
-
* @param options - Validation options including type reference, position, and context
|
|
57
|
-
* @returns Array of constraint violations (empty if no violations)
|
|
58
|
-
*/
|
|
59
|
-
export declare function validateOnlyConstraints(options: ValidateOnlyConstraintsOptions): ReadonlyArray<OnlyConstraintViolation>;
|
|
60
|
-
export {};
|
|
61
|
-
//# sourceMappingURL=only-validator.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"only-validator.d.ts","sourceRoot":"","sources":["../../../src/resolver-extractor/validator/only-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAE3E,MAAM,MAAM,2BAA2B,GACnC,+BAA+B,GAC/B,+BAA+B,CAAC;AAEpC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,IAAI,EAAE,2BAA2B,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AAED,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAC;IAChC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,uBAAuB;IAC/B,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC;IAClC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,UAAU,yBAAyB;IACjC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;IACpC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,iBAAiB,GACzB,qBAAqB,GACrB,sBAAsB,GACtB,uBAAuB,GACvB,yBAAyB,CAAC;AAE9B,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,OAAO,EAAE,eAAe,CAAC;IAClC,QAAQ,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC;IACtC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAC;CACrC;AA0ED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,aAAa,CAAC,uBAAuB,CAAC,CASxC"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OnlyValidator validates that scalar types with only constraints
|
|
3
|
-
* are used in the correct position (input or output).
|
|
4
|
-
*
|
|
5
|
-
* - Scalars with only: "output" can only be used in output positions
|
|
6
|
-
* - Scalars with only: "input" can only be used in input positions
|
|
7
|
-
* - Scalars without only constraint can be used in both positions
|
|
8
|
-
*/
|
|
9
|
-
function formatContextLocation(context) {
|
|
10
|
-
switch (context.kind) {
|
|
11
|
-
case "inputTypeField":
|
|
12
|
-
return `field '${context.fieldName}' of input type '${context.typeName}'`;
|
|
13
|
-
case "objectTypeField":
|
|
14
|
-
return `field '${context.fieldName}' of type '${context.typeName}'`;
|
|
15
|
-
case "resolverArgument":
|
|
16
|
-
return `argument '${context.argumentName}' of resolver '${context.resolverName}'`;
|
|
17
|
-
case "resolverReturnType":
|
|
18
|
-
return `return type of resolver '${context.resolverName}'`;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
function createViolationMessage(scalarName, only, position, context) {
|
|
22
|
-
const locationDesc = formatContextLocation(context);
|
|
23
|
-
const oppositePosition = only === "output" ? "input" : "output";
|
|
24
|
-
const hint = position === "input"
|
|
25
|
-
? "Use a type without 'only' constraint or with 'only: \"input\"' instead."
|
|
26
|
-
: "Use a type without 'only' constraint or with 'only: \"output\"' instead.";
|
|
27
|
-
return `Scalar type '${scalarName}' is ${only}-only but is used in ${position} position (${locationDesc}). ${oppositePosition.charAt(0).toUpperCase() + oppositePosition.slice(1)}-only scalars cannot be used in ${position} positions. ${hint}`;
|
|
28
|
-
}
|
|
29
|
-
function collectScalarViolations(typeRef, position, context, violations) {
|
|
30
|
-
if (typeRef.scalarInfo) {
|
|
31
|
-
const { scalarName, only } = typeRef.scalarInfo;
|
|
32
|
-
if (only !== null) {
|
|
33
|
-
if (position === "input" && only === "output") {
|
|
34
|
-
violations.push({
|
|
35
|
-
code: "OUTPUT_ONLY_IN_INPUT_POSITION",
|
|
36
|
-
message: createViolationMessage(scalarName, only, position, context),
|
|
37
|
-
scalarName,
|
|
38
|
-
only,
|
|
39
|
-
position,
|
|
40
|
-
context,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
else if (position === "output" && only === "input") {
|
|
44
|
-
violations.push({
|
|
45
|
-
code: "INPUT_ONLY_IN_OUTPUT_POSITION",
|
|
46
|
-
message: createViolationMessage(scalarName, only, position, context),
|
|
47
|
-
scalarName,
|
|
48
|
-
only,
|
|
49
|
-
position,
|
|
50
|
-
context,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
if (typeRef.elementType) {
|
|
56
|
-
collectScalarViolations(typeRef.elementType, position, context, violations);
|
|
57
|
-
}
|
|
58
|
-
if (typeRef.members) {
|
|
59
|
-
for (const member of typeRef.members) {
|
|
60
|
-
collectScalarViolations(member, position, context, violations);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Validates that only constraints are not violated.
|
|
66
|
-
* Returns diagnostics for each violation.
|
|
67
|
-
*
|
|
68
|
-
* @param options - Validation options including type reference, position, and context
|
|
69
|
-
* @returns Array of constraint violations (empty if no violations)
|
|
70
|
-
*/
|
|
71
|
-
export function validateOnlyConstraints(options) {
|
|
72
|
-
const violations = [];
|
|
73
|
-
collectScalarViolations(options.typeRef, options.position, options.context, violations);
|
|
74
|
-
return violations;
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=only-validator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"only-validator.js","sourceRoot":"","sources":["../../../src/resolver-extractor/validator/only-validator.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* OnlyValidator validates that scalar types with only constraints
|
|
3
|
-
* are used in the correct position (input or output).
|
|
4
|
-
*
|
|
5
|
-
* - Scalars with only: "output" can only be used in output positions
|
|
6
|
-
* - Scalars with only: "input" can only be used in input positions
|
|
7
|
-
* - Scalars without only constraint can be used in both positions
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { TSTypeReference } from "../../type-extractor/types/index.js";
|
|
11
|
-
|
|
12
|
-
export type OnlyConstraintViolationCode =
|
|
13
|
-
| "OUTPUT_ONLY_IN_INPUT_POSITION"
|
|
14
|
-
| "INPUT_ONLY_IN_OUTPUT_POSITION";
|
|
15
|
-
|
|
16
|
-
export interface OnlyConstraintViolation {
|
|
17
|
-
readonly code: OnlyConstraintViolationCode;
|
|
18
|
-
readonly message: string;
|
|
19
|
-
readonly scalarName: string;
|
|
20
|
-
readonly only: "input" | "output";
|
|
21
|
-
readonly position: "input" | "output";
|
|
22
|
-
readonly context: ValidationContext;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface InputTypeFieldContext {
|
|
26
|
-
readonly kind: "inputTypeField";
|
|
27
|
-
readonly typeName: string;
|
|
28
|
-
readonly fieldName: string;
|
|
29
|
-
readonly sourceFile: string;
|
|
30
|
-
readonly line: number;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface ObjectTypeFieldContext {
|
|
34
|
-
readonly kind: "objectTypeField";
|
|
35
|
-
readonly typeName: string;
|
|
36
|
-
readonly fieldName: string;
|
|
37
|
-
readonly sourceFile: string;
|
|
38
|
-
readonly line: number;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
interface ResolverArgumentContext {
|
|
42
|
-
readonly kind: "resolverArgument";
|
|
43
|
-
readonly resolverName: string;
|
|
44
|
-
readonly argumentName: string;
|
|
45
|
-
readonly sourceFile: string;
|
|
46
|
-
readonly line: number;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
interface ResolverReturnTypeContext {
|
|
50
|
-
readonly kind: "resolverReturnType";
|
|
51
|
-
readonly resolverName: string;
|
|
52
|
-
readonly sourceFile: string;
|
|
53
|
-
readonly line: number;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type ValidationContext =
|
|
57
|
-
| InputTypeFieldContext
|
|
58
|
-
| ObjectTypeFieldContext
|
|
59
|
-
| ResolverArgumentContext
|
|
60
|
-
| ResolverReturnTypeContext;
|
|
61
|
-
|
|
62
|
-
export interface ValidateOnlyConstraintsOptions {
|
|
63
|
-
readonly typeRef: TSTypeReference;
|
|
64
|
-
readonly position: "input" | "output";
|
|
65
|
-
readonly context: ValidationContext;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function formatContextLocation(context: ValidationContext): string {
|
|
69
|
-
switch (context.kind) {
|
|
70
|
-
case "inputTypeField":
|
|
71
|
-
return `field '${context.fieldName}' of input type '${context.typeName}'`;
|
|
72
|
-
case "objectTypeField":
|
|
73
|
-
return `field '${context.fieldName}' of type '${context.typeName}'`;
|
|
74
|
-
case "resolverArgument":
|
|
75
|
-
return `argument '${context.argumentName}' of resolver '${context.resolverName}'`;
|
|
76
|
-
case "resolverReturnType":
|
|
77
|
-
return `return type of resolver '${context.resolverName}'`;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function createViolationMessage(
|
|
82
|
-
scalarName: string,
|
|
83
|
-
only: "input" | "output",
|
|
84
|
-
position: "input" | "output",
|
|
85
|
-
context: ValidationContext,
|
|
86
|
-
): string {
|
|
87
|
-
const locationDesc = formatContextLocation(context);
|
|
88
|
-
const oppositePosition = only === "output" ? "input" : "output";
|
|
89
|
-
const hint =
|
|
90
|
-
position === "input"
|
|
91
|
-
? "Use a type without 'only' constraint or with 'only: \"input\"' instead."
|
|
92
|
-
: "Use a type without 'only' constraint or with 'only: \"output\"' instead.";
|
|
93
|
-
|
|
94
|
-
return `Scalar type '${scalarName}' is ${only}-only but is used in ${position} position (${locationDesc}). ${oppositePosition.charAt(0).toUpperCase() + oppositePosition.slice(1)}-only scalars cannot be used in ${position} positions. ${hint}`;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function collectScalarViolations(
|
|
98
|
-
typeRef: TSTypeReference,
|
|
99
|
-
position: "input" | "output",
|
|
100
|
-
context: ValidationContext,
|
|
101
|
-
violations: OnlyConstraintViolation[],
|
|
102
|
-
): void {
|
|
103
|
-
if (typeRef.scalarInfo) {
|
|
104
|
-
const { scalarName, only } = typeRef.scalarInfo;
|
|
105
|
-
|
|
106
|
-
if (only !== null) {
|
|
107
|
-
if (position === "input" && only === "output") {
|
|
108
|
-
violations.push({
|
|
109
|
-
code: "OUTPUT_ONLY_IN_INPUT_POSITION",
|
|
110
|
-
message: createViolationMessage(scalarName, only, position, context),
|
|
111
|
-
scalarName,
|
|
112
|
-
only,
|
|
113
|
-
position,
|
|
114
|
-
context,
|
|
115
|
-
});
|
|
116
|
-
} else if (position === "output" && only === "input") {
|
|
117
|
-
violations.push({
|
|
118
|
-
code: "INPUT_ONLY_IN_OUTPUT_POSITION",
|
|
119
|
-
message: createViolationMessage(scalarName, only, position, context),
|
|
120
|
-
scalarName,
|
|
121
|
-
only,
|
|
122
|
-
position,
|
|
123
|
-
context,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (typeRef.elementType) {
|
|
130
|
-
collectScalarViolations(typeRef.elementType, position, context, violations);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (typeRef.members) {
|
|
134
|
-
for (const member of typeRef.members) {
|
|
135
|
-
collectScalarViolations(member, position, context, violations);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Validates that only constraints are not violated.
|
|
142
|
-
* Returns diagnostics for each violation.
|
|
143
|
-
*
|
|
144
|
-
* @param options - Validation options including type reference, position, and context
|
|
145
|
-
* @returns Array of constraint violations (empty if no violations)
|
|
146
|
-
*/
|
|
147
|
-
export function validateOnlyConstraints(
|
|
148
|
-
options: ValidateOnlyConstraintsOptions,
|
|
149
|
-
): ReadonlyArray<OnlyConstraintViolation> {
|
|
150
|
-
const violations: OnlyConstraintViolation[] = [];
|
|
151
|
-
collectScalarViolations(
|
|
152
|
-
options.typeRef,
|
|
153
|
-
options.position,
|
|
154
|
-
options.context,
|
|
155
|
-
violations,
|
|
156
|
-
);
|
|
157
|
-
return violations;
|
|
158
|
-
}
|