Hello I’m trying to create field for mutation which is array of objects. 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
>Solution :
You need to create an InputType/ObjectType out of your nested interface to make it work.
@InputType()
class ChainToAddress {
@Field()
chain: string;
@Field()
address: string;
};
@InputType()
export class CreateONSInput {
@Field()
ons: string;
@Field(type => [ChainToAddress])
chainAddressess: ChainToAddress[];
}