Skip to content

Commit 9770db1

Browse files
committed
feat: Migrate on graphql-compose 2.9.0
1 parent cedbeba commit 9770db1

12 files changed

+971
-425
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ cache:
77
notifications:
88
email: true
99
node_js:
10+
- "8"
1011
- "7"
1112
- "6"
12-
- "5"
1313
- "4"
1414
before_install: yarn global add greenkeeper-lockfile@1
1515
before_script: greenkeeper-lockfile-update

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,33 @@
2323
},
2424
"homepage": "https://github.com/nodkz/graphql-compose-connection",
2525
"peerDependencies": {
26-
"graphql-compose": ">=1.20.3 || >=2.0.0"
26+
"graphql-compose": ">=1.20.3 || >=2.9.0"
2727
},
2828
"devDependencies": {
29-
"babel-cli": "^6.24.1",
29+
"babel-cli": "^6.26.0",
3030
"babel-eslint": "^7.2.3",
31-
"babel-jest": "^20.0.3",
31+
"babel-jest": "^21.0.0",
3232
"babel-plugin-transform-flow-strip-types": "^6.22.0",
33-
"babel-plugin-transform-object-rest-spread": "^6.23.0",
33+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
3434
"babel-plugin-transform-runtime": "^6.23.0",
35-
"babel-preset-env": "^1.5.2",
35+
"babel-preset-env": "^1.6.0",
3636
"cz-conventional-changelog": "^2.0.0",
37-
"eslint": "^4.0.0",
38-
"eslint-config-airbnb-base": "^11.2.0",
39-
"eslint-config-prettier": "^2.2.0",
40-
"eslint-plugin-flowtype": "^2.34.0",
41-
"eslint-plugin-import": "^2.3.0",
42-
"eslint-plugin-prettier": "^2.1.2",
43-
"flow-bin": "^0.52.0",
44-
"graphql": "^0.10.3",
45-
"graphql-compose": "^2.0.0",
46-
"jest": "^20.0.4",
47-
"prettier": "^1.4.4",
37+
"eslint": "^4.6.1",
38+
"eslint-config-airbnb-base": "^12.0.0",
39+
"eslint-config-prettier": "^2.4.0",
40+
"eslint-plugin-flowtype": "^2.35.1",
41+
"eslint-plugin-import": "^2.7.0",
42+
"eslint-plugin-prettier": "^2.2.0",
43+
"flow-bin": "^0.54.1",
44+
"graphql": "^0.11.3",
45+
"graphql-compose": "^2.9.0",
46+
"jest": "^21.0.1",
47+
"prettier": "^1.6.1",
4848
"rimraf": "^2.6.1",
49-
"semantic-release": "^6.3.2"
49+
"semantic-release": "^7.0.2"
5050
},
5151
"dependencies": {
52-
"babel-runtime": "^6.23.0"
52+
"babel-runtime": "^6.26.0"
5353
},
5454
"config": {
5555
"commitizen": {

src/__mocks__/userTypeComposer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { TypeComposer, Resolver, graphql } from 'graphql-compose';
55

6-
import type { ConnectionSortMapOpts } from '../definition';
6+
import type { ConnectionSortMapOpts } from '../connectionResolver';
77

88
const {
99
GraphQLString,

src/__tests__/connectionResolver-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ describe('connectionResolver', () => {
580580
},
581581
});
582582
expect(result.edges).toHaveLength(3);
583-
const cursor = result.edges[1].cursor;
583+
const { cursor } = result.edges[1];
584584
const prev = await connectionResolver.resolve({
585585
args: {
586586
sort: sortOptions.ID_ASC.value,
@@ -759,7 +759,7 @@ describe('connectionResolver', () => {
759759
},
760760
});
761761
expect(result.edges).toHaveLength(3);
762-
const cursor = result.edges[1].cursor;
762+
const { cursor } = result.edges[1];
763763
const prev = await connectionResolver.resolve({
764764
args: {
765765
sort: { name: 1 },

src/composeWithConnection.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/* @flow */
22

33
import { TypeComposer } from 'graphql-compose';
4-
import type { ComposeWithConnectionOpts } from './definition';
5-
import { prepareConnectionResolver } from './connectionResolver';
4+
import { prepareConnectionResolver, type ConnectionSortMapOpts } from './connectionResolver';
5+
6+
export type ComposeWithConnectionOpts = {
7+
findResolverName: string,
8+
countResolverName: string,
9+
sort: ConnectionSortMapOpts,
10+
};
611

712
export function composeWithConnection(
813
typeComposer: TypeComposer,

src/connectionResolver.js

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,67 @@
22
/* eslint-disable no-param-reassign, no-use-before-define */
33

44
import { Resolver, TypeComposer } from 'graphql-compose';
5-
import type {
6-
ResolveParams,
7-
ConnectionResolveParams,
8-
ComposeWithConnectionOpts,
9-
ConnectionSortOpts,
10-
ConnectionSortMapOpts,
11-
GraphQLConnectionType,
12-
} from './definition';
5+
import type { ResolveParams, ProjectionType } from 'graphql-compose';
6+
import type { GraphQLResolveInfo } from 'graphql-compose/lib/graphql';
137
import { prepareConnectionType } from './types/connectionType';
148
import { prepareSortType } from './types/sortInputType';
159
import CursorType from './types/cursorType';
16-
import { cursorToData, dataToCursor } from './cursor';
10+
import { cursorToData, dataToCursor, type CursorDataType } from './cursor';
11+
import type { ComposeWithConnectionOpts } from './composeWithConnection';
12+
13+
export type ConnectionSortOpts = {
14+
value: any,
15+
cursorFields: string[],
16+
beforeCursorQuery: (
17+
rawQuery: any,
18+
cursorData: CursorDataType,
19+
resolveParams: ConnectionResolveParams<*, *>
20+
) => any,
21+
afterCursorQuery: (
22+
rawQuery: any,
23+
cursorData: CursorDataType,
24+
resolveParams: ConnectionResolveParams<*, *>
25+
) => any,
26+
};
27+
28+
export type ConnectionSortMapOpts = {
29+
[sortName: string]: ConnectionSortOpts,
30+
};
31+
32+
export type ConnectionResolveParams<TSource, TContext> = {
33+
source: TSource,
34+
args: {
35+
first?: ?number,
36+
after?: string,
37+
last?: ?number,
38+
before?: string,
39+
sort?: ConnectionSortOpts,
40+
filter?: { [fieldName: string]: any },
41+
[argName: string]: any,
42+
},
43+
context: TContext,
44+
info: GraphQLResolveInfo,
45+
projection: $Shape<ProjectionType>,
46+
[opt: string]: any,
47+
};
48+
49+
export type ConnectionType = {
50+
count: number,
51+
edges: ConnectionEdgeType[],
52+
pageInfo: PageInfoType,
53+
};
54+
55+
export type ConnectionEdgeType = {
56+
cursor: string,
57+
node: mixed,
58+
};
59+
60+
export type PageInfoType = {
61+
startCursor: string,
62+
endCursor: string,
63+
hasPreviousPage: boolean,
64+
hasNextPage: boolean,
65+
};
1766

1867
export function prepareConnectionResolver<TSource, TContext>(
1968
typeComposer: TypeComposer,
@@ -326,7 +375,7 @@ export function prepareLimitSkipFallback(
326375
return [newLimit, newSkip];
327376
}
328377

329-
export function emptyConnection(): GraphQLConnectionType {
378+
export function emptyConnection(): ConnectionType {
330379
return {
331380
count: 0,
332381
edges: [],

src/cursor.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
/* @flow */
22

3-
import type { CursorDataType } from './definition';
3+
export type CursorDataType =
4+
| {
5+
[fieldName: string]: any,
6+
}
7+
| any;
48

59
export function base64(i: string): string {
6-
return new Buffer(i, 'ascii').toString('base64');
10+
return Buffer.from(i, 'ascii').toString('base64');
711
}
812

913
export function unbase64(i: string): string {
10-
return new Buffer(i, 'base64').toString('ascii');
14+
return Buffer.from(i, 'base64').toString('ascii');
1115
}
1216

1317
export function cursorToData(cursor?: string | mixed): CursorDataType | number | null {

src/definition.js

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ import { cursorToData, dataToCursor } from './cursor';
66
export default composeWithConnection;
77

88
export { composeWithConnection, cursorToData, dataToCursor };
9+
10+
export type { ComposeWithConnectionOpts } from './composeWithConnection';
11+
export type { ConnectionSortOpts, ConnectionSortMapOpts } from './connectionResolver';

src/types/cursorType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const GraphQLConnectionCursor = new GraphQLScalarType({
88
name: 'ConnectionCursor',
99
description:
1010
'The `ConnectionCursor` is String type, that represents a point of record in data set. ' +
11-
' Due this point, you may request previous or next records.',
11+
' Due this point, you may request previous or next records.',
1212
serialize: String,
1313
parseValue: String,
1414
parseLiteral(ast) {

0 commit comments

Comments
 (0)