UNPKG

7.95 kBTypeScriptView Raw
1import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2/**
3 * @description This plugin generates React Apollo components and HOC with TypeScript typings.
4 *
5 * It extends the basic TypeScript plugins: `@graphql-codegen/typescript`, `@graphql-codegen/typescript-operations` - and thus shares a similar configuration.
6 */
7export interface ReactApolloRawPluginConfig extends RawClientSideBasePluginConfig {
8 /**
9 * @description Customize the output by enabling/disabling the generated Component (deprecated since Apollo-Client v3). For more details: https://apollographql.com/docs/react/api/react/components
10 * @default false
11 *
12 * @exampleMarkdown
13 * ```ts filename="codegen.ts"
14 * import type { CodegenConfig } from '@graphql-codegen/cli';
15 *
16 * const config: CodegenConfig = {
17 * // ...
18 * generates: {
19 * 'path/to/file.ts': {
20 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
21 * config: {
22 * withComponent: true
23 * },
24 * },
25 * },
26 * };
27 * export default config;
28 * ```
29 */
30 withComponent?: boolean;
31 /**
32 * @description Customize the output by enabling/disabling the HOC (deprecated since Apollo-Client v3). For more details: https://apollographql.com/docs/react/api/react/hoc
33 * @default false
34 *
35 * @exampleMarkdown
36 * ```ts filename="codegen.ts"
37 * import type { CodegenConfig } from '@graphql-codegen/cli';
38 *
39 * const config: CodegenConfig = {
40 * // ...
41 * generates: {
42 * 'path/to/file.ts': {
43 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
44 * config: {
45 * withHOC: true
46 * },
47 * },
48 * },
49 * };
50 * export default config;
51 * ```
52 */
53 withHOC?: boolean;
54 /**
55 * @description Customized the output by enabling/disabling the generated React Hooks. For more details: https://apollographql.com/docs/react/api/react/hooks
56 * @default true
57 *
58 * @exampleMarkdown
59 * ```ts filename="codegen.ts"
60 * import type { CodegenConfig } from '@graphql-codegen/cli';
61 *
62 * const config: CodegenConfig = {
63 * // ...
64 * generates: {
65 * 'path/to/file.ts': {
66 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
67 * config: {
68 * withHooks: true
69 * },
70 * },
71 * },
72 * };
73 * export default config;
74 * ```
75 */
76 withHooks?: boolean;
77 /**
78 * @description Customized the output by enabling/disabling the generated mutation function signature.
79 * @default true
80 *
81 * @exampleMarkdown
82 * ```ts filename="codegen.ts"
83 * import type { CodegenConfig } from '@graphql-codegen/cli';
84 *
85 * const config: CodegenConfig = {
86 * // ...
87 * generates: {
88 * 'path/to/file.ts': {
89 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
90 * config: {
91 * withMutationFn: true
92 * },
93 * },
94 * },
95 * };
96 * export default config;
97 * ```
98 */
99 withMutationFn?: boolean;
100 /**
101 * @description Enable generating a function to be used with refetchQueries
102 * @default false
103 *
104 * @exampleMarkdown
105 * ```ts filename="codegen.ts"
106 * import type { CodegenConfig } from '@graphql-codegen/cli';
107 *
108 * const config: CodegenConfig = {
109 * // ...
110 * generates: {
111 * 'path/to/file.ts': {
112 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
113 * config: {
114 * withRefetchFn: false
115 * },
116 * },
117 * },
118 * };
119 * export default config;
120 * ```
121 */
122 withRefetchFn?: boolean;
123 /**
124 * @description Customize the package where apollo-react common lib is loaded from.
125 * @default "@apollo/react-common"
126 */
127 apolloReactCommonImportFrom?: string;
128 /**
129 * @description Customize the package where apollo-react component lib is loaded from.
130 * @default "@apollo/react-components"
131 */
132 apolloReactComponentsImportFrom?: string;
133 /**
134 * @description Customize the package where apollo-react HOC lib is loaded from.
135 * @default "@apollo/react-hoc"
136 */
137 apolloReactHocImportFrom?: string;
138 /**
139 * @description Customize the package where apollo-react hooks lib is loaded from.
140 * @default "@apollo/react-hooks"
141 */
142 apolloReactHooksImportFrom?: string;
143 /**
144 * @description You can specify a suffix that gets attached to the name of the generated component.
145 * @default Component
146 */
147 componentSuffix?: string;
148 /**
149 * @description Sets the version of react-apollo.
150 * If you are using the old (deprecated) package of `react-apollo`, please set this configuration to `2`.
151 * If you are using Apollo-Client v3, please set this to `3`.
152 * @default 3
153 *
154 * @exampleMarkdown
155 * ```ts filename="codegen.ts"
156 * import type { CodegenConfig } from '@graphql-codegen/cli';
157 *
158 * const config: CodegenConfig = {
159 * // ...
160 * generates: {
161 * 'path/to/file.ts': {
162 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
163 * config: {
164 * reactApolloVersion: 2
165 * },
166 * },
167 * },
168 * };
169 * export default config;
170 * ```
171 */
172 reactApolloVersion?: 2 | 3;
173 /**
174 * @description Customized the output by enabling/disabling the generated result type.
175 * @default true
176 *
177 * @exampleMarkdown
178 * ```ts filename="codegen.ts"
179 * import type { CodegenConfig } from '@graphql-codegen/cli';
180 *
181 * const config: CodegenConfig = {
182 * // ...
183 * generates: {
184 * 'path/to/file.ts': {
185 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
186 * config: {
187 * withResultType: true
188 * },
189 * },
190 * },
191 * };
192 * export default config;
193 * ```
194 */
195 withResultType?: boolean;
196 /**
197 * @description Customized the output by enabling/disabling the generated mutation option type.
198 * @default true
199 *
200 * @exampleMarkdown
201 * ```ts filename="codegen.ts"
202 * import type { CodegenConfig } from '@graphql-codegen/cli';
203 *
204 * const config: CodegenConfig = {
205 * // ...
206 * generates: {
207 * 'path/to/file.ts': {
208 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
209 * config: {
210 * withMutationOptionsType: true
211 * },
212 * },
213 * },
214 * };
215 * export default config;
216 * ```
217 */
218 withMutationOptionsType?: boolean;
219 /**
220 * @description Allows you to enable/disable the generation of docblocks in generated code.
221 * Some IDE's (like VSCode) add extra inline information with docblocks, you can disable this feature if your preferred IDE does not.
222 * @default true
223 *
224 * @exampleMarkdown
225 * ```ts filename="codegen.ts"
226 * import type { CodegenConfig } from '@graphql-codegen/cli';
227 *
228 * const config: CodegenConfig = {
229 * // ...
230 * generates: {
231 * 'path/to/file.ts': {
232 * plugins: ['typescript', 'typescript-operations', 'typescript-react-apollo'],
233 * config: {
234 * addDocBlocks: true
235 * },
236 * },
237 * },
238 * };
239 * export default config;
240 * ```
241 */
242 addDocBlocks?: boolean;
243 defaultBaseOptions?: {
244 [key: string]: string;
245 };
246 hooksSuffix?: string;
247}