Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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. 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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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[];
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading