type-graphql#ArgsType TypeScript Examples

The following examples show how to use type-graphql#ArgsType. 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: message-inputs.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export class editMessageArgs {
  @Field({ nullable: false })
  messageId: ObjectID;

  @Field({ nullable: false })
  @Length(2, 500)
  content: string;
}
Example #2
Source File: topic.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ArgsType()
class TopicsArgs {
  @Field((type) => Int, {
    defaultValue: 100,
  })
  take: number

  @Field((type) => Int, {
    defaultValue: 1,
  })
  page: number
}
Example #3
Source File: comment.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ArgsType()
class CommentsArgs {
  @Field((type) => Int)
  topicId: number

  @Field((type) => Int, {
    defaultValue: 100,
  })
  take: number

  @Field((type) => Int, {
    defaultValue: 1,
  })
  page: number

  @Field((type) => SORT_ORDER, { defaultValue: 'asc' })
  order: 'desc' | 'asc'
}
Example #4
Source File: comment.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ArgsType()
class CreateCommentArgs {
  @Field((type) => Int)
  topicId: number

  @Field()
  content: string

  @Field((type) => Int, {
    nullable: true,
  })
  parentId?: number
}
Example #5
Source File: user.inputs.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export class setUserLinksArgs {
  @Field({ nullable: true })
  @Length(5, 100)
  @Matches(githubUsernameRegex, { message: "Invalid Github username" })
  public github?: string;

  @Field({ nullable: true })
  @Length(5, 100)
  @Matches(twitterUsernameRegex, { message: "Invalid Twitter username" })
  public twitter?: string;

  @Field({ nullable: true })
  @Matches(instagramUsernameRegex, { message: "Invalid Instagram Link" })
  @Length(5, 150)
  public instagram?: string;

  @Field({ nullable: true })
  @Length(5, 100)
  @IsUrl(
    {
      disallow_auth: true,
      allow_protocol_relative_urls: false,
    },
    { message: "Invalid website URL" }
  )
  public website?: string;
}
Example #6
Source File: topic.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ArgsType()
class CreateTopicArgs {
  @Field()
  title: string

  @Field()
  content: string

  @Field({ nullable: true })
  url?: string
}
Example #7
Source File: topic.resolver.ts    From hakka with MIT License 6 votes vote down vote up
@ArgsType()
class UpdateTopicArgs {
  @Field((type) => Int)
  id: number

  @Field({ nullable: true })
  title?: string

  @Field({ nullable: true })
  content?: string

  @Field((type) => Int, { nullable: true })
  nodeId?: number
}
Example #8
Source File: message-inputs.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export class getMessagesArgs {
  @Field({ nullable: false })
  roomId: ObjectID;

  @Field(type => Int)
  limit: number;

  @Field({ nullable: true })
  before: string;

  @Field({ nullable: true })
  after: string;
}
Example #9
Source File: message-inputs.ts    From convoychat with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export class sendMessageArgs {
  @Field({ nullable: false })
  roomId: ObjectID;

  @Field({ nullable: false })
  @Length(2, 500)
  content: string;
}
Example #10
Source File: TargetDeviceOptions.ts    From ExpressLRS-Configurator with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export default class TargetDeviceOptionsArgs {
  @Field()
  target: string;

  @Field(() => FirmwareSource)
  source: FirmwareSource;

  @Field()
  gitTag: string;

  @Field()
  gitBranch: string;

  @Field()
  gitCommit: string;

  @Field()
  localPath: string;

  @Field(() => PullRequest)
  gitPullRequest: PullRequest | null;

  constructor() {
    this.source = FirmwareSource.GitBranch;
    this.target = 'DIY_2400_TX_ESP32_SX1280_E28_via_UART';
    this.gitTag = '';
    this.gitBranch = '';
    this.gitCommit = '';
    this.localPath = '';
    this.gitPullRequest = null;
  }
}
Example #11
Source File: Target.ts    From ExpressLRS-Configurator with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export default class TargetArgs {
  @Field(() => FirmwareSource)
  source: FirmwareSource;

  @Field()
  gitTag: string;

  @Field()
  gitBranch: string;

  @Field()
  gitCommit: string;

  @Field()
  localPath: string;

  @Field(() => PullRequest)
  gitPullRequest: PullRequest | null;

  constructor() {
    this.source = FirmwareSource.GitBranch;
    this.gitTag = '';
    this.gitBranch = '';
    this.gitCommit = '';
    this.localPath = '';
    this.gitPullRequest = null;
  }
}
Example #12
Source File: Lua.ts    From ExpressLRS-Configurator with GNU General Public License v3.0 6 votes vote down vote up
@ArgsType()
export default class LuaArgs {
  @Field(() => FirmwareSource)
  source: FirmwareSource;

  @Field()
  gitTag: string;

  @Field()
  gitBranch: string;

  @Field()
  gitCommit: string;

  @Field()
  localPath: string;

  @Field(() => PullRequest)
  gitPullRequest: PullRequest | null;

  constructor() {
    this.source = FirmwareSource.GitBranch;
    this.gitTag = '';
    this.gitBranch = '';
    this.gitCommit = '';
    this.localPath = '';
    this.gitPullRequest = null;
  }
}
Example #13
Source File: student.ts    From Koa-GraphQL-Template with MIT License 6 votes vote down vote up
@ArgsType()
class StudentArgs {
    @Field({ description: '姓名', nullable: true })
    public name?: string;

    @Field({ description: '性别', nullable: true })
    public sex?: string; // 考虑用enum

    @Field({ description: '年龄', nullable: true })
    public age?: number;

    @Field({ description: 'infoid', nullable: true })
    public info?: string;
}
Example #14
Source File: user.inputs.ts    From convoychat with GNU General Public License v3.0 5 votes vote down vote up
@ArgsType()
export class setColorArgs {
  @Field({ nullable: false })
  @IsHexColor()
  @Validate(ValidateColor)
  color: string;
}
Example #15
Source File: topic.resolver.ts    From hakka with MIT License 5 votes vote down vote up
@ArgsType()
class LikeTopicArgs {
  @Field((type) => Int)
  topicId: number
}
Example #16
Source File: topic.resolver.ts    From hakka with MIT License 5 votes vote down vote up
@ArgsType()
class TopicByIdArgs {
  @Field((type) => Int)
  id: number
}
Example #17
Source File: user.resolver.ts    From hakka with MIT License 5 votes vote down vote up
@ArgsType()
class ProfileArgs {
  @Field()
  username: string
}
Example #18
Source File: comment.resolver.ts    From hakka with MIT License 5 votes vote down vote up
@ArgsType()
class LikeCommentArgs {
  @Field((type) => Int)
  commentId: number
}
Example #19
Source File: create-generic-entity.ts    From Cromwell with MIT License 5 votes vote down vote up
@ArgsType()
    class CreateArgs {
        @Field(() => InputEntityClass ?? String)
        data: EntityInputType;
    }
Example #20
Source File: room-inputs.ts    From convoychat with GNU General Public License v3.0 5 votes vote down vote up
@ArgsType()
export class removeMembersArgs {
  @Field(type => ObjectID, { nullable: false })
  roomId: ObjectID;

  @Field(type => ObjectID, { nullable: false })
  memberId: ObjectID;
}
Example #21
Source File: room-inputs.ts    From convoychat with GNU General Public License v3.0 5 votes vote down vote up
@ArgsType()
export class createRoomArgs {
  @Field({ nullable: false })
  @Length(2, 25)
  name: string;
}
Example #22
Source File: invitation-resolver.ts    From convoychat with GNU General Public License v3.0 5 votes vote down vote up
@ArgsType()
export class inviteMembersArgs {
  @Field({ nullable: false })
  roomId: ObjectID;

  @Field(() => [ObjectID])
  members: ObjectID[];
}
Example #23
Source File: create-generic-entity.ts    From Cromwell with MIT License 5 votes vote down vote up
@ArgsType()
    class UpdateArgs {
        @Field(() => Int)
        id: number;

        @Field(() => InputEntityClass ?? String)
        data: EntityInputType;
    }
Example #24
Source File: create-generic-entity.ts    From Cromwell with MIT License 4 votes vote down vote up
createGenericEntity = <EntityType, EntityInputType = EntityType>(entityName: string,
    EntityClass: new (...args: any[]) => EntityType,
    InputEntityClass?: new (...args: any[]) => EntityInputType) => {

    @EntityRepository(EntityClass)
    class GenericRepository extends BaseRepository<EntityType, EntityInputType> {
        constructor() {
            super(EntityClass)
        }
    }

    @ObjectType(`Paged${entityName}`)
    class PagedEntity implements TPagedList<EntityType> {
        @Field(() => PagedMeta, { nullable: true })
        pagedMeta?: PagedMeta;

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

    @ArgsType()
    class CreateArgs {
        @Field(() => InputEntityClass ?? String)
        data: EntityInputType;
    }

    @ArgsType()
    class UpdateArgs {
        @Field(() => Int)
        id: number;

        @Field(() => InputEntityClass ?? String)
        data: EntityInputType;
    }

    const getPagedPath = GraphQLPaths.Generic.getManyPaged + entityName;
    const getAllPath = GraphQLPaths.Generic.getMany + entityName;
    const getBySlugPath = GraphQLPaths.Generic.getOneBySlug + entityName;
    const getByIdPath = GraphQLPaths.Generic.getOneById + entityName;
    const createPath = GraphQLPaths.Generic.create + entityName;
    const updatePath = GraphQLPaths.Generic.update + entityName;
    const deletePath = GraphQLPaths.Generic.delete + entityName;
    const getFilteredPath = GraphQLPaths.Generic.getFiltered + entityName;

    @Resolver(EntityClass, { isAbstract: true })
    abstract class GenericResolver {

        private repository = getCustomRepository(GenericRepository)

        @Authorized<TAuthRole>("administrator", "guest", "author")
        @Query(() => PagedEntity)
        async [getPagedPath](@Arg("pagedParams") pagedParams: PagedParamsInput<EntityType>):
            Promise<TPagedList<EntityType>> {
            return this.repository.getPaged(pagedParams);
        }

        @Authorized<TAuthRole>("administrator", "guest", "author")
        @Query(() => [EntityClass])
        async [getAllPath](): Promise<EntityType[]> {
            return this.repository.getAll();
        }

        @Authorized<TAuthRole>("administrator", "guest", "author")
        @Query(() => EntityClass)
        async [getBySlugPath](@Arg("slug") slug: string): Promise<EntityType | undefined> {
            return this.repository.getBySlug(slug);
        }

        @Authorized<TAuthRole>("administrator", "guest", "author")
        @Query(() => EntityClass)
        async [getByIdPath](@Arg("id", () => Int) id: number): Promise<EntityType | undefined> {
            return this.repository.getById(id);
        }

        @Authorized<TAuthRole>("administrator", "guest", "author")
        @Query(() => PagedEntity)
        async [getFilteredPath](
            @Arg("pagedParams", () => PagedParamsInput, { nullable: true }) pagedParams?: PagedParamsInput<EntityType>,
            @Arg("filterParams", () => BaseFilterInput, { nullable: true }) filterParams?: BaseFilterInput,
        ): Promise<TPagedList<EntityType> | undefined> {
            return this.repository.getFilteredEntities(pagedParams, filterParams);
        }

        @Authorized<TAuthRole>("administrator")
        @Mutation(() => EntityClass)
        async [createPath](@Args() { data }: CreateArgs): Promise<EntityType> {
            return this.repository.createEntity(data);
        }

        @Authorized<TAuthRole>("administrator")
        @Mutation(() => EntityClass)
        async [updatePath](@Args() { id, data }: UpdateArgs): Promise<EntityType> {
            return this.repository.updateEntity(id, data);
        }

        @Authorized<TAuthRole>("administrator")
        @Mutation(() => Boolean)
        async [deletePath](@Arg("id", () => Int) id: number): Promise<boolean> {
            return this.repository.deleteEntity(id);
        }

    }

    return {
        abstractResolver: GenericResolver as any,
        repository: GenericRepository as TObjectType<BaseRepository<EntityType, EntityInputType>>,
        pagedEntity: PagedEntity as any,
        createArgs: CreateArgs as any,
        updateArgs: UpdateArgs as any,
    }
}