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