title: How to return the entity with it's relations after saving it?
body: <p>I am building a storage application, with GraphQL as the backend, using Typegraphql and TypeORM.</p>
  <p>The categories need to be added separately and then when adding a product, you choose from a dropdown one of the available categories. This in turn passes the categoryId to the product in a one-to-many/many-to-one relationship.</p>
  <p>Here is my Category entity:</p>
  <pre><code>import {
    Entity,
    PrimaryColumn,
    Column,
    BaseEntity,
    Generated,
    OneToMany
  } from 'typeorm';
  import Product from './Product';
  
  @ObjectType()
  @Entity('categories')
  export default class Category extends BaseEntity {
    @Field()
    @PrimaryColumn()
    @Generated('uuid')
    categoryId: string;
  
    @Field()
    @Column()
    categoryName: string;
  
    @OneToMany(() =&gt; Product, (product: Product) =&gt; product.category)
    products: Product[];
  }
  </code></pre>
  <p>and here is my Product entity</p>
  <pre><code>import {
    Entity,
    PrimaryColumn,
    Column,
    BaseEntity,
    Generated,
    ManyToOne,
    JoinColumn
  } from 'typeorm';
  import Category from './Category';
  
  @ObjectType()
  @Entity('products')
  export default class Product extends BaseEntity {
    @Field()
    @PrimaryColumn()
    @Generated('uuid')
    productID: string;
  
    @Field()
    @Column()
    productName: string;
  
    @Field(() =&gt; Category)
    @ManyToOne(() =&gt; Category, (category: Category) =&gt; category.products, {
      cascade: true,
      lazy: true
    })
    @JoinColumn()
    category: Category;
  
    @Field()
    @Column()
    productQuantity: number;
  
    @Field()
    @Column({ type: 'decimal', precision: 2 })
    productPrice: number;
  
    @Field()
    @Column({ type: 'decimal', precision: 2 })
    productPriceRA: number;
  
    @Field()
    @Column({ type: 'decimal', precision: 2 })
    productPriceKK: number;
  
    @Field()
    @Column('varchar', { length: 255 })
    productSupplier: string;
  
    @Field()
    @Column('varchar', { length: 255 })
    productOrderLink: string;
  
    @Field()
    @Column('longtext')
    productImage: string;
  }
  </code></pre>
  <p>For the save mutation, I've created an Input type as well:</p>
  <pre><code>export default class ProductInput implements Partial&lt;Product&gt; {
      @Field()
      productName: string;
  
      @Field(() =&gt; String)
      category: Category;
  
      @Field()
      productQuantity: number;
  
      @Field()
      productPrice: number;
  
      @Field()
      productPriceRA: number;
  
      @Field()
      productPriceKK: number;
  
      @Field()
      productSupplier: string;
  
      @Field()
      productOrderLink: string;
  
      @Field()
      productImage: string;
  }
  </code></pre>
  <p>The relations work, as I am able to query the products, along with their category data with the following query:</p>
  <pre><code>{
    getProducts {
      productID
      productName
      category {
         categoryId
         categoryName
      }
    }
  }
  </code></pre>
  <p>However, when saving a product it always returns
  <code> &quot;message&quot;: &quot;Cannot return null for non-nullable field Category.categoryName.&quot;</code></p>
  <p>This is the Mutation's code in the Resolver:</p>
  <pre><code>@Mutation(() =&gt; Product, { description: 'Add new product' })
    async addProduct(
      @Arg('product') productInput: ProductInput
    ): Promise&lt;Product | any&gt; {
      try {
        const product = await Product.create(productInput).save();
  
        console.log('product: ', product);
        return product;
      } catch (error) {
        return error;
      }
    }
  </code></pre>
  <p>I've been trying different things, however nothing seems to work and I am wondering if it's even possible to directly return the entity with it's relations. If it's not, the other option I can think of is to return true/false based on the result and re-query all of the data. But this seems very inefficient and I am actively trying to avoid going this route.</p>
  <p>Any help will be much appreciated.</p>