Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator factory should apply to nested objects #2841

Open
1 of 4 tasks
abouroubi opened this issue May 24, 2023 · 4 comments
Open
1 of 4 tasks

Decorator factory should apply to nested objects #2841

abouroubi opened this issue May 24, 2023 · 4 comments

Comments

@abouroubi
Copy link

abouroubi commented May 24, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

According to #688 and to the docs, a second argument can be sent to PartialType() to change the decorator applied to the parent class, for example changing from ObjectType() to InputType(), but if the parent class is composed of another ObjectType() this change doesn't apply to it, and the schema builder will fail.

@ObjectType()
class ClassA {
  @Field()
  email: string;

  @Field()
  b: ClassB;
}

@ObjectType()
class ClassB {
  @Field()
  firstName: string;

  @Field()
  lastName: string;
}


@InputType()
export class ClassAInput extends PartialType(ClassA, InputType) {}

This code sample will fail on app startup, with the error:

/Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type.factory.js:19
                throw new cannot_determine_input_type_error_1.CannotDetermineInputTypeError(hostType, typeRef);
                      ^
Error: Cannot determine a GraphQL input type ("ClassB") for the "b". Make sure your class is decorated with an appropriate decorator.
    at InputTypeFactory.create (/Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type.factory.js:19:23)
    at /Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:48:52
    at Array.forEach (<anonymous>)
    at /Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:46:33
    at resolveObjMapThunk (/Users/project_nestjs/node_modules/graphql/type/definition.js:504:40)
    at defineInputFieldMap (/Users/project_nestjs/node_modules/graphql/type/definition.js:1313:20)
    at GraphQLInputObjectType.getFields (/Users/project_nestjs/node_modules/graphql/type/definition.js:1276:27)
    at TypeFieldsAccessor.extractFromInputType (/Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/services/type-fields.accessor.js:9:35)
    at /Users/project_nestjs/node_modules/@nestjs/graphql/dist/schema-builder/factories/input-type-definition.factory.js:64:66
    at resolveObjMapThunk (/Users/project_nestjs/node_modules/graphql/type/definition.js:504:40)

Minimum reproduction code

https://codesandbox.io/s/optimistic-flower-n5qhe9

Steps to reproduce

No response

Expected behavior

The entity to compile without error.

Package version

11.0.5

Graphql version

"graphql": "^16.3.0",

NestJS version

No response

Node.js version

No response

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@kamilmysliwiec
Copy link
Member

Please provide a minimum reproduction repository (Git repository/StackBlitz/CodeSandbox project).

@abouroubi
Copy link
Author

Yes of course, here is the link: https://codesandbox.io/s/optimistic-flower-n5qhe9

@mehdimoozeh
Copy link

@abouroubi Any news on this one?

@abouroubi
Copy link
Author

No idea, I just stopped using the PartialType

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants