nestjs / graphql

GraphQL (TypeScript) module for Nest framework (node.js) 🍷
https://docs.nestjs.com/graphql/quick-start
MIT License
1.46k stars 396 forks source link

Decorator factory should apply to nested objects #2841

Open abouroubi opened 1 year ago

abouroubi commented 1 year ago

Is there an existing issue for this?

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?

Other

No response

kamilmysliwiec commented 1 year ago

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

abouroubi commented 1 year ago

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

mehdimoozeh commented 8 months ago

@abouroubi Any news on this one?

abouroubi commented 8 months ago

No idea, I just stopped using the PartialType