Skip to content

Commit b648bf8

Browse files
committed
refactor: due changes in [email protected]
BREAKING CHANGE: Using API from [email protected]
1 parent 383823b commit b648bf8

File tree

11 files changed

+1496
-1489
lines changed

11 files changed

+1496
-1489
lines changed

.markdownlint.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"line-length": false,
3+
"no-trailing-punctuation": {
4+
"punctuation": ",;"
5+
},
6+
"no-inline-html": false,
7+
"ol-prefix": false,
8+
"first-line-h1": false,
9+
"first-heading-h1": false
10+
}

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"prettier.eslintIntegration": true,
3+
"eslint.validate": [
4+
"javascript",
5+
],
6+
"javascript.validate.enable": false
7+
}

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
graphql-compose-elasticsearch
2-
======================
1+
# graphql-compose-elasticsearch
32

4-
[![](https://img.shields.io/npm/v/graphql-compose-elasticsearch.svg)](https://www.npmjs.com/package/graphql-compose-elasticsearch)
5-
[![npm](https://img.shields.io/npm/dt/graphql-compose-elasticsearch.svg)](http://www.npmtrends.com/graphql-compose-elasticsearch)
3+
[![npm](https://img.shields.io/npm/v/graphql-compose-elasticsearch.svg)](https://www.npmjs.com/package/graphql-compose-elasticsearch)
4+
[![trends](https://img.shields.io/npm/dt/graphql-compose-elasticsearch.svg)](http://www.npmtrends.com/graphql-compose-elasticsearch)
65
[![Travis](https://img.shields.io/travis/graphql-compose/graphql-compose-elasticsearch.svg?maxAge=2592000)](https://travis-ci.org/graphql-compose/graphql-compose-elasticsearch)
76
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)
87
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
@@ -52,9 +51,11 @@ Live demo of [Introspection of Elasticsearch API via Graphiql](https://graphql-c
5251
---
5352

5453
## TypeComposer from Elastic mapping
54+
5555
In other side this module is a plugin for [graphql-compose](https://github.com/graphql-compose/graphql-compose), which derives GraphQLType from your [elastic mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) generates tons of types, provides all available methods in QueryDSL, Aggregations, Sorting with field autocompletion according to types in your mapping (like Dev Tools Console in Kibana).
5656

5757
Generated TypeComposer model has several awesome resolvers:
58+
5859
- `search` - greatly simplified elastic `search` method. According to GraphQL adaptation and its projection bunch of params setup automatically due your graphql query (eg `_source`, `explain`, `version`, `trackScores`), other rare fine tuning params moved to `opts` input field.
5960
- `searchConnection` - elastic `search` method that implements Relay Cursor Connection [spec](https://facebook.github.io/relay/graphql/connections.htm) for infinite lists. Internally it uses cheap [search_after](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-after.html) API. One downside, Elastic does not support backward scrolling, so `before` argument will not work.
6061
- `searchPagination` - elastic `search` method that has `page` and `perPage` arguments
@@ -132,25 +133,31 @@ const Schema = new GraphQLSchema({
132133
Full [code example](https://github.com/graphql-compose/graphql-compose-elasticsearch/blob/master/examples/elastic50/index.js)
133134

134135
## Installation
135-
```
136+
137+
```bash
136138
yarn add graphql graphql-compose elasticsearch graphql-compose-elasticsearch
137139
// or
138140
npm install graphql graphql-compose elasticsearch graphql-compose-elasticsearch --save
139141
```
142+
140143
Modules `graphql`, `graphql-compose`, `elasticsearch` are in `peerDependencies`, so should be installed explicitly in your app.
141144

142145
## Screenshots
143146

144147
### API proxy: Raw search method
148+
145149
<img width="1316" alt="screen shot 2017-03-07 at 22 26 17" src="https://cloud.githubusercontent.com/assets/1946920/23859886/61066f40-082f-11e7-89d0-8443aa2ae930.png">
146150

147151
### API proxy: Getting several raw elastic metric in one request
152+
148153
<img width="1314" alt="screen shot 2017-03-07 at 22 34 01" src="https://cloud.githubusercontent.com/assets/1946920/23859892/65e71744-082f-11e7-8c1a-cafeb87e08e6.png">
149154

150155
### Mapping: Relay Cursor Connection
156+
151157
<img width="1411" alt="screen shot 2017-03-22 at 19 34 09" src="https://cloud.githubusercontent.com/assets/1946920/24200219/a058c220-0f36-11e7-9cf1-38394052f922.png">
152158

153159
### Mapping: Generated GraphQL Types and Documentation
160+
154161
<img width="1703" alt="screen shot 2017-03-22 at 19 33 24" src="https://cloud.githubusercontent.com/assets/1946920/24200220/a05944b6-0f36-11e7-9919-39b7001af203.png">
155162

156163
## FAQ
@@ -185,4 +192,5 @@ ActivitiesEsTC.addResolver({
185192
```
186193

187194
## License
195+
188196
[MIT](https://github.com/graphql-compose/graphql-compose-elasticsearch/blob/master/LICENSE.md)

flow-typed/npm/express_v4.x.x.js

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { Server } from 'http';
66
declare type express$RouterOptions = {
77
caseSensitive?: boolean,
88
mergeParams?: boolean,
9-
strict?: boolean
9+
strict?: boolean,
1010
};
1111

1212
declare class express$RequestResponseBase {
@@ -17,20 +17,20 @@ declare class express$RequestResponseBase {
1717
declare class express$Request extends http$IncomingMessage mixins express$RequestResponseBase {
1818
baseUrl: string;
1919
body: mixed;
20-
cookies: {[cookie: string]: string};
20+
cookies: { [cookie: string]: string };
2121
fresh: boolean;
2222
hostname: string;
2323
ip: string;
2424
ips: Array<string>;
2525
method: string;
2626
originalUrl: string;
27-
params: {[param: string]: string};
27+
params: { [param: string]: string };
2828
path: string;
2929
protocol: 'https' | 'http';
30-
query: {[name: string]: string};
30+
query: { [name: string]: string };
3131
route: string;
3232
secure: boolean;
33-
signedCookies: {[signedCookie: string]: string};
33+
signedCookies: { [signedCookie: string]: string };
3434
stale: boolean;
3535
subdomains: Array<string>;
3636
xhr: boolean;
@@ -51,7 +51,7 @@ declare type express$CookieOptions = {
5151
maxAge?: number,
5252
path?: string,
5353
secure?: boolean,
54-
signed?: boolean
54+
signed?: boolean,
5555
};
5656

5757
declare type express$RenderCallback = (err: Error | null, html?: string) => mixed;
@@ -60,46 +60,55 @@ declare type express$SendFileOptions = {
6060
maxAge?: number,
6161
root?: string,
6262
lastModified?: boolean,
63-
headers?: {[name: string]: string},
64-
dotfiles?: 'allow' | 'deny' | 'ignore'
63+
headers?: { [name: string]: string },
64+
dotfiles?: 'allow' | 'deny' | 'ignore',
6565
};
6666

6767
declare class express$Response extends http$ServerResponse mixins express$RequestResponseBase {
6868
headersSent: boolean;
69-
locals: {[name: string]: mixed};
69+
locals: { [name: string]: mixed };
7070
append(field: string, value?: string): this;
7171
attachment(filename?: string): this;
7272
cookie(name: string, value: string, options?: express$CookieOptions): this;
7373
clearCookie(name: string, options?: express$CookieOptions): this;
7474
download(path: string, filename?: string, callback?: (err?: ?Error) => void): this;
75-
format(typesObject: {[type: string]: Function}): this;
75+
format(typesObject: { [type: string]: Function }): this;
7676
json(body?: mixed): this;
7777
jsonp(body?: mixed): this;
78-
links(links: {[name: string]: string}): this;
78+
links(links: { [name: string]: string }): this;
7979
location(path: string): this;
8080
redirect(url: string, ...args: Array<void>): this;
8181
redirect(status: number, url: string, ...args: Array<void>): this;
82-
render(view: string, locals?: {[name: string]: mixed}, callback?: express$RenderCallback): this;
82+
render(view: string, locals?: { [name: string]: mixed }, callback?: express$RenderCallback): this;
8383
send(body?: mixed): this;
84-
sendFile(path: string, options?: express$SendFileOptions, callback?: (err?: ?Error) => mixed): this;
84+
sendFile(
85+
path: string,
86+
options?: express$SendFileOptions,
87+
callback?: (err?: ?Error) => mixed
88+
): this;
8589
sendStatus(statusCode: number): this;
8690
header(field: string, value?: string): this;
87-
header(headers: {[name: string]: string}): this;
91+
header(headers: { [name: string]: string }): this;
8892
set(field: string, value?: string): this;
89-
set(headers: {[name: string]: string}): this;
93+
set(headers: { [name: string]: string }): this;
9094
status(statusCode: number): this;
9195
type(type: string): this;
9296
vary(field: string): this;
9397
}
9498

9599
declare type express$NextFunction = (err?: ?Error) => mixed;
96100
declare type express$Middleware =
97-
((req: express$Request, res: express$Response, next: express$NextFunction) => mixed) |
98-
((error: ?Error, req: express$Request, res: express$Response, next: express$NextFunction) => mixed);
101+
| ((req: express$Request, res: express$Response, next: express$NextFunction) => mixed)
102+
| ((
103+
error: ?Error,
104+
req: express$Request,
105+
res: express$Response,
106+
next: express$NextFunction
107+
) => mixed);
99108
declare interface express$RouteMethodType<T> {
100109
(middleware: express$Middleware): T;
101110
(...middleware: Array<express$Middleware>): T;
102-
(path: string|RegExp|string[], ...middleware: Array<express$Middleware>): T;
111+
(path: string | RegExp | string[], ...middleware: Array<express$Middleware>): T;
103112
}
104113
declare class express$Route {
105114
all: express$RouteMethodType<this>;
@@ -139,18 +148,23 @@ declare class express$Router extends express$Route {
139148
static (): express$Router;
140149
use(middleware: express$Middleware): this;
141150
use(...middleware: Array<express$Middleware>): this;
142-
use(path: string|RegExp|string[], ...middleware: Array<express$Middleware>): this;
151+
use(path: string | RegExp | string[], ...middleware: Array<express$Middleware>): this;
143152
use(path: string, router: express$Router): this;
144-
handle(req: http$IncomingMessage, res: http$ServerResponse, next: express$NextFunction): void;
153+
handle(req: http$IncomingMessage<>, res: http$ServerResponse, next: express$NextFunction): void;
145154

146-
(req: http$IncomingMessage, res: http$ServerResponse, next?: ?express$NextFunction): void;
155+
(req: http$IncomingMessage<>, res: http$ServerResponse, next?: ?express$NextFunction): void;
147156
}
148157

149158
declare class express$Application extends express$Router mixins events$EventEmitter {
150159
constructor(): void;
151-
locals: {[name: string]: mixed};
160+
locals: { [name: string]: mixed };
152161
mountpath: string;
153-
listen(port: number, hostname?: string, backlog?: number, callback?: (err?: ?Error) => mixed): Server;
162+
listen(
163+
port: number,
164+
hostname?: string,
165+
backlog?: number,
166+
callback?: (err?: ?Error) => mixed
167+
): Server;
154168
listen(port: number, hostname?: string, callback?: (err?: ?Error) => mixed): Server;
155169
listen(port: number, callback?: (err?: ?Error) => mixed): Server;
156170
listen(path: string, callback?: (err?: ?Error) => mixed): Server;
@@ -165,8 +179,12 @@ declare class express$Application extends express$Router mixins events$EventEmit
165179
*/
166180
// get(name: string): mixed;
167181
set(name: string, value: mixed): mixed;
168-
render(name: string, optionsOrFunction: {[name: string]: mixed}, callback: express$RenderCallback): void;
169-
handle(req: http$IncomingMessage, res: http$ServerResponse, next?: ?express$NextFunction): void;
182+
render(
183+
name: string,
184+
optionsOrFunction: { [name: string]: mixed },
185+
callback: express$RenderCallback
186+
): void;
187+
handle(req: http$IncomingMessage<>, res: http$ServerResponse, next?: ?express$NextFunction): void;
170188
}
171189

172190
declare module 'express' {

package.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,41 @@
2828
},
2929
"peerDependencies": {
3030
"elasticsearch": ">=15.0.0 || >=14.0.0 || >=13.0.0 || >=12.0.0",
31-
"graphql-compose": ">=5.0.2 || >=4.4.1"
31+
"graphql-compose": ">=6.0.0"
3232
},
3333
"devDependencies": {
34-
"@babel/cli": "^7.2.0",
35-
"@babel/core": "^7.2.0",
36-
"@babel/node": "^7.2.0",
37-
"@babel/plugin-proposal-class-properties": "^7.2.1",
38-
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
39-
"@babel/plugin-transform-flow-strip-types": "^7.2.0",
40-
"@babel/plugin-transform-runtime": "^7.2.0",
41-
"@babel/preset-env": "^7.2.0",
34+
"@babel/cli": "^7.2.3",
35+
"@babel/core": "^7.3.4",
36+
"@babel/node": "^7.2.2",
37+
"@babel/plugin-proposal-class-properties": "^7.3.4",
38+
"@babel/plugin-proposal-object-rest-spread": "^7.3.4",
39+
"@babel/plugin-transform-flow-strip-types": "^7.3.4",
40+
"@babel/plugin-transform-runtime": "^7.3.4",
41+
"@babel/preset-env": "^7.3.4",
4242
"@babel/preset-flow": "^7.0.0",
43-
"aws-sdk": "^2.311.0",
43+
"aws-sdk": "^2.422.0",
4444
"babel-core": "^7.0.0-bridge.0",
4545
"babel-eslint": "^10.0.1",
46-
"babel-jest": "^23.6.0",
46+
"babel-jest": "^24.5.0",
4747
"cz-conventional-changelog": "^2.1.0",
48-
"elasticsearch": "^15.2.0",
49-
"eslint": "^5.10.0",
48+
"elasticsearch": "^15.4.1",
49+
"eslint": "^5.15.1",
5050
"eslint-config-airbnb-base": "^13.1.0",
51-
"eslint-config-prettier": "^3.3.0",
52-
"eslint-plugin-flowtype": "^3.2.0",
53-
"eslint-plugin-import": "^2.14.0",
54-
"eslint-plugin-prettier": "^3.0.0",
51+
"eslint-config-prettier": "^4.1.0",
52+
"eslint-plugin-flowtype": "^3.4.2",
53+
"eslint-plugin-import": "^2.16.0",
54+
"eslint-plugin-prettier": "^3.0.1",
5555
"express": "^4.16.4",
5656
"express-graphql": "^0.7.1",
57-
"flow-bin": "^0.88.0",
58-
"graphql": "14.0.2",
59-
"graphql-compose": "^5.3.4",
60-
"jest": "^23.6.0",
61-
"nodemon": "^1.18.8",
57+
"flow-bin": "^0.94.0",
58+
"graphql": "14.1.1",
59+
"graphql-compose": "^5.12.0",
60+
"jest": "^24.5.0",
61+
"nodemon": "^1.18.10",
6262
"npm-run-all": "^4.1.5",
63-
"prettier": "^1.15.3",
64-
"rimraf": "^2.6.2",
65-
"semantic-release": "^15.12.4"
63+
"prettier": "^1.16.4",
64+
"rimraf": "^2.6.3",
65+
"semantic-release": "^15.13.3"
6666
},
6767
"config": {
6868
"commitizen": {
@@ -94,7 +94,7 @@
9494
"docker:v2": "node ./scripts/docker/start 2 & wait",
9595
"docker:v5": "node ./scripts/docker/start 5 & wait",
9696
"link": "yarn build && yarn link graphql-compose && yarn link",
97-
"unlink": "yarn unlink graphql-compose && yarn add graphql-compose",
97+
"unlink": "rimraf node_modules && yarn install",
9898
"my-demo": "./node_modules/.bin/babel-node ./__fixtures__/index.js"
9999
}
100100
}

src/__mocks__/elasticClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import elasticsearch from 'elasticsearch';
44

55
const elasticClient = new elasticsearch.Client({
66
host: 'http://localhost:9200',
7-
apiVersion: '5.0',
7+
apiVersion: '6.0',
88
// log: 'trace',
99
});
1010

src/__tests__/github_issues/32-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GraphQLSchema, GraphQLObjectType } from 'graphql';
66
import { composeWithElastic } from '../..';
77

88
const ELASTICSEARCH_HOST = '';
9-
const ELASTICSEARCH_API_VERSION = '5.0';
9+
const ELASTICSEARCH_API_VERSION = '6.0';
1010
const mapping = {
1111
properties: {
1212
id: {

src/__tests__/github_issues/37-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { graphql } from 'graphql';
1212
import { composeWithElastic } from '../..';
1313

1414
const ELASTICSEARCH_HOST = '';
15-
const ELASTICSEARCH_API_VERSION = '5.2';
15+
const ELASTICSEARCH_API_VERSION = '5.6';
1616
const mapping = {
1717
properties: {
1818
id: {

src/__tests__/mappingConverter-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,12 @@ describe('PropertiesConverter', () => {
244244
});
245245

246246
it('should work with graphql schema without errors', () => {
247-
schemaComposer.rootQuery().addFields({ userES: tc9 });
247+
schemaComposer.Query.addFields({ userES: tc9 });
248248
expect(() => schemaComposer.buildSchema()).not.toThrowError();
249249
});
250250

251251
it('should use Elastic field names from source', async () => {
252-
schemaComposer.rootQuery().addFields({ userES: tc9 });
252+
schemaComposer.Query.addFields({ userES: tc9 });
253253
const result = await graphql.graphql(
254254
schemaComposer.buildSchema(),
255255
`

src/resolvers/__tests__/findById-test.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ describe('findById', () => {
2020
expect(findByIdResolver.hasArg('id')).toBeTruthy();
2121
});
2222

23-
it('resolve', () => {
24-
findByIdResolver.resolve({ args: { id: '4554' }, context: { elasticClient } }).then(res => {
23+
it('resolve', async () => {
24+
await findByIdResolver
25+
.resolve({ args: { id: '4554' }, context: { elasticClient } })
26+
.then(res => {
2527
console.log(res); // eslint-disable-line
26-
});
28+
})
29+
.catch(e => {
30+
expect(e).toMatchObject({ message: /unknown error/ });
31+
});
2732
});
2833
});

0 commit comments

Comments
 (0)