UNPKG

5.84 kBTypeScriptView Raw
1import { RawDocumentsConfig, AvoidOptionalsConfig } from '@graphql-codegen/visitor-plugin-common';
2/**
3 * @description This plugin generates TypeScript types based on your GraphQLSchema _and_ your GraphQL operations and fragments.
4 * It generates types for your GraphQL documents: Query, Mutation, Subscription and Fragment.
5 *
6 * Note: In most configurations, this plugin requires you to use `typescript as well, because it depends on its base types.
7 */
8export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig {
9 /**
10 * @description The [GraphQL spec](https://spec.graphql.org/draft/#sel-FAHjBJFCAACE_Gh7d)
11 * allows arrays and a single primitive value for list input. This allows to
12 * deactivate that behavior to only accept arrays instead of single values. If
13 * set to `false`, the definition: `query foo(bar: [Int!]!): Foo` will output
14 * `bar: Array<Int>` instead of `bar: Array<Int> | Int` for the variable part.
15 * @default true
16 *
17 * @exampleMarkdown
18 * ```yaml
19 * generates:
20 * path/to/file.ts:
21 * plugins:
22 * - typescript
23 * config:
24 * arrayInputCoercion: false
25 * ```
26 */
27 arrayInputCoercion?: boolean;
28 /**
29 * @description This will cause the generator to avoid using TypeScript optionals (`?`) on types,
30 * so the following definition: `type A { myField: String }` will output `myField: Maybe<string>`
31 * instead of `myField?: Maybe<string>`.
32 * @default false
33 *
34 * @exampleMarkdown
35 * ## Override all definition types
36 *
37 * ```yaml
38 * generates:
39 * path/to/file.ts:
40 * plugins:
41 * - typescript
42 * - typescript-operations
43 * config:
44 * avoidOptionals: true
45 * ```
46 *
47 * ## Override only specific definition types
48 *
49 * ```yaml
50 * generates:
51 * path/to/file.ts:
52 * plugins:
53 * - typescript
54 * config:
55 * avoidOptionals:
56 * field: true
57 * inputValue: true
58 * object: true
59 * defaultValue: true
60 * ```
61 */
62 avoidOptionals?: boolean | AvoidOptionalsConfig;
63 /**
64 * @description Generates immutable types by adding `readonly` to properties and uses `ReadonlyArray`.
65 * @default false
66 *
67 * @exampleMarkdown
68 * ```yaml
69 * generates:
70 * path/to/file.ts:
71 * plugins:
72 * - typescript
73 * - typescript-operations
74 * config:
75 * immutableTypes: true
76 * ```
77 */
78 immutableTypes?: boolean;
79 /**
80 * @description Flatten fragment spread and inline fragments into a simple selection set before generating.
81 * @default false
82 *
83 * @exampleMarkdown
84 * ```yaml
85 * generates:
86 * path/to/file.ts:
87 * plugins:
88 * - typescript
89 * - typescript-operations
90 * config:
91 * flattenGeneratedTypes: true
92 * ```
93 */
94 flattenGeneratedTypes?: boolean;
95 /**
96 * @description Include all fragments types when flattenGeneratedTypes is enabled.
97 * @default false
98 *
99 * @exampleMarkdown
100 * ```yaml
101 * generates:
102 * path/to/file.ts:
103 * plugins:
104 * - typescript
105 * - typescript-operations
106 * config:
107 * flattenGeneratedTypes: true
108 * flattenGeneratedTypesIncludeFragments: true
109 * ```
110 */
111 flattenGeneratedTypesIncludeFragments?: boolean;
112 /**
113 * @description Set to `true` in order to generate output without `export` modifier.
114 * This is useful if you are generating `.d.ts` file and want it to be globally available.
115 * @default false
116 *
117 * @exampleMarkdown
118 * ```yaml
119 * generates:
120 * path/to/file.ts:
121 * plugins:
122 * - typescript
123 * config:
124 * noExport: true
125 * ```
126 */
127 noExport?: boolean;
128 globalNamespace?: boolean;
129 /**
130 * @name addOperationExport
131 * @type boolean
132 * @description Add const export of the operation name to output file. Pay attention that the file should be `d.ts`.
133 * You can combine it with `near-operation-file preset` and therefore the types will be generated along with graphql file. Then you need to set extension in `presetConfig` to be `.gql.d.ts` and by that you can import `gql` file in `ts` files.
134 * It will allow you to get everything with one import:
135 *
136 * ```ts
137 * import { GetClient, GetClientQuery, GetClientQueryVariables } from './GetClient.gql'
138 * ```
139 * @default false
140 * @see https://github.com/dotansimha/graphql-code-generator/issues/3949
141 *
142 * @example
143 * ```yaml
144 * generates:
145 * ./typings/api.ts:
146 * plugins:
147 * - '@graphql-codegen/typescript'
148 * ./:
149 * preset: near-operation-file
150 * presetConfig:
151 * baseTypesPath: ./typings/api.ts
152 * extension: .gql.d.ts
153 * plugins:
154 * - '@graphql-codegen/typescript-operations'
155 * config:
156 * addOperationExport: true
157 * ```
158 */
159 addOperationExport?: boolean;
160 /**
161 * @description Allow to override the type value of `Maybe`.
162 * @default T | null
163 *
164 * @exampleMarkdown
165 * ## Allow undefined
166 * ```yaml
167 * generates:
168 * path/to/file.ts:
169 * plugins:
170 * - typescript
171 * config:
172 * maybeValue: T | null | undefined
173 * ```
174 *
175 * ## Allow `null` in resolvers:
176 * ```yaml
177 * generates:
178 * path/to/file.ts:
179 * plugins:
180 * - typescript
181 * - typescript-resolvers
182 * config:
183 * maybeValue: 'T extends PromiseLike<infer U> ? Promise<U | null> : T | null'
184 * ```
185 */
186 maybeValue?: string;
187}