1 | import { ScalarsMap, ParsedScalarsMap, NamingConvention, ConvertFn, ConvertOptions, LoadedFragment, NormalizedScalarsMap, DeclarationKind } from './types';
|
2 | import { DeclarationBlockConfig } from './utils';
|
3 | import { ASTNode, FragmentDefinitionNode, OperationDefinitionNode } from 'graphql';
|
4 | import { ImportDeclaration, FragmentImport } from './imports';
|
5 | export interface BaseVisitorConvertOptions {
|
6 | useTypesPrefix?: boolean;
|
7 | useTypesSuffix?: boolean;
|
8 | }
|
9 | export declare type InlineFragmentTypeOptions = 'inline' | 'combine' | 'mask';
|
10 | export interface ParsedConfig {
|
11 | scalars: ParsedScalarsMap;
|
12 | convert: ConvertFn;
|
13 | typesPrefix: string;
|
14 | typesSuffix: string;
|
15 | addTypename: boolean;
|
16 | nonOptionalTypename: boolean;
|
17 | externalFragments: LoadedFragment[];
|
18 | fragmentImports: ImportDeclaration<FragmentImport>[];
|
19 | immutableTypes: boolean;
|
20 | useTypeImports: boolean;
|
21 | dedupeFragments: boolean;
|
22 | allowEnumStringTypes: boolean;
|
23 | inlineFragmentTypes: InlineFragmentTypeOptions;
|
24 | }
|
25 | export interface RawConfig {
|
26 | /**
|
27 | * @description Makes scalars strict.
|
28 | *
|
29 | * If scalars are found in the schema that are not defined in `scalars`
|
30 | * an error will be thrown during codegen.
|
31 | * @default false
|
32 | *
|
33 | * @exampleMarkdown
|
34 | * ```yaml
|
35 | * config:
|
36 | * strictScalars: true
|
37 | * ```
|
38 | */
|
39 | strictScalars?: boolean;
|
40 | /**
|
41 | * @description Allows you to override the type that unknown scalars will have.
|
42 | * @default any
|
43 | *
|
44 | * @exampleMarkdown
|
45 | * ```yaml
|
46 | * config:
|
47 | * defaultScalarType: unknown
|
48 | * ```
|
49 | */
|
50 | defaultScalarType?: string;
|
51 | /**
|
52 | * @description Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
|
53 | *
|
54 | * @exampleMarkdown
|
55 | * ```yaml
|
56 | * config:
|
57 | * scalars:
|
58 | * DateTime: Date
|
59 | * JSON: "{ [key: string]: any }"
|
60 | * ```
|
61 | */
|
62 | scalars?: ScalarsMap;
|
63 | /**
|
64 | * @default change-case-all#pascalCase
|
65 | * @description Allow you to override the naming convention of the output.
|
66 | * You can either override all namings, or specify an object with specific custom naming convention per output.
|
67 | * The format of the converter must be a valid `module#method`.
|
68 | * Allowed values for specific output are: `typeNames`, `enumValues`.
|
69 | * You can also use "keep" to keep all GraphQL names as-is.
|
70 | * Additionally, you can set `transformUnderscore` to `true` if you want to override the default behavior,
|
71 | * which is to preserve underscores.
|
72 | *
|
73 | * Available case functions in `change-case-all` are `camelCase`, `capitalCase`, `constantCase`, `dotCase`, `headerCase`, `noCase`, `paramCase`, `pascalCase`, `pathCase`, `sentenceCase`, `snakeCase`, `lowerCase`, `localeLowerCase`, `lowerCaseFirst`, `spongeCase`, `titleCase`, `upperCase`, `localeUpperCase` and `upperCaseFirst`
|
74 | * [See more](https://github.com/btxtiger/change-case-all)
|
75 | *
|
76 | * @exampleMarkdown
|
77 | * ## Override All Names
|
78 | * ```yaml
|
79 | * config:
|
80 | * namingConvention: change-case-all#lowerCase
|
81 | * ```
|
82 | *
|
83 | * ## Upper-case enum values
|
84 | * ```yaml
|
85 | * config:
|
86 | * namingConvention:
|
87 | * typeNames: change-case-all#pascalCase
|
88 | * enumValues: change-case-all#upperCase
|
89 | * ```
|
90 | *
|
91 | * ## Keep names as is
|
92 | * ```yaml
|
93 | * config:
|
94 | * namingConvention: keep
|
95 | * ```
|
96 | *
|
97 | * ## Remove Underscores
|
98 | * ```yaml
|
99 | * config:
|
100 | * namingConvention:
|
101 | * typeNames: change-case-all#pascalCase
|
102 | * transformUnderscore: true
|
103 | * ```
|
104 | */
|
105 | namingConvention?: NamingConvention;
|
106 | /**
|
107 | * @default ""
|
108 | * @description Prefixes all the generated types.
|
109 | *
|
110 | * @exampleMarkdown
|
111 | * ```yaml
|
112 | * config:
|
113 | * typesPrefix: I
|
114 | * ```
|
115 | */
|
116 | typesPrefix?: string;
|
117 | /**
|
118 | * @default ""
|
119 | * @description Suffixes all the generated types.
|
120 | *
|
121 | * @exampleMarkdown
|
122 | * ```yaml
|
123 | * config:
|
124 | * typesSuffix: I
|
125 | * ```
|
126 | */
|
127 | typesSuffix?: string;
|
128 | /**
|
129 | * @default false
|
130 | * @description Does not add `__typename` to the generated types, unless it was specified in the selection set.
|
131 | *
|
132 | * @exampleMarkdown
|
133 | * ```yaml
|
134 | * config:
|
135 | * skipTypename: true
|
136 | * ```
|
137 | */
|
138 | skipTypename?: boolean;
|
139 | /**
|
140 | * @default false
|
141 | * @description Automatically adds `__typename` field to the generated types, even when they are not specified
|
142 | * in the selection set, and makes it non-optional
|
143 | *
|
144 | * @exampleMarkdown
|
145 | * ```yaml
|
146 | * config:
|
147 | * nonOptionalTypename: true
|
148 | * ```
|
149 | */
|
150 | nonOptionalTypename?: boolean;
|
151 | /**
|
152 | * @name useTypeImports
|
153 | * @type boolean
|
154 | * @default false
|
155 | * @description Will use `import type {}` rather than `import {}` when importing only types. This gives
|
156 | * compatibility with TypeScript's "importsNotUsedAsValues": "error" option
|
157 | *
|
158 | * @example
|
159 | * ```yaml
|
160 | * config:
|
161 | * useTypeImports: true
|
162 | * ```
|
163 | */
|
164 | useTypeImports?: boolean;
|
165 | /**
|
166 | * @ignore
|
167 | */
|
168 | externalFragments?: LoadedFragment[];
|
169 | /**
|
170 | * @ignore
|
171 | */
|
172 | fragmentImports?: ImportDeclaration<FragmentImport>[];
|
173 | /**
|
174 | * @ignore
|
175 | */
|
176 | globalNamespace?: boolean;
|
177 | /**
|
178 | * @description Removes fragment duplicates for reducing data transfer.
|
179 | * It is done by removing sub-fragments imports from fragment definition
|
180 | * Instead - all of them are imported to the Operation node.
|
181 | * @type boolean
|
182 | * @default false
|
183 | */
|
184 | dedupeFragments?: boolean;
|
185 | /**
|
186 | * @ignore
|
187 | */
|
188 | allowEnumStringTypes?: boolean;
|
189 | /**
|
190 | * @description Whether fragment types should be inlined into other operations.
|
191 | * "inline" is the default behavior and will perform deep inlining fragment types within operation type definitions.
|
192 | * "combine" is the previous behavior that uses fragment type references without inlining the types (and might cause issues with deeply nested fragment that uses list types).
|
193 | *
|
194 | * @type string
|
195 | * @default inline
|
196 | */
|
197 | inlineFragmentTypes?: InlineFragmentTypeOptions;
|
198 | }
|
199 | export declare class BaseVisitor<TRawConfig extends RawConfig = RawConfig, TPluginConfig extends ParsedConfig = ParsedConfig> {
|
200 | protected _parsedConfig: TPluginConfig;
|
201 | protected _declarationBlockConfig: DeclarationBlockConfig;
|
202 | readonly scalars: NormalizedScalarsMap;
|
203 | constructor(rawConfig: TRawConfig, additionalConfig: Partial<TPluginConfig>);
|
204 | protected getVisitorKindContextFromAncestors(ancestors: ASTNode[]): string[];
|
205 | get config(): TPluginConfig;
|
206 | convertName(node: ASTNode | string, options?: BaseVisitorConvertOptions & ConvertOptions): string;
|
207 | getOperationSuffix(node: FragmentDefinitionNode | OperationDefinitionNode | string, operationType: string): string;
|
208 | getFragmentSuffix(node: FragmentDefinitionNode | string): string;
|
209 | getFragmentName(node: FragmentDefinitionNode | string): string;
|
210 | getFragmentVariableName(node: FragmentDefinitionNode | string): string;
|
211 | protected getPunctuation(_declarationKind: DeclarationKind): string;
|
212 | }
|