Skip to content

Commit

Permalink
feat: Changed bookmarks to union
Browse files Browse the repository at this point in the history
  • Loading branch information
TriPSs committed Oct 5, 2020
1 parent e66ff40 commit b0d2b05
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
11 changes: 6 additions & 5 deletions apps/api/src/bookmarks/bookmarks.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,23 @@ import { Content } from '@pct-org/mongo-models'

import { BookmarksArgs } from './dto/bookmarks.args'
import { BookmarksService } from './bookmarks.service'
import { BookmarksUnion } from './bookmarks.union'
import { PubSubService } from '../shared/pub-sub/pub-sub.service'

@Resolver(of => Content)
@Resolver(of => BookmarksUnion)
export class BookmarksResolver {

constructor(
private readonly bookmarksService: BookmarksService,
private readonly pubSubService: PubSubService
) {}

@Query(returns => [Content])
@Query(returns => [BookmarksUnion])
bookmarks(@Args() bookmarksArgs: BookmarksArgs): Promise<Content[]> {
return this.bookmarksService.findAll(bookmarksArgs)
}

@Mutation(returns => Content)
@Mutation(returns => BookmarksUnion)
async addBookmark(
@Args('_id') _id: string,
@Args('type') type: string
Expand All @@ -35,7 +36,7 @@ export class BookmarksResolver {
return updateBookmark
}

@Mutation(returns => Content)
@Mutation(returns => BookmarksUnion)
async removeBookmark(
@Args('_id') _id: string,
@Args('type') type: string
Expand All @@ -52,7 +53,7 @@ export class BookmarksResolver {
return updateBookmark
}

@Subscription(returns => Content)
@Subscription(returns => BookmarksUnion)
bookmarked() {
return this.pubSubService.asyncIterator('bookmarked')
}
Expand Down
18 changes: 18 additions & 0 deletions apps/api/src/bookmarks/bookmarks.union.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createUnionType } from '@nestjs/graphql'
import { Movie, Show } from '@pct-org/mongo-models'

export const BookmarksUnion = createUnionType({
name: 'Bookmark',
types: () => [Movie, Show],
resolveType(value) {
if (value.type === 'movie') {
return Movie
}

if (value.type === 'show') {
return Show
}

return null
}
})

0 comments on commit b0d2b05

Please sign in to comment.