@@ -39,7 +39,7 @@ export class PersonConnection extends createConnectionType(PersonEdge) {}
39
39
40
40
### Create a Connection Arguments type
41
41
42
- Extend a class from ` ConnectionArgs ` class to have pagination arguments pre-defined for you. You can additionally
42
+ Extend a class from ` ConnectionArgs ` class to have pagination arguments pre-defined for you. You can additionally
43
43
define your own arguments for filtering, etc.
44
44
45
45
``` ts
@@ -51,7 +51,7 @@ export class PersonConnectionArgs extends ConnectionArgs {
51
51
/*
52
52
* PersonConnectionArgs will inherit `first`, `last`, `before`, `after`, and `page` fields from ConnectionArgs
53
53
*/
54
-
54
+
55
55
// Optional: example of a custom argument for filtering
56
56
@Field (type => ID , { nullable: true })
57
57
public personId? : string ;
@@ -76,20 +76,18 @@ import { OffsetCursorPaginator } from 'nestjs-graphql-connection';
76
76
@Resolver ()
77
77
export class PersonQueryResolver {
78
78
@Query (returns => PersonConnection )
79
- public async persons(
80
- @Args () connectionArgs : PersonConnectionArgs ,
81
- ): Promise <PersonConnection > {
79
+ public async persons(@Args () connectionArgs : PersonConnectionArgs ): Promise <PersonConnection > {
82
80
const { personId } = connectionArgs ;
83
-
81
+
84
82
// Example: Count the total number of matching persons (ignoring pagination)
85
83
const totalPersons = await countPersons ({ where: { personId } });
86
84
87
85
// Create paginator instance
88
86
const paginator = OffsetCursorPaginator .createFromConnectionArgs (connectionArgs , totalPersons );
89
87
90
88
// Example: Do whatever you need to do to fetch the current page of persons
91
- const persons = await fetchPersons ({
92
- where: { personId },
89
+ const persons = await fetchPersons ({
90
+ where: { personId },
93
91
take: paginator .take , // how many rows to fetch
94
92
skip: paginator .skip , // row offset to fetch from
95
93
});
0 commit comments