【问题标题】:Possible reflection Issues with type-graphql mutations?可能的反思 type-graphql 突变的问题?
【发布时间】:2020-07-03 12:01:41
【问题描述】:

我一直在尝试在最近的 nodejs 项目中使用type-graphql。我已经能够成功实现@Query 方法,但我一生都无法让以下工作。我正在将它与 Molecler 服务一起使用。

@Mutation()
  // eslint-disable-next-line class-methods-use-this
  removeValue((@Arg("value") value: number): void {
    console.log(value);
  } 

我收到以下错误

/home/micro-api/node_modules/type-graphql/dist/helpers/findType.js:10
 metadataDesignType = reflectedType[parameterIndex];
                                          ^
/home/micro-api/node_modules/type-graphql/dist/helpers/findType.js:1
TypeError: Cannot read property '0' of undefined

有什么想法吗?我看到一些 cmets 在我的搜索中提到了反射,但由于我对 node 和 typescript 还很陌生,所以我有点卡住了。

【问题讨论】:

标签: typescript graphql typegraphql


【解决方案1】:

我认为您面临的问题是突变(或查询)不应返回任何内容,也不应返回 void。请查看https://github.com/MichalLytek/type-graphql/issues/318

一个简单的补丁可以是:

@Mutation(() => Boolean)  
removeValue((@Arg("value") value: number): boolean {
    console.log(value);
    return true;
} 

【讨论】:

    猜你喜欢
    • 2019-05-29
    • 2019-07-20
    • 2020-10-08
    • 2020-02-03
    • 2018-07-26
    • 2020-09-26
    • 2020-11-11
    • 2020-02-14
    • 2019-01-23
    相关资源
    最近更新 更多