Skip to content

Commit

Permalink
fix(input types): fix missing scalar enum imports
Browse files Browse the repository at this point in the history
  • Loading branch information
rfermann committed Apr 21, 2021
1 parent c35b318 commit fbf4656
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,7 @@ export class DeleteOneUserInput {

exports[`InputTypeHandler should parse input types and create correct user input files from datamodel 6`] = `
"import { Field, InputType, Int } from \\"@nestjs/graphql\\";
import { UserScalarFieldEnum } from \\"../../enums\\";
import { UserOrderByInput } from \\"./UserOrderByInput\\";
import { UserWhereInput } from \\"./UserWhereInput\\";
import { UserWhereUniqueInput } from \\"./UserWhereUniqueInput\\";
Expand Down Expand Up @@ -2745,6 +2746,7 @@ export class FindFirstUserInput {

exports[`InputTypeHandler should parse input types and create correct user input files from datamodel 7`] = `
"import { Field, InputType, Int } from \\"@nestjs/graphql\\";
import { UserScalarFieldEnum } from \\"../../enums\\";
import { UserOrderByInput } from \\"./UserOrderByInput\\";
import { UserWhereInput } from \\"./UserWhereInput\\";
import { UserWhereUniqueInput } from \\"./UserWhereUniqueInput\\";
Expand Down Expand Up @@ -2804,6 +2806,7 @@ export class FindUniqueUserInput {

exports[`InputTypeHandler should parse input types and create correct user input files from datamodel 9`] = `
"import { Field, InputType, Int } from \\"@nestjs/graphql\\";
import { UserScalarFieldEnum } from \\"../../enums\\";
import { UserOrderByInput } from \\"./UserOrderByInput\\";
import { UserScalarWhereWithAggregatesInput } from \\"./UserScalarWhereWithAggregatesInput\\";
import { UserWhereInput } from \\"./UserWhereInput\\";
Expand Down
12 changes: 6 additions & 6 deletions src/Handlers/InputTypeHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ export class InputTypeHandler extends BaseHandler {
type: parsedField.graphQLType,
});

const baseGraphqlType = parsedField.graphQLType.replace("[", "").replace("]", "");

fieldInputTypes.forEach(({ location, type }) => {
if (this.baseParser.getEnumName(type) === parsedField.graphQLType) {
if (this.baseParser.getEnumName(type) === baseGraphqlType) {
enumImports = this.baseParser.getEnumImports({ enumImports, field: { location, type } });
}

Expand All @@ -126,8 +128,6 @@ export class InputTypeHandler extends BaseHandler {
});
});

const baseGraphqlType = parsedField.graphQLType.replace("[", "").replace("]", "");

// prevent a type from importing itself
if (name === baseGraphqlType) {
return;
Expand All @@ -139,11 +139,11 @@ export class InputTypeHandler extends BaseHandler {

graphqlScalarImports = this.baseParser.getGraphqlScalarImports({
graphqlScalarImports,
type: parsedField.graphQLType,
type: baseGraphqlType,
});

if (this.baseParser.nestJSImports.has(parsedField.graphQLType)) {
nestJSImports.add(parsedField.graphQLType);
if (this.baseParser.nestJSImports.has(baseGraphqlType)) {
nestJSImports.add(baseGraphqlType);
}

fields.push(parsedField);
Expand Down

0 comments on commit fbf4656

Please sign in to comment.