Reputation: 63
I'm studying GraphQL with TypeGraphQL + Typescript. It has a little bit of beauty but I'm getting some trouble with rules of typing.
So, I have the code below:
@Resolver(CountryInfo)
export class StaticDataResolver {
@Query(_returns => [CountryInfo])
allcountries(@Arg("arg") arg: string) {
console.log(arg)
}
@Query(_returns => [CompleteCountryInfo])
countryDetails(@Arg("countryId") countryId: string) {
console.log(countryId)
}
@Query(_returns => [StateInfo])
statesOfCountry(@Arg("countryId") countryId: string){
console.log(countryId)
}
}
When I run the server I get the error:
F:\github\places-api\node_modules\type-graphql\dist\helpers\findType.js:10
metadataDesignType = reflectedType[parameterIndex];
^
TypeError: Cannot read property '0' of undefined
at Object.findType (F:\github\places-api\node_modules\type-graphql\dist\helpers\findType.js:10:43)
at Object.getParamInfo (F:\github\places-api\node_modules\type-graphql\dist\helpers\params.js:9:49)
at F:\github\places-api\node_modules\type-graphql\dist\decorators\Arg.js:9:159
at F:\github\places-api\src\graphql\resolvers\static-data.resolver.ts:9:37
at DecorateProperty (F:\github\places-api\node_modules\reflect-metadata\Reflect.js:553:33)
at Object.decorate (F:\github\places-api\node_modules\reflect-metadata\Reflect.js:123:24)
at __decorate (F:\github\places-api\src\graphql\resolvers\static-data.resolver.ts:4:92)
at Object.<anonymous> (F:\github\places-api\src\graphql\resolvers\static-data.resolver.ts:12:5)
at Module._compile (internal/modules/cjs/loader.js:1158:30)
at Module.m._compile (F:\github\places-api\node_modules\ts-node\src\index.ts:806:23)
I don't know what's wrong with my code, so if anyone has the answer it'll be welcome! =]
Upvotes: 3
Views: 1044
Reputation: 11
Try to set emitDecoratorMetadata: true
in your tsconfig.json
.
It helped me resolve this trouble.
Upvotes: 1
Reputation: 12107
Looks like you are using babel without proper TypeScript metadata reflections plugin.
Please checkout this issue: https://github.com/MichalLytek/type-graphql/issues/55
Upvotes: 0