1 | import { RawTypesConfig, AvoidOptionalsConfig } from '@graphql-codegen/visitor-plugin-common';
|
2 | /**
|
3 | * @description This plugin generates the base TypeScript types, based on your GraphQL schema.
|
4 | *
|
5 | * The types generated by this plugin are simple, and refers to the exact structure of your schema, and it's used as the base types for other plugins (such as `typescript-operations` / `typescript-resolvers`)
|
6 | */
|
7 | export interface TypeScriptPluginConfig extends RawTypesConfig {
|
8 | /**
|
9 | * @description This will cause the generator to avoid using TypeScript optionals (`?`) on types,
|
10 | * so the following definition: `type A { myField: String }` will output `myField: Maybe<string>`
|
11 | * instead of `myField?: Maybe<string>`.
|
12 | * @default false
|
13 | *
|
14 | * @exampleMarkdown
|
15 | * ## Override all definition types
|
16 | *
|
17 | * ```yaml
|
18 | * generates:
|
19 | * path/to/file.ts:
|
20 | * plugins:
|
21 | * - typescript
|
22 | * config:
|
23 | * avoidOptionals: true
|
24 | * ```
|
25 | *
|
26 | * ## Override only specific definition types
|
27 | *
|
28 | * ```yaml
|
29 | * generates:
|
30 | * path/to/file.ts:
|
31 | * plugins:
|
32 | * - typescript
|
33 | * config:
|
34 | * avoidOptionals:
|
35 | * field: true
|
36 | * inputValue: true
|
37 | * object: true
|
38 | * defaultValue: true
|
39 | * ```
|
40 | */
|
41 | avoidOptionals?: boolean | AvoidOptionalsConfig;
|
42 | /**
|
43 | * @description Will prefix every generated `enum` with `const`, you can read more about const enums here: https://www.typescriptlang.org/docs/handbook/enums.html.
|
44 | * @default false
|
45 | *
|
46 | * @exampleMarkdown
|
47 | * ```yaml
|
48 | * generates:
|
49 | * path/to/file.ts:
|
50 | * plugins:
|
51 | * - typescript
|
52 | * config:
|
53 | * constEnums: true
|
54 | * ```
|
55 | */
|
56 | constEnums?: boolean;
|
57 | /**
|
58 | * @description Generates enum as TypeScript `type` instead of `enum`. Useful if you wish to generate `.d.ts` declaration file instead of `.ts`
|
59 | * @default false
|
60 | *
|
61 | * @exampleMarkdown
|
62 | * ```yaml
|
63 | * generates:
|
64 | * path/to/file.ts:
|
65 | * plugins:
|
66 | * - typescript
|
67 | * config:
|
68 | * enumsAsTypes: true
|
69 | * ```
|
70 | */
|
71 | enumsAsTypes?: boolean;
|
72 | /**
|
73 | * @description Controls whether to preserve typescript enum values as numbers
|
74 | * @default false
|
75 | *
|
76 | * @exampleMarkdown
|
77 | * ```yaml
|
78 | * generates:
|
79 | * path/to/file.ts:
|
80 | * plugins:
|
81 | * - typescript
|
82 | * config:
|
83 | * numericEnums: true
|
84 | * ```
|
85 | */
|
86 | numericEnums?: boolean;
|
87 | /**
|
88 | * @description This option controls whether or not a catch-all entry is added to enum type definitions for values that may be added in the future.
|
89 | * This is useful if you are using `relay`.
|
90 | * @default false
|
91 | *
|
92 | * @exampleMarkdown
|
93 | * ```yaml
|
94 | * generates:
|
95 | * path/to/file.ts:
|
96 | * plugins:
|
97 | * - typescript
|
98 | * config:
|
99 | * enumsAsTypes: true
|
100 | * futureProofEnums: true
|
101 | * ```
|
102 | */
|
103 | futureProofEnums?: boolean;
|
104 | /**
|
105 | * @description This option controls whether or not a catch-all entry is added to union type definitions for values that may be added in the future.
|
106 | * This is useful if you are using `relay`.
|
107 | * @default false
|
108 | *
|
109 | * @exampleMarkdown
|
110 | * ```yaml
|
111 | * generates:
|
112 | * path/to/file.ts:
|
113 | * plugins:
|
114 | * - typescript
|
115 | * config:
|
116 | * futureProofUnions: true
|
117 | * ```
|
118 | */
|
119 | futureProofUnions?: boolean;
|
120 | /**
|
121 | * @description Generates enum as TypeScript `const assertions` instead of `enum`. This can even be used to enable enum-like patterns in plain JavaScript code if you choose not to use TypeScript’s enum construct.
|
122 | * @default false
|
123 | *
|
124 | * @exampleMarkdown
|
125 | * ```yaml
|
126 | * generates:
|
127 | * path/to/file.ts:
|
128 | * plugins:
|
129 | * - typescript
|
130 | * config:
|
131 | * enumsAsConst: true
|
132 | * ```
|
133 | */
|
134 | enumsAsConst?: boolean;
|
135 | /**
|
136 | * @description This will cause the generator to emit types for enums only.
|
137 | * @default false
|
138 | *
|
139 | * @exampleMarkdown Override all definition types
|
140 | * ```yaml
|
141 | * generates:
|
142 | * path/to/file.ts:
|
143 | * plugins:
|
144 | * - typescript
|
145 | * config:
|
146 | * onlyEnums: true
|
147 | * ```
|
148 | */
|
149 | onlyEnums?: boolean;
|
150 | /**
|
151 | * @description This will cause the generator to emit types for operations only (basically only enums and scalars).
|
152 | * Interacts well with `preResolveTypes: true`
|
153 | * @default false
|
154 | *
|
155 | * @exampleMarkdown Override all definition types
|
156 | * ```yaml
|
157 | * generates:
|
158 | * path/to/file.ts:
|
159 | * plugins:
|
160 | * - typescript
|
161 | * config:
|
162 | * onlyOperationTypes: true
|
163 | * ```
|
164 | */
|
165 | onlyOperationTypes?: boolean;
|
166 | /**
|
167 | * @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
|
168 | * @default false
|
169 | *
|
170 | * @exampleMarkdown
|
171 | * ```yaml
|
172 | * generates:
|
173 | * path/to/file.ts:
|
174 | * plugins:
|
175 | * - typescript
|
176 | * config:
|
177 | * immutableTypes: true
|
178 | * ```
|
179 | */
|
180 | immutableTypes?: boolean;
|
181 | /**
|
182 | * @description Allow to override the type value of `Maybe`.
|
183 | * @default T | null
|
184 | *
|
185 | * @exampleMarkdown
|
186 | * ## Allow undefined
|
187 | *
|
188 | * ```yaml
|
189 | * generates:
|
190 | * path/to/file.ts:
|
191 | * plugins:
|
192 | * - typescript
|
193 | * config:
|
194 | * maybeValue: T | null | undefined
|
195 | * ```
|
196 | *
|
197 | * ## Allow `null` in resolvers:
|
198 | *
|
199 | * ```yaml
|
200 | * generates:
|
201 | * path/to/file.ts:
|
202 | * plugins:
|
203 | * - typescript
|
204 | * - typescript-resolvers
|
205 | * config:
|
206 | * maybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
|
207 | * ```
|
208 | */
|
209 | maybeValue?: string;
|
210 | /**
|
211 | * @description Allow to override the type value of `Maybe` for input types and arguments.
|
212 | * This is useful in case you want to differentiate between the wrapper of input and output types.
|
213 | * By default, this type just refers to `Maybe` type, but you can override it's definition.
|
214 | *
|
215 | * @default Maybe<T>
|
216 | *
|
217 | * @exampleMarkdown
|
218 | * ## Allow undefined
|
219 | * ```yaml
|
220 | * generates:
|
221 | * path/to/file.ts:
|
222 | * plugins:
|
223 | * - typescript
|
224 | * config:
|
225 | * inputMaybeValue: T | null | undefined
|
226 | * ```
|
227 | *
|
228 | * ## Allow `null` in resolvers:
|
229 | * ```yaml
|
230 | * generates:
|
231 | * path/to/file.ts:
|
232 | * plugins:
|
233 | * - typescript
|
234 | * - typescript-resolvers
|
235 | * config:
|
236 | * inputMaybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
|
237 | * ```
|
238 | */
|
239 | inputMaybeValue?: string;
|
240 | /**
|
241 | * @description Set to `true` in order to generate output without `export` modifier.
|
242 | * This is useful if you are generating `.d.ts` file and want it to be globally available.
|
243 | * @default false
|
244 | *
|
245 | * @exampleMarkdown
|
246 | * ## Disable all export from a file
|
247 | *
|
248 | * ```yaml
|
249 | * generates:
|
250 | * path/to/file.ts:
|
251 | * plugins:
|
252 | * - typescript
|
253 | * config:
|
254 | * noExport: true
|
255 | * ```
|
256 | */
|
257 | noExport?: boolean;
|
258 | /**
|
259 | * @description Set the value to `true` in order to disable all description generation.
|
260 | * @default false
|
261 | *
|
262 | * @exampleMarkdown
|
263 | * ## Disable description generation
|
264 | *
|
265 | * ```yaml
|
266 | * generates:
|
267 | * path/to/file.ts:
|
268 | * plugins:
|
269 | * - typescript
|
270 | * config:
|
271 | * disableDescriptions: true
|
272 | * ```
|
273 | */
|
274 | disableDescriptions?: boolean;
|
275 | /**
|
276 | * @description When a GraphQL interface is used for a field, this flag will use the implementing types, instead of the interface itself.
|
277 | * @default false
|
278 | *
|
279 | * @exampleMarkdown
|
280 | * ## Override all definition types
|
281 | *
|
282 | * ```yaml
|
283 | * generates:
|
284 | * path/to/file.ts:
|
285 | * plugins:
|
286 | * - typescript
|
287 | * config:
|
288 | * useImplementingTypes: true
|
289 | * ```
|
290 | */
|
291 | useImplementingTypes?: boolean;
|
292 | /**
|
293 | * @name wrapEntireFieldDefinitions
|
294 | * @type boolean
|
295 | * @description Set to `true` in order to wrap field definitions with `EntireFieldWrapper`.
|
296 | * This is useful to allow return types such as Promises and functions for fields.
|
297 | * Differs from `wrapFieldDefinitions` in that this wraps the entire field definition if i.e. the field is an Array, while
|
298 | * `wrapFieldDefinitions` will wrap every single value inside the array.
|
299 | * @default false
|
300 | *
|
301 | * @example Enable wrapping entire fields
|
302 | * ```yaml
|
303 | * generates:
|
304 | * path/to/file.ts:
|
305 | * plugins:
|
306 | * - typescript
|
307 | * config:
|
308 | * wrapEntireFieldDefinitions: false
|
309 | * ```
|
310 | */
|
311 | wrapEntireFieldDefinitions?: boolean;
|
312 | /**
|
313 | * @name entireFieldWrapperValue
|
314 | * @type string
|
315 | * @description Allow to override the type value of `EntireFieldWrapper`. This wrapper applies outside of Array and Maybe
|
316 | * unlike `fieldWrapperValue`, that will wrap the inner type.
|
317 | * @default T | Promise<T> | (() => T | Promise<T>)
|
318 | *
|
319 | * @example Only allow values
|
320 | * ```yaml
|
321 | * generates:
|
322 | * path/to/file.ts:
|
323 | * plugins:
|
324 | * - typescript
|
325 | * config:
|
326 | * entireFieldWrapperValue: T
|
327 | * ```
|
328 | */
|
329 | entireFieldWrapperValue?: string;
|
330 | /**
|
331 | * @description Allow using enum string values directly.
|
332 | *
|
333 | * @exampleMarkdown
|
334 | * ```yaml
|
335 | * config:
|
336 | * allowEnumStringTypes: true
|
337 | * ```
|
338 | */
|
339 | allowEnumStringTypes?: boolean;
|
340 | }
|