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

Reduntant type info #353

Open
MichalLytek opened this issue Jan 18, 2023 · 5 comments
Open

Reduntant type info #353

MichalLytek opened this issue Jan 18, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@MichalLytek
Copy link
Owner

Currently, in some cases, the generator emits reduntant type info, like for fields of input types or models. Also, it not generates that type info for @Args in resolvers.

The first iteration would add the emitRedundantTypesInfo generator option, that would generate all the missing redundant types info, so that 3rd party compilers without types metadata support would be able to work correctly with the generated code.

Second iteration would invole detecting when the type info could be ommited, so that we will reduce the ammout of emitted code, that could speed up and save some space when using bundlers.

The redundancy in inputs, args and models would be disabled by default and enable full info with this option enabled.

@MichalLytek MichalLytek added the enhancement New feature or request label Jan 18, 2023
@MichalLytek MichalLytek self-assigned this Jan 18, 2023
@MichalLytek
Copy link
Owner Author

MichalLytek commented Jan 18, 2023

First iteration done in 36113be. You can now use emitRedundantTypesInfo generator option:
https://prisma.typegraphql.com/docs/advanced/emit-redundant-types-info

@nephix
Copy link

nephix commented Jan 29, 2023

Really cool!

How would I go about integrating this?

I enabled the emitRedundantTypesInfo flag and did a quick test build with esbuild but I still run into these reflection errors:

/Users/xxx/Projects/boilerplate/apps/server/dist/server.js:69362
        throw new errors_1.NoExplicitTypeError(prototype.constructor.name, propertyKey, parameterIndex, argName);
        ^

NoExplicitTypeError: Unable to infer GraphQL type from TypeScript reflection system. You need to provide explicit type for 'auth' of 'AdminAuthResponse' class.
    at Object.findType (/Users/xxx/Projects/boilerplate/apps/server/dist/server.js:69362:15)
    at /Users/xxx/Projects/boilerplate/apps/server/dist/server.js:69767:53
    at __decorateClass (/Users/xxx/Projects/boilerplate/apps/server/dist/server.js:34:25)
    at Object.<anonymous> (/Users/xxx/Projects/boilerplate/apps/server/dist/server.js:246548:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Module.load (node:internal/modules/cjs/loader:1033:32)
    at Function.Module._load (node:internal/modules/cjs/loader:868:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47

The mentioned AdminAuthResponse class:

@ObjectType()
export class Authentication {
  @Field(() => String, { nullable: true })
  token: string | null;

  @Field(() => Date, { nullable: true })
  expiresAt: Date | null;
}

@ObjectType()
export class AdminAuthResponse {
  @Field()
  auth: Authentication;

  @Field(() => Admin, { nullable: true })
  admin: Admin | null;
}

Admin here is a type generated from typegraphql-prisma but seems like auth: Authentication is the problem

@MichalLytek
Copy link
Owner Author

@nephix

@Field(() => Authentication)
auth: Authentication;

@nephix
Copy link

nephix commented Jan 29, 2023

Thanks @MichalLytek !

Second iteration would invole detecting when the type info could be ommited, so that we will reduce the ammout of emitted code, that could speed up and save some space when using bundlers.

Would some of that duplication go away with that or is that only about the emitted code?

Or is TypeScript v5 going to help with this? (microsoft/TypeScript#50820)

@MichalLytek
Copy link
Owner Author

I think TypeScript v5 won't solve esbuild lack of types metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants