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

@Root should support returnTypeFunction #889

Closed
alex-kinokon opened this issue May 19, 2021 · 8 comments
Closed

@Root should support returnTypeFunction #889

alex-kinokon opened this issue May 19, 2021 · 8 comments
Labels
Community 👨‍👧 Something initiated by a community Out of scope ✖️ Proposal doesn't fit in project goals

Comments

@alex-kinokon
Copy link

Is your feature request related to a problem? Please describe.
I’m using esbuild with type-graphql so I need to annotate types explicitly. Most decorators allow the pattern of providing a class factory such as () => [Recipe] in case emitDecoratorMetadata doesn’t emit enough information, but not @Root.

Describe the solution you’d like
@Root(() => Recipe) should be supported.

Describe alternatives you’ve considered
Manually importing __metadata from tslib and annotate the type with a decorator myself.

Additional context
N/A

@alex-kinokon
Copy link
Author

I have a working fork that implements this. Let me know if you are interested in a pull request.

@MichalLytek
Copy link
Owner

returnTypeFunction is used to provide type info for GraphQL schema.

Root is not visible or reflected in the schema. It's just the object you return from resolvers (queries and mutations). Hence there's completely no need to provide info which won't be used anywhere 😝

You can put whatever type you need as a type of @Root argument, it's not used for schema building.

I have a working fork that implements this.

Now I wonder what do you do with those type info 😅

@MichalLytek MichalLytek added Community 👨‍👧 Something initiated by a community Out of scope ✖️ Proposal doesn't fit in project goals labels May 20, 2021
@alex-kinokon
Copy link
Author

@MichalLytek The problem is @Root() will throw if there is no parameter metadata for the decorated method. If it’s not used, then it shouldn’t check the type.

@MichalLytek
Copy link
Owner

You mean all the types are erased? So how the decorators works at all in your setup?

Please refer to #55 to get more details how to configure babel, webpack and other tools.

@alex-kinokon
Copy link
Author

Decorators and type metadata are two separate things. esbuild supports transforming decorators but not type metadata. I annotate all types manually. Anyway the point is, if it doesn’t need the type information, it shouldn’t ask for it.

@MichalLytek
Copy link
Owner

MichalLytek commented May 21, 2021

@proteriax TypeGraphQL is designed to work with TypeScript. JS support is not official and you need some workaround and plugins to make it work, as stated in #55.

Anyway the point is, if it doesn’t need the type information, it shouldn’t ask for it.

The root type info is used to create an instance of the object type class.

@alex-kinokon
Copy link
Author

I’m confused. You first said

info which won't be used anywhere

but also

The root type info is used to create an instance of the object type class.

So does @Root() require runtime type information of the parameter it is decorating?

@MichalLytek
Copy link
Owner

returnTypeFunction is used to override reflected type to be used in schema. Root is not displayed in schema, hence it doesn't have returnTypeFunction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community 👨‍👧 Something initiated by a community Out of scope ✖️ Proposal doesn't fit in project goals
Projects
None yet
Development

No branches or pull requests

2 participants