import { Arg, Args, Mutation, Query, Root, Resolver, FieldResolver, ObjectType, Field, Int, ArgsType, Info, } from 'type-graphql'; import graphqlFields from 'graphql-fields'; import { Inject } from 'typedi'; import { Min } from 'class-validator'; import { Fields, StandardDeleteResponse, UserId, PageInfo, RawFields } from 'warthog'; import { VideoCreateInput, VideoCreateManyArgs, VideoUpdateArgs, VideoWhereArgs, VideoWhereInput, VideoWhereUniqueInput, VideoOrderByEnum, } from '../../../generated'; import { Video } from './video.model'; import { VideoService } from './video.service'; import { Channel } from '../channel/channel.model'; import { VideoCategory } from '../video-category/video-category.model'; import { DataObject } from '../data-object/data-object.model'; import { Language } from '../language/language.model'; import { License } from '../license/license.model'; import { VideoMediaMetadata } from '../video-media-metadata/video-media-metadata.model'; import { FeaturedVideo } from '../featured-video/featured-video.model'; import { getConnection } from 'typeorm'; @ObjectType() export class VideoEdge { @Field(() => Video, { nullable: false }) node!: Video; @Field(() => String, { nullable: false }) cursor!: string; } @ObjectType() export class VideoConnection { @Field(() => Int, { nullable: false }) totalCount!: number; @Field(() => [VideoEdge], { nullable: false }) edges!: VideoEdge[]; @Field(() => PageInfo, { nullable: false }) pageInfo!: PageInfo; } @ArgsType() export class ConnectionPageInputOptions { @Field(() => Int, { nullable: true }) @Min(0) first?: number; @Field(() => String, { nullable: true }) after?: string; // V3: TODO: should we make a RelayCursor scalar? @Field(() => Int, { nullable: true }) @Min(0) last?: number; @Field(() => String, { nullable: true }) before?: string; } @ArgsType() export class VideoConnectionWhereArgs extends ConnectionPageInputOptions { @Field(() => VideoWhereInput, { nullable: true }) where?: VideoWhereInput; @Field(() => VideoOrderByEnum, { nullable: true }) orderBy?: VideoOrderByEnum; } @Resolver(Video) export class VideoResolver { constructor(@Inject('VideoService') public readonly service: VideoService) {} @Query(() => [Video]) async videos( @Args() { where, orderBy, limit, offset }: VideoWhereArgs, @Fields() fields: string[] ): Promise { return this.service.find(where, orderBy, limit, offset, fields); } @Query(() => Video, { nullable: true }) async videoByUniqueInput( @Arg('where') where: VideoWhereUniqueInput, @Fields() fields: string[] ): Promise