type-graphql#ObjectType TypeScript Examples

The following examples show how to use type-graphql#ObjectType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: product.filter.ts    From Cromwell with MIT License 6 votes vote down vote up
@ObjectType('FilteredProduct')
export class FilteredProduct implements TFilteredProductList {
    @Field(() => PagedMeta, { nullable: true })
    pagedMeta?: PagedMeta;

    @Field(() => [Product], { nullable: true })
    elements?: Product[];

    @Field(() => ProductFilterMeta)
    filterMeta: TProductFilterMeta;
}
Example #2
Source File: BuildFlashFirmwareResult.ts    From ExpressLRS-Configurator with GNU General Public License v3.0 6 votes vote down vote up
@ObjectType('BuildFlashFirmwareResult')
export default class BuildFlashFirmwareResult {
  @Field()
  success: boolean;

  @Field(() => BuildFirmwareErrorType, { nullable: true })
  errorType?: BuildFirmwareErrorType;

  @Field({ nullable: true })
  message?: string;

  @Field({ nullable: true })
  firmwareBinPath?: string;

  constructor(
    success: boolean,
    message?: string,
    errorType?: BuildFirmwareErrorType,
    firmwareBinPath?: string
  ) {
    this.success = success;
    this.errorType = errorType;
    this.message = message;
    this.firmwareBinPath = firmwareBinPath;
  }
}
Example #3
Source File: type.ts    From typegraphql-nestjs with MIT License 6 votes vote down vote up
@ObjectType()
@InputType("RecipeInput")
export default class Recipe {
  @Field()
  title!: string;

  @Field({ nullable: true })
  description?: string;
}
Example #4
Source File: Me.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@ObjectType()
export class Me {
  @Field({ name: "id" })
  _id: ObjectID;

  @Field()
  public name!: string;

  @Field()
  public username!: string;

  @Field()
  public email!: string;

  @Field()
  public avatarUrl!: string;

  @Field(() => [Room])
  public rooms!: Ref<Room>[];

  @Field()
  public color!: string;

  @Field(() => UserLinks, { nullable: true })
  public links?: UserLinks;
}
Example #5
Source File: Department.ts    From graphql-ts-client with MIT License 6 votes vote down vote up
@ObjectType({implements: Node})
export class Department extends Node {

    @Field(() => String)
    readonly name: string;

    constructor(row: TDepartment) {
        super(row.id);
        this.name = row.name;
    }

    @Field(() => [Employee])
    employees(): Employee[] {
        return employeeTable
            .findByProp("departmentId", this.id)
            .map(row => new Employee(row));
    }

    @Field(() => Float)
    avgSalary(): number {
        const arr = employeeTable
            .findByProp("departmentId", this.id)
            .map(row => row.salary);
        return arr.length !== 0 ?
            arr.reduce((p, c) => p + c, 0) / arr.length :
            0;
    }
}
Example #6
Source File: User.ts    From lireddit with MIT License 6 votes vote down vote up
@ObjectType()
@Entity()
export class User extends BaseEntity {
  @Field()
  @PrimaryGeneratedColumn()
  id!: number;

  @Field()
  @Column({ unique: true })
  username!: string;

  @Field()
  @Column({ unique: true })
  email!: string;

  @Column()
  password!: string;

  @OneToMany(() => Post, (post) => post.creator)
  posts: Post[];

  @OneToMany(() => Updoot, (updoot) => updoot.user)
  updoots: Updoot[];

  @Field(() => String)
  @CreateDateColumn()
  createdAt: Date;

  @Field(() => String)
  @UpdateDateColumn()
  updatedAt: Date;
}
Example #7
Source File: ChatCategory.object.ts    From bouncecode-cms with GNU General Public License v3.0 6 votes vote down vote up
/**
 * {@link TestResolver} 에서 반환되는 데이터를 확인하기위한 ObjectType 입니다.
 *
 * @author BounceCode, Inc.
 */
@ObjectType()
export class ChatCategoryObject {
  @Field()
  id: number;

  @Field()
  title: string;

  @Field()
  description: string;

  @Field(() => GraphQLJSON)
  payload: any;

  @Field()
  version: number;

  @Field()
  createdDate: Date;

  @Field()
  updatedDate: Date;
}
Example #8
Source File: UserAccount.ts    From Wern-Fullstack-Template with MIT License 6 votes vote down vote up
@ObjectType()
@Entity()
export class UserAccount extends BaseEntity {
  @Field()
  @PrimaryGeneratedColumn()
  id!: number

  @Field()
  @Column({ unique: true })
  username!: string

  @Field()
  @Column({ unique: true })
  email!: string

  @Column()
  password!: string

  @Field(() => String)
  @CreateDateColumn()
  createdAt: Date

  @Field(() => String)
  @UpdateDateColumn()
  updatedAt: Date
}
Example #9
Source File: fields.ts    From backend with MIT License 6 votes vote down vote up
@ObjectType()
class MatchPool {
    @Field()
    name: string;
    @Field({ nullable: true })
    automatic?: MatchPoolAutomatic;
    @Field(type => [String])
    toggles: string[];
}
Example #10
Source File: author.entity.ts    From mikro-orm-graphql-example with MIT License 6 votes vote down vote up
@ObjectType()
@Entity()
export class Author extends Base<Author> {
  @Field()
  @Property()
  public name: string;

  @Field()
  @Property()
  @Unique()
  public email: string;

  @Property()
  public termsAccepted = false;

  @Field({ nullable: true })
  @Property({ nullable: true })
  public born?: Date;

  @Field(() => [Book])
  @OneToMany(() => Book, (b: Book) => b.author, { cascade: [Cascade.ALL] })
  public books = new Collection<Book>(this);

  @Field(() => Book, { nullable: true })
  @ManyToOne(() => Book, { nullable: true })
  public favouriteBook?: Book;

  constructor(body: AuthorValidator) {
    super(body);
  }
}
Example #11
Source File: comment.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ObjectType()
export class Comment {
  @Field((type) => Int)
  id: number

  @Field()
  createdAt: Date

  @Field()
  updatedAt: Date

  @Field()
  content: string

  @Field((type) => Int)
  authorId: number

  @Field((type) => Int, { nullable: true })
  parentId: number

  @Field((type) => Int)
  topicId: number
}
Example #12
Source File: GrowMap.ts    From liferay-grow with MIT License 6 votes vote down vote up
@ObjectType()
@Entity()
export class GrowMap extends MainEntity {
  @Field(() => [KnowledgeSkillDetails], { nullable: true })
  @JoinTable({ name: 'grow_map_knowledge_skill_details' })
  @ManyToMany(() => KnowledgeSkillDetails, { onDelete: 'CASCADE' })
  knowledgeSkillDetails: KnowledgeSkillDetails[];

  @Field(() => [KnowledgeGapsDetails], { nullable: true })
  @JoinTable({ name: 'grow_map_knowledge_gaps_details' })
  @ManyToMany(() => KnowledgeGapsDetails, { onDelete: 'CASCADE' })
  knowledgeGapsDetails: KnowledgeGapsDetails[];

  @Field(() => UserDetails)
  @OneToOne(() => UserDetails)
  @JoinColumn()
  userDetails: UserDetails;

  @Field(() => User)
  @OneToOne(() => User)
  @JoinColumn()
  user: User;
}
Example #13
Source File: testSchemaTypeGraphql.ts    From ra-data-prisma with MIT License 6 votes vote down vote up
@ObjectType()
class Address {
  @Field()
  street: string;

  @Field()
  city: string;

  @Field()
  countryCode: string;
}
Example #14
Source File: ApplicationSoftware.ts    From type-graphql-dataloader with MIT License 6 votes vote down vote up
@ObjectType()
@Entity()
export class ApplicationSoftware extends Base<ApplicationSoftware> {
  @Field()
  @PrimaryColumn()
  name: string;

  @Field()
  @PrimaryColumn()
  majorVersion: number;

  @Field()
  @PrimaryColumn()
  minorVersion: number;

  @Field((type) => [PersonalComputer])
  @ManyToMany((type) => PersonalComputer, (pc) => pc.installedApps)
  @TypeormLoader()
  installedComputers: PersonalComputer[];

  @Field((type) => Company)
  @ManyToOne((type) => Company, (company) => company.publishedApps, {
    lazy: true,
  })
  @TypeormLoader()
  publishedBy: Lazy<Company>;
}
Example #15
Source File: resolvers.ts    From squid with GNU General Public License v3.0 6 votes vote down vote up
@ObjectType({simpleResolvers: true})
export class ScalarRow {
    @Field({nullable: false})
    id!: string

    @Field()
    bool?: boolean

    @Field()
    date?: Date

    @Field()
    bigNumber?: bigint

    @Field()
    bytes?: Buffer

    @Field(() => Json)
    attributes?: any
}
Example #16
Source File: meta.ts    From Koa-GraphQL-Template with MIT License 6 votes vote down vote up
@ObjectType()
export class Meta {
    @Field({ description: '创建时间' })
    @prop({ default: Date.now() })
    public createdAt!: number;

    @Field({ description: '更新时间' })
    @prop({ default: Date.now() })
    public updatedAt!: number;
}
Example #17
Source File: create-generic-entity.ts    From Cromwell with MIT License 5 votes vote down vote up
@ObjectType(`Paged${entityName}`)
    class PagedEntity implements TPagedList<EntityType> {
        @Field(() => PagedMeta, { nullable: true })
        pagedMeta?: PagedMeta;

        @Field(() => [EntityClass], { nullable: true })
        elements?: EntityType[];
    }