-
-
Notifications
You must be signed in to change notification settings - Fork 676
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
TypeError: Reflect.getMetadata is not a function #21
Comments
Hi @4F2E4A2E!
You can see this in the examples on the repo too: |
doh! Of course i forgot about the reflect-metadata import, sorry for that. The minimal example worked just fine. @GraphQLObjectType()
export interface Recipe {
@Field(type => ID)
readonly id: string;
@Field()
title: string;
@Field({nullable: true})
description?: string;
@Field({nullable: true})
averageRating?: number;
} |
No, interfaces are removed at compilation so they doesn't exist at runtime. However you can just use abstract classes as interfaces 😉 @GraphQLObjectType()
export abstract class IRecipe {
@Field(type => ID)
readonly id: string;
@Field()
title: string;
@Field({nullable: true})
description?: string;
@Field({nullable: true})
averageRating?: number;
}
class SpecialRecipe implements IRecipe {
// impl...
} |
It's working fine this way. I still will pursue a way to automatise it in order to not be invasive with the already declared interface types. |
|
Thank you for that info, i will do exactly that! |
Because interfaces doesn't exist in JS (runtime) so they are removed on TypeScript compilation step. So when the app starts, I'm not able to figure out what is the type, what fields does it have, etc. so there's no way to generate the schema with GQL types from interfaces. The only way is to use classes and decorators to collect metadata emitted by TypeScript compiler, just the way TypeORM or class-validiator works. Or create an "offline" code generator that will read the source and comments, just like I am closing this issue as the main problem is solved. If you want to know more details about types reflection we can discuss on gitter 😉 |
Hi there 👋
I've posted this question on the apollo slack #general and after looking up and testing all projects related to this on github I finally stumble upon this amazing project. I am very hopeful on this one.
Our project have a lot of types definitions written in typescript as interfaces, so reusing them would be a great benefit in terms of time, reusability, type safety ,stability and greatness :)
So thank you for maintaining this 👍
Still, I am having a hard time trying to get a minimal viable example working.
ts-node -O '{"module": "commonjs"}' test.ts
Any help would be much appreciated.
The text was updated successfully, but these errors were encountered: