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