I have a user entity that is suppose to contain an array of json objects, but I couldn't find a json array type for typeorm to store natively, and I'm not sure how to store them in the database using typeorm.
The current setup works with typegraphql but it's the typeorm I'm confused about.
My user entity roughly looks like this:
User.ts
import { Entity, PrimaryGeneratedColumn, Column, BaseEntity, ManyToOne } from "typeorm";
import { Field, Int, ObjectType, ID } from "type-graphql";
**//THIS ENTITY**
@ObjectType()
export class Softwares {
@Field(() => Number)
id: number;
@Field()
category: string;
@Field(() => [String])
list: string[];
}
@ObjectType()
export class About {
@Field( { nullable: true } )
@Column("text", { nullable: true })
about_header_message: string;
**//THIS PART**
@Field(() => [Softwares], { nullable: true })
softwares: Softwares[];
@Field(() => [[String]], { nullable: true })
@Column("text", { nullable: true, array: true })
info: string[][];
}
@ObjectType()
@Entity()
export class User extends BaseEntity {
@Field(() => ID)
@PrimaryGeneratedColumn()
id: number;
@Field({ nullable: true })
@Column("text", { nullable: true })
title_name: string;
@Field({ nullable: true })
@Column("text", { nullable: true })
first_name: string;
@Field({ nullable: true })
@Column("text", { nullable: true })
last_name: string;
@Field((type) => About)
@Column(() => About)
about: About;
}
Note that the About class is inherited into the normal user entity. I did this because my final GraphQL on a get request should look something like this :
{
title_name: "Sky Johnson",
first_name: "Sky",
last_name: "Johnson",
about: {
about_header_message: "A passionate developer, artist, and photographer",
info: [
["University", "University of Colorado Boulder - Cumulative GPA: 3.376"],
["Graduation", "May Class of 2020"],
["Degree", "Computer Science (BS) - Degree GPA: 3.514"],
["2nd Degree", "Creative Technology and Design (BS) - Degree GPA: 3.657"],
["Minor", "Applied Mathematics: Theoretical Statistics"],
["Languages", "English: Native", "日本語:~N4 University Experience"],
],
softwares: [
{
id: 1,
category: "Favorite Languages",
list: [
"C# + Unity",
"Python",
"Java",
"Scala",
"Javascript/Typescript",
"C/C++ (limited)",
"Processing/Arduino",
"OpenSCAD",
],
},
{
id: 2,
category: "Python Libraries",
list: [
"Tensor Flow",
"MatPlotLib",
"NetworkX",
"Seaborn",
"SciKit",
"Keras",
],
},
],
},
};
I tried using a ManyToOne relation in typeorm on the softwares field in the about type, but I couldn't get it to work since I think the inherited nature of the about class on User is messing it up (since one user can have many softwares objects, but the list of softwares is in the about entity).
If anyone has any ideas that would help a lot. Thanks!