Skip to content

Commit 34e68c2

Browse files
committed
refactor
1 parent 0df7c60 commit 34e68c2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/definitions/object.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ export function buildObjectTypeDefinition(
9898
const fieldNodes = typeInResolverInterfacesConfig
9999
? node.fields
100100
: fieldsWithArguments;
101-
const hasConstructor = Boolean(constructor);
101+
const abstractModifier = constructor ? "abstract " : "";
102102
const keyWord = constructor ? "abstract class" : "interface";
103103
return `${annotations}${outputRestrictionAnnotation}${keyWord} ${name}${constructor}${interfaceInheritance} {
104-
${getDataClassMembers({ node, fieldNodes, schema, config, shouldGenerateFunctions, hasConstructor })}
104+
${getDataClassMembers({ node, fieldNodes, schema, config, shouldGenerateFunctions, abstractModifier })}
105105
}`;
106106
}
107107

@@ -115,15 +115,15 @@ function getDataClassMembers({
115115
fieldNodes,
116116
schema,
117117
config,
118+
abstractModifier,
118119
shouldGenerateFunctions,
119-
hasConstructor,
120120
}: {
121121
node: ObjectTypeDefinitionNode;
122122
fieldNodes?: readonly FieldDefinitionNode[];
123123
schema: GraphQLSchema;
124124
config: CodegenConfigWithDefaults;
125+
abstractModifier?: string;
125126
shouldGenerateFunctions?: boolean;
126-
hasConstructor?: boolean;
127127
}) {
128128
return (fieldNodes ?? node.fields)
129129
?.map((fieldNode) => {
@@ -134,8 +134,8 @@ function getDataClassMembers({
134134
schema,
135135
config,
136136
typeMetadata,
137+
abstractModifier,
137138
shouldGenerateFunctions,
138-
hasConstructor,
139139
);
140140
})
141141
.join(`${shouldGenerateFunctions ? "" : ","}\n`);

src/helpers/build-field-definition.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ export function buildFieldDefinition(
3131
schema: GraphQLSchema,
3232
config: CodegenConfigWithDefaults,
3333
typeMetadata: TypeMetadata,
34+
abstractModifier: string = "",
3435
shouldGenerateFunctions?: boolean,
35-
hasConstructor?: boolean,
3636
) {
3737
const modifier = buildFieldModifier(
3838
node,
3939
fieldNode,
4040
schema,
4141
config,
42-
hasConstructor,
42+
abstractModifier,
4343
);
4444
const fieldArguments = buildFieldArguments(node, fieldNode, schema, config);
4545
const fieldDefinition = `${modifier} ${fieldNode.name.value}${fieldArguments}`;
@@ -80,7 +80,7 @@ function buildFieldModifier(
8080
fieldNode: FieldDefinitionNode,
8181
schema: GraphQLSchema,
8282
config: CodegenConfigWithDefaults,
83-
hasConstructor?: boolean,
83+
abstractModifier: string,
8484
) {
8585
const typeInResolverInterfacesConfig = findTypeInResolverInterfacesConfig(
8686
node,
@@ -102,7 +102,6 @@ function buildFieldModifier(
102102
if (node.kind === Kind.INTERFACE_TYPE_DEFINITION) {
103103
return `${functionModifier}fun`;
104104
}
105-
const abstractModifier = hasConstructor ? "abstract " : "";
106105

107106
return `${abstractModifier}${overrideModifier}${functionModifier}fun`;
108107
}

0 commit comments

Comments
 (0)