|
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/graphql-compose/graphql-compose-connection)
|
4 | 4 | [](https://codecov.io/github/graphql-compose/graphql-compose-connection)
|
5 |
| -[](https://www.npmjs.com/package/graphql-compose-connection) |
6 |
| -[](http://www.npmtrends.com/graphql-compose-connection) |
| 5 | +[](https://www.npmjs.com/package/graphql-compose-connection) |
| 6 | +[](http://www.npmtrends.com/graphql-compose-connection) |
7 | 7 | [](http://commitizen.github.io/cz-cli/)
|
8 | 8 |
|
9 | 9 | This is a plugin for [graphql-compose](https://github.com/graphql-compose/graphql-compose) family, which adds to the ObjectTypeComposer `connection` resolver.
|
10 | 10 |
|
11 | 11 | Live demo: [https://graphql-compose.herokuapp.com/](https://graphql-compose.herokuapp.com/)
|
12 | 12 |
|
13 |
| -This package completely follows to Relay Cursor Connections Specification (https://facebook.github.io/relay/graphql/connections.htm). |
| 13 | +This package completely follows to Relay Cursor Connections Specification (<https://relay.dev/graphql/connections.htm>). |
14 | 14 |
|
15 | 15 | Besides standard connection arguments `first`, `last`, `before` and `after`, also added significant arguments:
|
16 |
| -* `filter` arg - for filtering records |
17 |
| -* `sort` arg - for sorting records. Build in mechanism allows sort by any unique indexes (not only by id). Also supported compound sorting (by several fields). |
| 16 | + |
| 17 | +- `filter` arg - for filtering records |
| 18 | +- `sort` arg - for sorting records. Build in mechanism allows sort by any unique indexes (not only by id). Also supported compound sorting (by several fields). |
18 | 19 |
|
19 | 20 | [CHANGELOG](https://github.com/graphql-compose/graphql-compose-connection/blob/master/CHANGELOG.md)
|
20 | 21 |
|
21 |
| -Installation |
22 |
| -============ |
23 |
| -``` |
| 22 | +## Installation |
| 23 | + |
| 24 | +```bash |
24 | 25 | npm install graphql graphql-compose graphql-compose-connection --save
|
25 | 26 | ```
|
26 | 27 |
|
27 | 28 | Modules `graphql` and `graphql-compose` are in `peerDependencies`, so should be installed explicitly in your app. They should not installed as submodules, cause internally checks the classes instances.
|
28 | 29 |
|
| 30 | +## Example |
29 | 31 |
|
30 |
| -Example |
31 |
| -======= |
32 | 32 | ```js
|
33 | 33 | import composeWithConnection from 'graphql-compose-connection';
|
34 | 34 | import userTC from './user.js';
|
@@ -56,15 +56,15 @@ composeWithConnection(userTC, {
|
56 | 56 | // Unpacked data from `cursor` will be available in (`cursorData`) argument.
|
57 | 57 | // PS. All other filter options provided via GraphQL query will be added automatically.
|
58 | 58 | // ----- [record] ----- sorted dataset, according to above option with `value` name
|
59 |
| - // ^^^^^ `rawQuery` should filter this set |
| 59 | + // ^^^^^ `rawQuery` should filter this set |
60 | 60 | beforeCursorQuery: (rawQuery, cursorData, resolveParams) => {
|
61 | 61 | if (!rawQuery._id) rawQuery._id = {};
|
62 | 62 | rawQuery._id.$lt = cursorData._id;
|
63 | 63 | },
|
64 | 64 |
|
65 | 65 | // Constructing `rawQuery` for connection `after` argument.
|
66 | 66 | // ----- [record] ----- sorted dataset
|
67 |
| - // ^^^^^ `rawQuery` should filter this set |
| 67 | + // ^^^^^ `rawQuery` should filter this set |
68 | 68 | afterCursorQuery: (rawQuery, cursorData, resolveParams) => {
|
69 | 69 | if (!rawQuery._id) rawQuery._id = {};
|
70 | 70 | rawQuery._id.$gt = cursorData._id;
|
@@ -105,19 +105,20 @@ composeWithConnection(userTC, {
|
105 | 105 | },
|
106 | 106 | });
|
107 | 107 | ```
|
| 108 | + |
108 | 109 | <img width="1249" alt="screen shot 2016-07-20 at 12 20 08" src="https://cloud.githubusercontent.com/assets/1946920/16976899/67a5e0f8-4e74-11e6-87e5-fc4574deaaab.png">
|
109 | 110 |
|
110 |
| -Requirements |
111 |
| -============ |
| 111 | +## Requirements |
| 112 | + |
112 | 113 | Types should have following resolvers:
|
113 |
| -* `count` - for counting records |
114 |
| -* `findMany` - for filtering records. Also required that this resolver supports search with operators (lt, gt), which used in `directionFilter` option. Resolver `findMany` should have `filter` argument, which will be copied to connection. Also should have `limit` and `skip` args. |
115 | 114 |
|
116 |
| -Used in plugins |
117 |
| -=============== |
| 115 | +- `count` - for counting records |
| 116 | +- `findMany` - for filtering records. Also required that this resolver supports search with operators (lt, gt), which used in `directionFilter` option. Resolver `findMany` should have `filter` argument, which will be copied to connection. Also should have `limit` and `skip` args. |
| 117 | + |
| 118 | +## Used in plugins |
| 119 | + |
118 | 120 | [graphql-compose-mongoose](https://github.com/graphql-compose/graphql-compose-mongoose) - converts mongoose models to graphql types
|
119 | 121 |
|
| 122 | +## License |
120 | 123 |
|
121 |
| -License |
122 |
| -======= |
123 | 124 | [MIT](https://github.com/graphql-compose/graphql-compose-connection/blob/master/LICENSE.md)
|
0 commit comments