Skip to content

Commit

Permalink
Removed unused Maybe declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
vejrj committed Jan 27, 2024
1 parent cbf0e22 commit 5d84bf9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 6 additions & 0 deletions packages/graphql-codegen-typescript-operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,16 @@ export const plugin: PluginFunction<
}`;
}

const commonTypes = [];
if (config.inlineCommonTypes && content.includes("Maybe<")) {
commonTypes.push(`type Maybe<T> = T | null;`);
}

return {
prepend: [
...visitor.getImports(),
...visitor.getGlobalDeclarations(visitor.config.noExport),
...commonTypes,
],
content,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Kind, TypeNode } from "graphql";

const BASIC_TYPES = ["string", "number", "boolean", "any"];
export class TypeScriptOperationVariablesToObject extends TSOperationVariablesToObject {
public isMaybeUsed = false;
public immutableTypes: boolean;

constructor(
Expand All @@ -23,7 +22,6 @@ export class TypeScriptOperationVariablesToObject extends TSOperationVariablesTo
_enumValues: ParsedEnumValuesMap = {},
_applyCoercion = false,
protected inlineCommonTypes = false,
protected setIsMaybeUsed: () => void,
) {
super(
_scalars,
Expand All @@ -50,7 +48,6 @@ export class TypeScriptOperationVariablesToObject extends TSOperationVariablesTo

protected wrapMaybe(type?: string) {
if (this.inlineCommonTypes) {
this.setIsMaybeUsed();
return `Maybe${type ? `<${type}>` : ""}`;
}

Expand Down
10 changes: 0 additions & 10 deletions packages/graphql-codegen-typescript-operations/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
TypeScriptDocumentsParsedConfig
> {
private usedTypes: Set<string>;
private isMaybeUsed = false;
private isExactUsed = false;

constructor(
Expand Down Expand Up @@ -73,7 +72,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<

this.usedTypes = new Set();
const wrapOptional = (type: string) => {
this.isMaybeUsed = true;
const prefix =
!this.config.inlineCommonTypes && this.config.namespacedImportName
? `${this.config.namespacedImportName}.`
Expand Down Expand Up @@ -144,18 +142,13 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
this.config.enumValues,
true,
this.config.inlineCommonTypes,
this.setIsMaybeUsed.bind(this),
),
);
this._declarationBlockConfig = {
ignoreExport: this.config.noExport,
};
}

public setIsMaybeUsed() {
this.isMaybeUsed = true;
}

public getImports(): Array<string> {
const imports = !this.config.globalNamespace
? this.config.fragmentImports
Expand All @@ -171,9 +164,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor<
)
: [];

if (this.config.inlineCommonTypes && this.isMaybeUsed) {
imports.push(`type Maybe<T> = T | null;`);
}
if (this.config.inlineCommonTypes && this.isExactUsed) {
imports.push(`type Exact<T extends { [key: string]: unknown }> = {
[K in keyof T]: T[K];
Expand Down

0 comments on commit 5d84bf9

Please sign in to comment.