@@ -93,14 +93,17 @@ import type { CodegenConfig } from '@graphql-codegen/cli'
9393const config: CodegenConfig = {
9494 schema: ' ./schema.graphql' ,
9595 documents: [' ./src/**/*.{ts,tsx}' , ' !./src/**/__generated__/**' ],
96+ externalDocuments: [
97+ ' ../other-package/src/**/*.{ts,tsx}' ,
98+ ' !../other-package/src/**/__generated__/**'
99+ ],
96100 generates: {
97101 ' ./src/' : {
98102 preset: ' near-operation-file' ,
99103 presetConfig: {
100104 extension: ' .ts' ,
101105 folder: ' __generated__' ,
102- filePerOperation: true ,
103- inGeneratesOnly: true
106+ filePerOperation: true
104107 },
105108 plugins: [' typescript-operations' ],
106109 config: {
@@ -154,14 +157,17 @@ import type { CodegenConfig } from '@graphql-codegen/cli'
154157const config: CodegenConfig = {
155158 schema: ' ./schema.graphql' ,
156159 documents: [' ./src/**/*.{ts,tsx}' , ' !./src/**/__generated__/**' ],
160+ externalDocuments: [
161+ ' ../other-package/src/**/*.{ts,tsx}' ,
162+ ' !../other-package/src/**/__generated__/**'
163+ ],
157164 generates: {
158165 ' ./src/' : {
159166 preset: ' near-operation-file' ,
160167 presetConfig: {
161168 extension: ' .ts' , // Extension for generated files
162169 folder: ' __generated__' , // Generated files go into __generated__/ subfolder
163- filePerOperation: true , // Generate type files per-operation (not per-component)
164- inGeneratesOnly: true // Only generate files defined in `generates` scan paths (don't generate for all `documents`)
170+ filePerOperation: true // Generate type files per-operation (not per-component)
165171 },
166172 plugins: [' typescript-operations' ]
167173 }
@@ -196,14 +202,17 @@ configuration option:
196202const config: CodegenConfig = {
197203 schema: ' ./schema.graphql' ,
198204 documents: [' ./src/**/*.{ts,tsx}' , ' !./src/**/__generated__/**' ],
205+ externalDocuments: [
206+ ' ../other-package/src/**/*.{ts,tsx}' ,
207+ ' !../other-package/src/**/__generated__/**'
208+ ],
199209 generates: {
200210 ' ./src/' : {
201211 preset: ' near-operation-file' ,
202212 presetConfig: {
203213 extension: ' .ts' ,
204214 folder: ' __generated__' ,
205- filePerOperation: true ,
206- inGeneratesOnly: true
215+ filePerOperation: true
207216 },
208217 plugins: [' typescript-operations' ],
209218 config: {
@@ -239,14 +248,17 @@ declarations matching Apollo Tooling's output, set `enumType: 'native'`:
239248const config: CodegenConfig = {
240249 schema: ' ./schema.graphql' ,
241250 documents: [' ./src/**/*.{ts,tsx}' , ' !./src/**/__generated__/**' ],
251+ externalDocuments: [
252+ ' ../other-package/src/**/*.{ts,tsx}' ,
253+ ' !../other-package/src/**/__generated__/**'
254+ ],
242255 generates: {
243256 ' ./src/' : {
244257 preset: ' near-operation-file' ,
245258 presetConfig: {
246259 extension: ' .ts' ,
247260 folder: ' __generated__' ,
248- filePerOperation: true ,
249- inGeneratesOnly: true
261+ filePerOperation: true
250262 },
251263 plugins: [' typescript-operations' ],
252264 config: {
@@ -284,16 +296,20 @@ import type { CodegenConfig } from '@graphql-codegen/cli'
284296const config: CodegenConfig = {
285297 schema: ' ./schema.graphql' ,
286298 documents: [' ./src/**/*.{ts,tsx}' , ' !./src/**/__generated__/**' ],
299+ // `externalDocuments` are read-only documents that are loaded but do not generate output.
300+ // They are used to include fragments from another package in a monorepo without generating unnecessary files.
301+ externalDocuments: [
302+ ' ../other-package/src/**/*.{ts,tsx}' ,
303+ ' !../other-package/src/**/__generated__/**'
304+ ],
287305 generates: {
288306 ' ./src/' : {
289307 preset: ' near-operation-file' ,
290308 presetConfig: {
291309 extension: ' .ts' ,
292310 folder: ' __generated__' ,
293311 // Generate type files per-operation (not per-component)
294- filePerOperation: true ,
295- // Only generate files defined in `generates` scan paths (don't generate for all `documents`)
296- inGeneratesOnly: true
312+ filePerOperation: true
297313 },
298314 plugins: [' typescript-operations' ],
299315 config: {
@@ -329,17 +345,17 @@ export default config
329345The setup above closely mimics Apollo Tooling but isn’t an exact match. The following items may
330346require manual fixes:
331347
332- 1 . Nested field types naming.
348+ #### 1. Nested field types naming.
333349
334- In very rare cases, the names generated by GraphQL Codegen don’t match Apollo Tooling’s. Update
335- these cases manually.
350+ In very rare cases, the field names generated by GraphQL Codegen don’t match Apollo Tooling’s.
351+ Update these cases manually.
336352
337- 2 . Enum file location.
353+ #### 2. Enum file location.
338354
339355Occasionally, GraphQL Codegen places enums in a different file then Apollo Tooling. If an enum is
340356missing, check nearby generated files and adjust your imports accordingly.
341357
342- 3 . ` is possibly null ` and ` has any type ` typecheck bugs.
358+ #### 3. ` is possibly null ` and ` has any type ` typecheck bugs.
343359
344360These bugs has to be fixed.
345361
@@ -351,30 +367,33 @@ For `is possibly null` bug, asserting for not null or adding `!` will fix most c
351367
352368For ` has any type ` bug - a proper type needs to be determined.
353369
354- 4 . Mismatch between ` Type | null ` and ` Type | null | undefined ` .
370+ #### 4. Mismatch between ` Type | null ` and ` Type | null | undefined ` .
355371
356372Experiment with the following configuration options to keep your codebase changes to a minimum:
357373
358- ```
359- maybeValue: defaults to 'T | null', set to 'T | null | undefined' if necessary
360- inputMaybeValue: defaults to 'Maybe<T>', set to 'T | null | undefined' if necessary
361- avoidOptionals: Replaces ? optional modifier with explicit Maybe<T>. Supports granular control via object form.
362- allowUndefinedQueryVariables: Adds | undefined to Query operation variable types (not Mutation/Subscription)
363- optionalResolveType: Makes __resolveType optional (__resolveType?) in resolver types.
364- nullability: When errorHandlingClient: true, adjusts nullability for fields marked with @semanticNonNull directive (requires graphql-sock).
365- ```
374+ - ** maybeValue** : defaults to ` T | null ` , set to ` T | null | undefined ` if necessary
375+ - ** inputMaybeValue** : defaults to ` Maybe<T> ` , set to ` T | null | undefined ` if necessary
376+ - ** avoidOptionals** : Replaces ? optional modifier with explicit ` Maybe<T> ` . Supports granular
377+ control via object form.
378+ - ** allowUndefinedQueryVariables** : Adds | undefined to Query operation variable types (not
379+ Mutation/Subscription)
380+ - ** optionalResolveType** : Makes ` __resolveType ` optional (` __resolveType? ` ) in resolver types.
381+ - ** nullability** : When ` errorHandlingClient: true ` , adjusts nullability for fields marked with
382+ ` @semanticNonNull ` directive (requires ` graphql-sock ` ).
366383
367- 5 . Extra ` __typename ` present, or required ` __typename ` missing.
384+ #### 5. Extra ` __typename ` present, or required ` __typename ` missing.
368385
369386Experiment with the following configuration options to keep your codebase changes to a minimum:
370387
371- ```
372- skipTypename: prevents adding __typename to generated types unless explicitly in the selection set.
373- skipTypeNameForRoot: skips __typename specifically for root types (Query, Mutation, Subscription). Ignored if __typename is explicitly in the selection set
374- nonOptionalTypename: always adds __typename and makes it a required (non-optional) field.
375- addTypenameToSelectionSets: injects __typename directly into the generated document node selection sets.
376- resolversNonOptionalTypename: makes __typename non-optional in resolver mappings without affecting base types. Supports granular control via object form.
377- ```
388+ - ** skipTypename** : prevents adding ` __typename ` to generated types unless explicitly in the
389+ selection set.
390+ - ** skipTypeNameForRoot** : skips ` __typename ` specifically for root types (Query, Mutation,
391+ Subscription). Ignored if ` __typename ` is explicitly in the selection set
392+ - ** nonOptionalTypename** : always adds ` __typename ` and makes it a required (non-optional) field.
393+ - ** addTypenameToSelectionSets** : injects ` __typename ` directly into the generated document node
394+ selection sets.
395+ - ** resolversNonOptionalTypename** : makes ` __typename ` non-optional in resolver mappings without
396+ affecting base types. Supports granular control via object form.
378397
379398## Further reading
380399
0 commit comments