如何访问 nestjs 中的 graphql 字段名称?
How to access graphql field name in nestjs?
我正在尝试访问以下输入中字段装饰器的名称值。
//myInput.ts
@InputType()
export class MyInput {
@Field(() => Int, { name: "price" })
priceValue: number;
}
//myResolver.ts
@Resolver()
export class MyResolver {
constructor(private readonly myService: MyService){}
@Query(() => boolean)
async prices(@Args('input') input: MyInput){
/*
So in typescript system the input field is named `priceValue` but in the
graphql side is named `price` (This is the string i want to access)
*/
}
}
我尝试了各种方法,例如 @Info()
装饰器和 TypeMetadaStorage
,但我找不到重命名值。
是否有访问此字段的解决方法?
我找到了一种使用 TypeMetadataStorage 方法 getArgumentsMetadataByTarget(MyInput) 的方法;
const schemaNames = TypeMetadataStorage.getArgumentsMetadataByTarget(MyInput).properties.map(({ schemaName }) => schemaName);
我正在尝试访问以下输入中字段装饰器的名称值。
//myInput.ts
@InputType()
export class MyInput {
@Field(() => Int, { name: "price" })
priceValue: number;
}
//myResolver.ts
@Resolver()
export class MyResolver {
constructor(private readonly myService: MyService){}
@Query(() => boolean)
async prices(@Args('input') input: MyInput){
/*
So in typescript system the input field is named `priceValue` but in the
graphql side is named `price` (This is the string i want to access)
*/
}
}
我尝试了各种方法,例如 @Info()
装饰器和 TypeMetadaStorage
,但我找不到重命名值。
是否有访问此字段的解决方法?
我找到了一种使用 TypeMetadataStorage 方法 getArgumentsMetadataByTarget(MyInput) 的方法;
const schemaNames = TypeMetadataStorage.getArgumentsMetadataByTarget(MyInput).properties.map(({ schemaName }) => schemaName);