Просмотр исходного кода

add poster image url to video hero schema (#26)

* add poster image url to video hero schema

* fix tests
Klaudiusz Dembler 3 лет назад
Родитель
Сommit
27592bfb12

+ 9 - 1
schema.graphql

@@ -35,7 +35,7 @@ type Mutation {
   """Add a single follow to the target channel"""
   followChannel(channelId: ID!): ChannelFollowsInfo!
   setCategoryFeaturedVideos(categoryId: ID!, videos: [FeaturedVideoInput!]!): [FeaturedVideo!]!
-  setVideoHero(heroTitle: String!, heroVideoCutUrl: String!, videoId: ID!): VideoHero!
+  setVideoHero(newVideoHero: VideoHeroInput!): VideoHero!
 
   """Remove a single follow from the target channel"""
   unfollowChannel(channelId: ID!): ChannelFollowsInfo!
@@ -115,6 +115,14 @@ type Query {
 }
 
 type VideoHero {
+  heroPosterUrl: String!
+  heroTitle: String!
+  heroVideoCutUrl: String!
+  videoId: ID!
+}
+
+input VideoHeroInput {
+  heroPosterUrl: String!
   heroTitle: String!
   heroVideoCutUrl: String!
   videoId: ID!

+ 5 - 0
src/models/FeaturedContent.ts

@@ -16,6 +16,10 @@ export class VideoHero {
   @prop({ required: true })
   @Field()
   heroVideoCutUrl!: string
+
+  @prop({ required: true })
+  @Field()
+  heroPosterUrl!: string
 }
 
 @ObjectType()
@@ -46,6 +50,7 @@ export const DEFAULT_FEATURED_CONTENT_DOC: FeaturedContent = {
     videoId: '0',
     heroTitle: 'Change Me',
     heroVideoCutUrl: 'https://google.com',
+    heroPosterUrl: 'https://google.com',
   },
   featuredVideosPerCategory: new Map<string, FeaturedVideo[]>(),
 }

+ 16 - 1
src/resolvers/featuredContent.ts

@@ -11,6 +11,21 @@ class FeaturedVideoInput implements FeaturedVideo {
   videoCutUrl?: string
 }
 
+@InputType()
+class VideoHeroInput implements VideoHero {
+  @Field(() => ID)
+  videoId!: string
+
+  @Field()
+  heroPosterUrl!: string
+
+  @Field()
+  heroTitle!: string
+
+  @Field()
+  heroVideoCutUrl!: string
+}
+
 @ArgsType()
 class SetCategoryFeaturedVideoArgs {
   @Field(() => ID)
@@ -50,7 +65,7 @@ export class FeaturedContentResolver {
 
   @Mutation(() => VideoHero, { nullable: false })
   @Authorized()
-  async setVideoHero(@Args() newVideoHero: VideoHero) {
+  async setVideoHero(@Arg('newVideoHero', () => VideoHeroInput) newVideoHero: VideoHeroInput) {
     const featuredContent = await getFeaturedContentDoc()
     featuredContent.videoHero = newVideoHero
     await featuredContent.save()

+ 2 - 1
tests/featuredContent.test.ts

@@ -92,10 +92,11 @@ describe('Featured content resolver', () => {
       videoId: '1111',
       heroTitle: 'Hello darkness my old friend',
       heroVideoCutUrl: 'example_url',
+      heroPosterUrl: 'example_url_2',
     }
     await mutate<SetVideoHero, SetVideoHeroArgs>({
       mutation: SET_VIDEO_HERO,
-      variables: { ...newVideoHero },
+      variables: { newVideoHero },
     })
 
     const videoHero = await getVideoHero()

+ 10 - 5
tests/queries/featuredContent.ts

@@ -7,6 +7,7 @@ export const GET_VIDEO_HERO = gql`
     videoHero {
       heroTitle
       heroVideoCutUrl
+      heroPosterUrl
       videoId
     }
   }
@@ -46,11 +47,12 @@ export type GetAllCategoriesFeaturedVideos = {
 }
 
 export const SET_VIDEO_HERO = gql`
-  mutation SetVideoHero($videoId: ID!, $heroTitle: String!, $heroVideoCutUrl: String!) {
-    setVideoHero(videoId: $videoId, heroTitle: $heroTitle, heroVideoCutUrl: $heroVideoCutUrl) {
+  mutation SetVideoHero($newVideoHero: VideoHeroInput!) {
+    setVideoHero(newVideoHero: $newVideoHero) {
       videoId
       heroTitle
       heroVideoCutUrl
+      heroPosterUrl
     }
   }
 `
@@ -58,9 +60,12 @@ export type SetVideoHero = {
   setVideoHero: VideoHero
 }
 export type SetVideoHeroArgs = {
-  videoId: string
-  heroTitle: string
-  heroVideoCutUrl: string
+  newVideoHero: {
+    videoId: string
+    heroTitle: string
+    heroVideoCutUrl: string
+    heroPosterUrl: string
+  }
 }
 
 export const SET_CATEGORY_FEATURED_VIDEOS = gql`