[英]How to create more complex types in graphql using code first approach
Hello I'm trying to create field
for mutation which is array of objects.您好,我正在尝试为突变创建
field
,该字段是对象数组。 Code looks like this:代码如下所示:
import { Field, InputType } from '@nestjs/graphql';
type ChainToAddress = {
chain: string;
address: string;
};
@InputType()
export class CreateONSInput {
@Field()
ons: string;
@Field(type => [ChainToAddress])
chainAddressess: ChainToAddress;
}
Currently is throwing following error:目前正在抛出以下错误:
'ChainToAddress' only refers to a type, but is being used as a value here.
Any idea how to make it work, tried with interfaces / type but somehow not able to manage it知道如何使其工作,尝试使用接口/类型,但不知何故无法管理它
You need to create an InputType
/ ObjectType
out of your nested interface to make it work.您需要在嵌套接口之外创建一个
InputType
/ ObjectType
才能使其工作。
@InputType()
class ChainToAddress {
@Field()
chain: string;
@Field()
address: string;
};
@InputType()
export class CreateONSInput {
@Field()
ons: string;
@Field(type => [ChainToAddress])
chainAddressess: ChainToAddress[];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.