| 1 | import { Args |
| 2 | import { AllowAnonymous } from '@thallesp/nestjs-better-auth'; |
| 3 |
| 4 | import type { GraphqlContext } from '../../../../lib/github/loaders.js'; |
| 5 | import type { GithubViewer } from '../../../auth/github-request.js'; |
| 6 | import { Viewer } from '../../../auth/viewer.decorator.js'; |
| 7 | import { SearchType } from '../../enums.js'; |
| 8 | import { SearchResultItemConnection } from '../../types/search.type.js'; |
| 9 | import { GithubSearchService } from './search.service.js'; |
| 10 |
| 11 | @Resolver() |
| 12 | @AllowAnonymous() |
| 13 | export class SearchResolver { |
| 14 | constructor(private readonly searches: GithubSearchService) {} |
| 15 |
| 16 | @Query(() => SearchResultItemConnection) |
| 17 | search( |
| 18 | @Args('type', { type: () => SearchType }) type: SearchType, |
| 19 | @Args('query') query: string, |
| 20 | @Viewer() viewer: GithubViewer | null, |
| 21 | @Context() { loaders }: GraphqlContext, |
| 22 | @Args('first', { type: () => Int, nullable: true }) first?: number, |
| 23 | // gh asks with `last: $limit`; search results have no "end" to count back from, so last reads as first. |
| 24 | @Args('last', { type: () => Int, nullable: true }) last?: number, |
| 25 | @Args('after', { nullable: true }) after?: string, |
| 26 | ) { |
| 27 | return this.searches.search( |
| 28 | type, |
| 29 | query, |
| 30 | viewer, |
| 31 | loaders, |
| 32 | first, |
| 33 | last, |
| 34 | after, |
| 35 | ); |
| 36 | } |
| 37 | } |