Skip to content

Undefined type error. Make sure you are providing an explicit type for the "alerts" of the "AlertType" class. #334

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

Closed
kasir-barati opened this issue Dec 13, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@kasir-barati
Copy link
Contributor

Describe the bug
So it is fairly simple, just have a 1:N relation between alert and alert type. Need to allow users to fetch:

  • An alert with its alert type.
  • An alert type with its alerts.

Have you read the Contributing Guidelines?

Yup.

To Reproduce
Clone my repo: https://github.com/kasir-barati/nestjs-materials

  1. cd typeorm.
  2. pnpm i --frozen-lockfile.
  3. nx serve botprobe-nest

Expected behavior
Just start like it was before adding this piece of code in my alert-type.entity.ts:

https://github.com/kasir-barati/nestjs-materials/blob/0b712a5de535c7cb8204aa8eac5d9344af9afaa3/typeorm/apps/botprobe-nest/src/alert-type/entities/alert-type.entity.ts#L41-L45

Screenshots
Screenshot of the error message

Desktop (please complete the following information):

  • Node Version: 22.12.0
  • Nestjs-query Version: 8.0.0

Additional context

Error message in text:

/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/utils/reflection.utilts.js:17
            throw new undefined_type_error_1.UndefinedTypeError((0, lodash_1.get)(prototype, 'constructor.name'), propertyKey, index);
                  ^

Error: Undefined type error. Make sure you are providing an explicit type for the "alerts" of the "AlertType" class.
    at reflectTypeFromMetadata (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/utils/reflection.utilts.js:17:19)
    at applyMetadataFn (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/decorators/field.decorator.js:31:107)
    at singleCallFunctionWrapper (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/schema-builder/storages/lazy-metadata.storage.js:67:13)
    at /home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/schema-builder/storages/lazy-metadata.storage.js:41:44
    at Array.forEach (<anonymous>)
    at LazyMetadataStorageHost.load (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/schema-builder/storages/lazy-metadata.storage.js:41:26)
    at getFieldsAndDecoratorForType (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/schema-builder/utils/get-fields-and-decorator.util.js:16:49)
    at PartialType (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@nestjs+graphql@12.2.2_@nestjs+common@10.4.15_class-transformer@0.5.1_class-validator@0.14.1__zsrjvl6g7tdfe2t3vnfusw45sm/node_modules/@nestjs/graphql/dist/type-helpers/partial-type.helper.js:18:107)
    at /home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@ptc-org+nestjs-query-graphql@8.0.0_@apollo+gateway@2.9.3_encoding@0.1.13_graphql@16.9.0__@ne_fbjnmutqxhqvoxqdmvnas6ncgu/packages/query-graphql/src/resolvers/delete.resolver.ts:100:48
    at DeleteResolver (/home/kasir/projects/nestjs-materials/typeorm/node_modules/.pnpm/@ptc-org+nestjs-query-graphql@8.0.0_@apollo+gateway@2.9.3_encoding@0.1.13_graphql@16.9.0__@ne_fbjnmutqxhqvoxqdmvnas6ncgu/packages/query-graphql/src/resolvers/delete.resolver.ts:227:89)


 NX  Process exited with code 1, waiting for changes to restart...

I am kinda wondering if I am experiencing what they are talking about it here: https://stackoverflow.com/a/72300528/8784518

@kasir-barati kasir-barati added the bug Something isn't working label Dec 13, 2024
@kasir-barati
Copy link
Contributor Author

I also read this issues but it seems that no one actually has experienced this issue, i.e. except me 😅.

#301
#307

@kasir-barati
Copy link
Contributor Author

You can see that it works just fine in normal setup with NestJS: https://github.com/kasir-barati/bugs/tree/normal-one-to-many-rel

@kasir-barati
Copy link
Contributor Author

kasir-barati commented Dec 14, 2024

I am trying to debug this issue with an example, but I am having a bit of trouble. It does not make sense to me that although I have said in my entities (written in TypeORM) that I wanna have a camelCase table name, and column name but in reality when I go to database container I can see it is in snake_case.

What in the world is happening here?

@TriPSs
Copy link
Owner

TriPSs commented Dec 14, 2024

Took a quick look, but relations are not defined with @Field / @FilterableField, please check these docs

@kasir-barati
Copy link
Contributor Author

kasir-barati commented Dec 14, 2024

I am trying to debug this issue with an example, but I am having a bit of trouble. It does not make sense to me that although I have said in my entities (written in TypeORM) that I wanna have a camelCase table name, and column name but in reality when I go to database container I can see it is in snake_case.

What in the world is happening here?

I had to tell that it MUST use the camelCase naming convention explicitly. But this goes against what is normal (for more details look at this).

import { Field, GraphQLISODateTime, ObjectType } from '@nestjs/graphql'
import { FilterableField } from '@ptc-org/nestjs-query-graphql'
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'
import { AlertType } from '../alert-type/alert-type.entity'

@ObjectType()
@Entity()
export class Alert {
  @Column('uuid', { name: 'userId' })
  @Field({ description: "Who's the creator of this alert" })
  @FilterableField()
  userId: string
}

@TriPSs
Copy link
Owner

TriPSs commented Dec 14, 2024

You lost me here? If I understand you this is a issue with TypeORM and not this lib?

@kasir-barati
Copy link
Contributor Author

kasir-barati commented Dec 14, 2024

If you ask me I would say some configuration somewhere is causing TypeORM to behave this way. But let's ignore it right now since it is not directly related to this issue.

BTW I am reading the docs ATM. Will update you here.

@kasir-barati
Copy link
Contributor Author

Thanks to this comments I was able to pin point the issue and solve it (RTFM, I did not read it completely). This was a lesson I learned. First read the docs completely.

kasir-barati/nestjs-materials@4755f6a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants