【问题标题】:Can I change the type of args from graphql's resolver to id?我可以将 args 的类型从 graphql 的解析器更改为 id 吗?
【发布时间】:2021-09-02 04:32:11
【问题描述】:

我想在查询中更改 graphql 的 ID 类型。有可能吗?

id: 编号 ==> id: ID

@Resolver()
export class LocationResolver {
    constructor(private readonly locationService: LocationService) {}

    @Query(() => Location_Group)
    async locationGroup(@Args('id') id: number): Promise<Location_Group> {
        return await this.locationService.getLocationGroup(id);
    }
}

【问题讨论】:

  • 我解决了。 @Args('id', { type: () => ID }) id: number
  • 您可以发布答案以帮助其他人吗?谢谢!

标签: graphql nestjs typeorm


【解决方案1】:

这是我的答案:

@Query(() => Location)
async location(
    @Args('id', { type: () => ID }) id: number
): Promise<Location> {
    return await this.locationService.findLocation(id);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-12
    • 2021-01-23
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-05
    • 2014-09-20
    相关资源
    最近更新 更多