File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -410,7 +410,19 @@ We saw one use of generics above. This powerful TypeScript feature can be used t
410
410
import { Field , ObjectType, Int } from '@nestjs/graphql';
411
411
import { Type } from '@nestjs/common';
412
412
413
- export function Paginated<T>(classRef : Type <T >): any {
413
+ interface IEdgeType<T> {
414
+ cursor : string ;
415
+ node : T ;
416
+ }
417
+
418
+ export interface IPaginatedType<T> {
419
+ edges : IEdgeType <T >[];
420
+ nodes : T [];
421
+ totalCount : number ;
422
+ hasNextPage : boolean ;
423
+ }
424
+
425
+ export function Paginated<T>(classRef : Type <T >): Type <IPaginatedType <T >> {
414
426
@ObjectType (`${classRef.name}Edge`)
415
427
abstract class EdgeType {
416
428
@Field ((type) => String )
@@ -421,7 +433,7 @@ export function Paginated<T>(classRef: Type<T>): any {
421
433
}
422
434
423
435
@ObjectType ({ isAbstract : true })
424
- abstract class PaginatedType {
436
+ abstract class PaginatedType implements IPaginatedType < T > {
425
437
@Field ((type) => [EdgeType ], { nullable : true })
426
438
edges : EdgeType [];
427
439
@@ -434,7 +446,7 @@ export function Paginated<T>(classRef: Type<T>): any {
434
446
@Field ()
435
447
hasNextPage : boolean ;
436
448
}
437
- return PaginatedType ;
449
+ return PaginatedType as Type < IPaginatedType < T >> ;
438
450
}
439
451
```
440
452
You can’t perform that action at this time.
0 commit comments