Skip to content

Commit 3f83163

Browse files
committed
fixing duplication bug
1 parent 2c42650 commit 3f83163

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

packages/plugins/other/visitor-plugin-common/src/base-documents-visitor.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,22 @@ export class BaseDocumentsVisitor<
371371
})
372372
);
373373

374-
const operationResult = new DeclarationBlock(this._declarationBlockConfig)
375-
.export()
376-
.asKind('type')
377-
.withName(
378-
this.convertName(name, {
379-
suffix: operationTypeSuffix + this._parsedConfig.operationResultSuffix,
380-
})
381-
)
382-
.withContent(selectionSetObjects.mergedTypeString).string;
374+
const operationResultName = this.convertName(name, {
375+
suffix: operationTypeSuffix + this._parsedConfig.operationResultSuffix,
376+
});
377+
378+
// When extractAllFieldsToTypes creates a root type with the same name as the operation result,
379+
// we only need the extracted type and can skip the alias to avoid duplicates
380+
const shouldSkipOperationResult =
381+
this._parsedConfig.extractAllFieldsToTypes && operationResultName === selectionSetObjects.mergedTypeString;
382+
383+
const operationResult = shouldSkipOperationResult
384+
? ''
385+
: new DeclarationBlock(this._declarationBlockConfig)
386+
.export()
387+
.asKind('type')
388+
.withName(operationResultName)
389+
.withContent(selectionSetObjects.mergedTypeString).string;
383390

384391
const operationVariables = new DeclarationBlock({
385392
...this._declarationBlockConfig,

packages/plugins/typescript/operations/tests/extract-all-types.spec.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,9 +1562,6 @@ describe('extractAllFieldsToTypesCompact: true', () => {
15621562
export type GetCompanyInfoVariables = Exact<{
15631563
id: string;
15641564
}>;
1565-
1566-
1567-
export type GetCompanyInfo = GetCompanyInfo;
15681565
"
15691566
`);
15701567

0 commit comments

Comments
 (0)