Skip to content

Commit 39319da

Browse files
committed
feat: Migrate on graphql-compose 2.9.0
1 parent 4b9953c commit 39319da

File tree

6 files changed

+738
-342
lines changed

6 files changed

+738
-342
lines changed

package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,33 @@
2424
},
2525
"homepage": "https://github.com/nodkz/graphql-compose-pagination",
2626
"peerDependencies": {
27-
"graphql-compose": ">=1.20.3 || >=2.0.0"
27+
"graphql-compose": ">=1.20.3 || >=2.9.0"
2828
},
2929
"devDependencies": {
30-
"babel-cli": "^6.24.1",
30+
"babel-cli": "^6.26.0",
3131
"babel-eslint": "^7.2.3",
32-
"babel-jest": "^20.0.3",
32+
"babel-jest": "^21.0.0",
3333
"babel-plugin-transform-flow-strip-types": "^6.22.0",
34-
"babel-plugin-transform-object-rest-spread": "^6.23.0",
34+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3535
"babel-plugin-transform-runtime": "^6.23.0",
3636
"babel-preset-env": "^1.6.0",
3737
"cz-conventional-changelog": "^2.0.0",
38-
"eslint": "^4.4.0",
39-
"eslint-config-airbnb-base": "^11.3.1",
40-
"eslint-config-prettier": "^2.3.0",
41-
"eslint-plugin-flowtype": "^2.35.0",
38+
"eslint": "^4.6.1",
39+
"eslint-config-airbnb-base": "^12.0.0",
40+
"eslint-config-prettier": "^2.4.0",
41+
"eslint-plugin-flowtype": "^2.35.1",
4242
"eslint-plugin-import": "^2.7.0",
43-
"eslint-plugin-prettier": "^2.1.2",
44-
"flow-bin": "^0.52.0",
45-
"graphql": "^0.10.5",
46-
"graphql-compose": "^2.2.0",
47-
"jest": "^20.0.4",
48-
"prettier": "^1.5.3",
43+
"eslint-plugin-prettier": "^2.2.0",
44+
"flow-bin": "^0.54.1",
45+
"graphql": "^0.11.3",
46+
"graphql-compose": "^2.9.0",
47+
"jest": "^21.0.1",
48+
"prettier": "^1.6.1",
4949
"rimraf": "^2.6.1",
50-
"semantic-release": "^6.3.6"
50+
"semantic-release": "^7.0.2"
5151
},
5252
"dependencies": {
53-
"babel-runtime": "^6.25.0"
53+
"babel-runtime": "^6.26.0"
5454
},
5555
"config": {
5656
"commitizen": {

src/composeWithPagination.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
/* @flow */
22

33
import { TypeComposer } from 'graphql-compose';
4-
import type { ComposeWithPaginationOpts } from './definition';
54
import { preparePaginationResolver } from './paginationResolver';
65

6+
export type ComposeWithPaginationOpts = {
7+
findResolverName: string,
8+
countResolverName: string,
9+
perPage?: number,
10+
};
11+
712
export function composeWithPagination(
813
typeComposer: TypeComposer,
914
opts: ComposeWithPaginationOpts

src/definition.js

-51
This file was deleted.

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ import { composeWithPagination } from './composeWithPagination';
55
export default composeWithPagination;
66

77
export { composeWithPagination };
8+
9+
export type { ComposeWithPaginationOpts } from './composeWithPagination';

src/paginationResolver.js

+37-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,42 @@
22
/* eslint-disable no-param-reassign, no-use-before-define */
33

44
import { Resolver, TypeComposer } from 'graphql-compose';
5-
import type {
6-
ResolveParams,
7-
PaginationResolveParams,
8-
GraphQLPaginationType,
9-
ComposeWithPaginationOpts,
10-
} from './definition';
5+
import type { ResolveParams, ProjectionType } from 'graphql-compose';
6+
import type { GraphQLResolveInfo } from 'graphql-compose/lib/graphql';
7+
import type { ComposeWithPaginationOpts } from './composeWithPagination';
118
import preparePaginationType from './types/paginationType';
129

13-
const defaultPerPage = 20;
10+
const DEFAULT_PER_PAGE = 20;
11+
12+
export type PaginationResolveParams<TSource, TContext> = {
13+
source: TSource,
14+
args: {
15+
page?: ?number,
16+
perPage?: ?number,
17+
sort?: any,
18+
filter?: { [fieldName: string]: any },
19+
[argName: string]: any,
20+
},
21+
context: TContext,
22+
info: GraphQLResolveInfo,
23+
projection: $Shape<ProjectionType>,
24+
[opt: string]: any,
25+
};
26+
27+
export type PaginationType = {|
28+
count: number,
29+
items: any[],
30+
pageInfo: PaginationInfoType,
31+
|};
32+
33+
export type PaginationInfoType = {|
34+
currentPage: number,
35+
perPage: number,
36+
itemCount: number,
37+
pageCount: number,
38+
hasPreviousPage: boolean,
39+
hasNextPage: boolean,
40+
|};
1441

1542
export function preparePaginationResolver<TSource, TContext>(
1643
typeComposer: TypeComposer,
@@ -78,7 +105,7 @@ export function preparePaginationResolver<TSource, TContext>(
78105
perPage: {
79106
type: 'Int',
80107
description: '',
81-
defaultValue: opts.perPage || defaultPerPage,
108+
defaultValue: opts.perPage || DEFAULT_PER_PAGE,
82109
},
83110
...additionalArgs,
84111
},
@@ -95,7 +122,7 @@ export function preparePaginationResolver<TSource, TContext>(
95122
if (page <= 0) {
96123
throw new Error('Argument `page` should be positive number.');
97124
}
98-
const perPage = parseInt(args.perPage, 10) || opts.perPage || defaultPerPage;
125+
const perPage = parseInt(args.perPage, 10) || opts.perPage || DEFAULT_PER_PAGE;
99126
if (perPage <= 0) {
100127
throw new Error('Argument `perPage` should be positive number.');
101128
}
@@ -147,7 +174,7 @@ export function preparePaginationResolver<TSource, TContext>(
147174
}
148175

149176
return Promise.all([findManyPromise, countPromise]).then(([items, count]) => {
150-
const result: GraphQLPaginationType = {
177+
const result: PaginationType = {
151178
count,
152179
items: items.length > limit ? items.slice(0, limit) : items,
153180
pageInfo: {

0 commit comments

Comments
 (0)