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
410410import { Field , ObjectType, Int } from '@nestjs/graphql';
411411import { Type } from '@nestjs/common';
412412
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 >> {
414426 @ObjectType (`${classRef.name}Edge`)
415427 abstract class EdgeType {
416428 @Field ((type) => String )
@@ -421,7 +433,7 @@ export function Paginated<T>(classRef: Type<T>): any {
421433 }
422434
423435 @ObjectType ({ isAbstract : true })
424- abstract class PaginatedType {
436+ abstract class PaginatedType implements IPaginatedType < T > {
425437 @Field ((type) => [EdgeType ], { nullable : true })
426438 edges : EdgeType [];
427439
@@ -434,7 +446,7 @@ export function Paginated<T>(classRef: Type<T>): any {
434446 @Field ()
435447 hasNextPage : boolean ;
436448 }
437- return PaginatedType ;
449+ return PaginatedType as Type < IPaginatedType < T >> ;
438450}
439451```
440452
You can’t perform that action at this time.
0 commit comments