Typescript TypeGraphQL:metadataDesignType=reflectedType[parameterIndex]类型错误:无法读取属性';0';未定义的
我正在用TypeGraphQL+Typescript学习GraphQL。它有点美,但我在打字规则方面遇到了一些麻烦 因此,我有以下代码:Typescript TypeGraphQL:metadataDesignType=reflectedType[parameterIndex]类型错误:无法读取属性';0';未定义的,typescript,graphql,typegraphql,Typescript,Graphql,Typegraphql,我正在用TypeGraphQL+Typescript学习GraphQL。它有点美,但我在打字规则方面遇到了一些麻烦 因此,我有以下代码: @Resolver(CountryInfo) export class StaticDataResolver { @Query(_returns => [CountryInfo]) allcountries(@Arg("arg") arg: string) { console.log(arg) } @
@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)
}
}
当我运行服务器时,会出现以下错误:
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)
F:\github\places api\node\u modules\type graphql\dist\helpers\findType.js:10
metadataDesignType=反射类型[参数索引];
^
TypeError:无法读取未定义的属性“0”
在Object.findType(F:\github\places api\node\u modules\type graphql\dist\helpers\findType.js:10:43)
在Object.getParamInfo(F:\github\places api\node\u modules\type graphql\dist\helpers\params.js:9:49)
在F:\github\places api\node\u modules\type graphql\dist\decorators\Arg.js:9:159
在F:\github\places api\src\graphql\resolvers\static data.resolver.ts:9:37
在DecorateProperty(F:\github\places api\node\u modules\reflect metadata\reflect.js:553:33)
在Object.decoration(F:\github\places api\node\u modules\reflect metadata\reflect.js:123:24)
位于(F:\github\places api\src\graphql\resolvers\static data.resolver.ts:4:92)
反对。(F:\github\places api\src\graphql\resolvers\static data.resolver.ts:12:5)
at模块编译(内部/modules/cjs/loader.js:1158:30)
在Module.m.处编译(F:\github\places api\node\u modules\ts node\src\index.ts:806:23)
我不知道我的代码出了什么问题,所以如果有人知道答案,我将非常欢迎!=] 看起来您在使用babel时没有使用正确的TypeScript元数据反射插件 请检查此问题:
尝试在
tsconfig.json
中设置emitDecoreTata:true
。
它帮助我解决了这个问题