Skip to content

Commit 00ebacc

Browse files
authored
chore: tidy up docs and npm files (#4)
1 parent e9c3ac2 commit 00ebacc

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ dist
128128
.yarn/build-state.yml
129129
.yarn/install-state.gz
130130
.pnp.*
131+
132+
.DS_Store

.npmignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage/
2+
examples/
3+
**/*.test.js

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This library provides a GQL directive to more easily implement pagination based
44

55
## What / why?
66

7-
Cursor-based pagination, the style implemented by the Relay specific, involves wrapping a dataset in a `connection` object which presents your dataset items as a collection of `edges`. When making your query you provide a `first` (page size) value and an optional `after` value. `first` sets the number of items to return and `after` sets the start point for item selection. For example, given 100 records with sequential IDs, your initial query could include a `first` value of 10 and the second query would include 10 as the `after` value (the id of the last item in the first page).
7+
Cursor-based pagination, the style implemented by the Relay specific, involves wrapping a dataset in a `connection` object which presents your dataset items as a collection of `edges`. When making your query you provide a `first` (page size) value and an optional `after` value. `first` sets the number of items to return and `after` sets the start point for item selection. For example, given 100 records with sequential IDs, your initial query could include a `first` value of 10 and the second query would include 10 as the `after` value (the `id` of the last item on the first page).
88

99
To support this pattern in GQL we need to
1010

@@ -18,11 +18,11 @@ This library aims to reduce this overhead by providing a GQL directive that allo
1818
## Install
1919

2020
```
21-
yarn add relay-pagination
21+
yarn add relay-pagination-directive
2222
# or
23-
npm i relay-pagination
23+
npm i relay-pagination-directive
2424
# or
25-
pnpm add relay-pagination
25+
pnpm add relay-pagination-directive
2626
```
2727

2828
## Usage
@@ -34,7 +34,7 @@ Annotate any types you wish to paginate with the `@connection` directive. Apply
3434

3535
const Fastify = require("fastify");
3636
const mercurius = require("..");
37-
const { connectionDirective } = require('relay-pagination')
37+
const { connectionDirective } = require('relay-pagination-directive')
3838

3939
const app = Fastify();
4040

@@ -187,7 +187,7 @@ const resolvers = {
187187

188188
### Custom Connection/Edge properties
189189

190-
Often it is desirable to add additional properties to our connection and/or edge objects. This is possible using the `typeOptionsMap` config object. This is a mapping of the base type name to the configuration detail. For example if we wanted to add a `totalCount` property.
190+
Often it is desirable to add additional properties to our connection and/or edge objects. This is possible using the `typeOptionsMap` config object. This is a mapping of the base type name to the configuration detail. For example, if we wanted to add a `totalCount` property.
191191

192192
```js
193193
...
@@ -436,12 +436,12 @@ An object with the following properties
436436

437437
## `hasNextPage` Strategies
438438

439-
The intention of the `pageInfo.hasNextPage` property is to indicate to the consuming application whether it needs to query for subsequent pages of results. By default, this library will set this value to true if the data set returned from your resolver has the same length as the `first` argument. Depending on your use case this could be enough for you. For example, in a scenario where you're using pagination to load a large dataset and your UI does not display page numbers having another page is not a problem. However if your pagination is enabling some `Next` style UI button this would be bad as the user could click next and receive a blank page.
439+
The intention of the `pageInfo.hasNextPage` property is to indicate to the consuming application whether it needs to query for subsequent pages of results. By default, this library will set this value to true if the data set returned from your resolver has the same length as the `first` argument. Depending on your use case this could be enough for you. For example, in a scenario where you're using pagination to load a large dataset and your UI does not display page numbers having another page is not a problem. However, if your pagination is enabling some `Next` style UI button this would be bad as the user could click next and receive a blank page.
440440

441441
These are two additional strategies that can be used to generate your own `hasNextPage` value and provide it in the resolver response.
442442

443-
- The simplest and lowest overhead option is to simply add 1 to the received `first` value e.g. if 100 items are requested, query your DB for 101. You'll then known if 101 records are returned that there is at least 1 more page.
444-
- A window function can be added to you SQL query to retrieve the total (remaining) records found by a query. Most DB products support window functions and with a simple count, we can retrieve the total number of records. You can then infer that if the total remaining count is greater than the request page size that there are more pages.
443+
- The simplest and lowest overhead option is to simply add 1 to the received `first` value e.g. if 100 items are requested, query your DB for 101. You'll then know if 101 records are returned that there is at least 1 more page.
444+
- A window function can be added to your SQL query to retrieve the total (remaining) records found by a query. Most DB products support window functions and with a simple count, we can retrieve the total number of records. You can then infer that if the total remaining count is greater than the requested page size there are more pages.
445445

446446
You can view full examples of all three strategies in [this example](./examples/hasNextPageStrategies.js)
447447

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
"type": "module",
88
"scripts": {
99
"lint": "eslint .",
10-
"test": "node --test src/",
10+
"test": "c8 node --test src/",
1111
"test:watch": "c8 node --test --watch src/",
12-
"coverage": "c8 npm run test",
1312
"prepare": "husky install"
1413
},
1514
"repository": {
@@ -22,7 +21,7 @@
2221
"pagination"
2322
],
2423
"author": "Luke Jones",
25-
"license": "ISC",
24+
"license": "MIT",
2625
"bugs": {
2726
"url": "https://github.com/nearform/relay-pagination-directive/issues"
2827
},

0 commit comments

Comments
 (0)