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