How to use Unions when creating Input types, Mutations in nest graphql schema, by code first approach

Viewed 1984

I am doing code-first approach in typescript for a class (MyClass) that contains Union as one of the attribute types. I used @ObjectType() and @InputType() , @Field(type => myUnion) decorators.

I defined a graphql type for myUnion using createUnionType from https://docs.nestjs.com/graphql/unions-and-enums. When schema.gql is autogenerated, I see type for myUnion, MyClass but not input for MyClass. Is there a way to create Input Types and Mutations for a class with union types using nest-graphql ?

Note: I have no issues, with ObjectType() or Query(), but input types are not getting generated.

What is the best way to use unions.

1 Answers
Related