Skip to content

Commit 05fd45f

Browse files
committed
feat: upgrade till [email protected]
1 parent a4b0002 commit 05fd45f

File tree

10 files changed

+777
-632
lines changed

10 files changed

+777
-632
lines changed

package.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@
2828
},
2929
"peerDependencies": {
3030
"elasticsearch": ">=15.0.0 || >=14.0.0 || >=13.0.0 || >=12.0.0",
31-
"graphql-compose": ">=6.0.2"
31+
"graphql-compose": ">=6.2.0"
3232
},
3333
"devDependencies": {
34-
"@babel/cli": "^7.2.3",
35-
"@babel/core": "^7.3.4",
34+
"@babel/cli": "^7.4.3",
35+
"@babel/core": "^7.4.3",
3636
"@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",
37+
"@babel/plugin-proposal-class-properties": "^7.4.0",
38+
"@babel/plugin-proposal-object-rest-spread": "^7.4.3",
39+
"@babel/plugin-transform-flow-strip-types": "^7.4.0",
40+
"@babel/plugin-transform-runtime": "^7.4.3",
41+
"@babel/preset-env": "^7.4.3",
4242
"@babel/preset-flow": "^7.0.0",
43-
"aws-sdk": "^2.422.0",
43+
"aws-sdk": "^2.437.0",
4444
"babel-core": "^7.0.0-bridge.0",
4545
"babel-eslint": "^10.0.1",
46-
"babel-jest": "^24.5.0",
46+
"babel-jest": "^24.7.1",
4747
"cz-conventional-changelog": "^2.1.0",
4848
"elasticsearch": "^15.4.1",
49-
"eslint": "^5.15.2",
49+
"eslint": "^5.16.0",
5050
"eslint-config-airbnb-base": "^13.1.0",
5151
"eslint-config-prettier": "^4.1.0",
52-
"eslint-plugin-flowtype": "^3.4.2",
52+
"eslint-plugin-flowtype": "^3.5.1",
5353
"eslint-plugin-import": "^2.16.0",
5454
"eslint-plugin-prettier": "^3.0.1",
5555
"express": "^4.16.4",
5656
"express-graphql": "^0.7.1",
57-
"flow-bin": "^0.95.1",
58-
"graphql": "14.1.1",
59-
"graphql-compose": "^6.0.2",
60-
"jest": "^24.5.0",
57+
"flow-bin": "^0.96.0",
58+
"graphql": "^14.2.1",
59+
"graphql-compose": "^6.2.0",
60+
"jest": "^24.7.1",
6161
"nodemon": "^1.18.10",
6262
"npm-run-all": "^4.1.5",
6363
"prettier": "^1.16.4",

src/__tests__/github_issues/32-test.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import elasticsearch from 'elasticsearch';
44
import { schemaComposer, ObjectTypeComposer, Resolver } from 'graphql-compose';
5-
import { GraphQLSchema, GraphQLObjectType } from 'graphql';
5+
import { GraphQLSchema, GraphQLObjectType } from 'graphql-compose/lib/graphql';
66
import { composeWithElastic } from '../..';
77

88
const ELASTICSEARCH_HOST = '';
@@ -33,11 +33,11 @@ const ActivitiesEsTC = composeWithElastic({
3333
}),
3434
});
3535

36-
beforeEach(() => {
37-
schemaComposer.clear();
38-
});
39-
4036
describe('github issue #32 - hits returns me the found id, score, type...', () => {
37+
beforeEach(() => {
38+
schemaComposer.clear();
39+
});
40+
4141
it('test `search` resolver', () => {
4242
expect(ActivitiesEsTC).toBeInstanceOf(ObjectTypeComposer);
4343

@@ -56,7 +56,7 @@ describe('github issue #32 - hits returns me the found id, score, type...', () =
5656
'_shards',
5757
]);
5858

59-
const HitsTC = OutputTC.getFieldTC('hits');
59+
const HitsTC = OutputTC.getFieldOTC('hits');
6060
expect(HitsTC).toBeInstanceOf(ObjectTypeComposer);
6161
expect(HitsTC.getFieldNames()).toEqual([
6262
'_index',
@@ -73,7 +73,7 @@ describe('github issue #32 - hits returns me the found id, score, type...', () =
7373
'fields',
7474
]);
7575

76-
const SourceTC = HitsTC.getFieldTC('_source');
76+
const SourceTC = HitsTC.getFieldOTC('_source');
7777
expect(SourceTC.getTypeName()).toBe('SearchActivitiesSearchActivities');
7878
expect(SourceTC).toBeInstanceOf(ObjectTypeComposer);
7979
expect(SourceTC.getFieldNames()).toEqual(['id', 'title', 'description']);
@@ -102,7 +102,7 @@ describe('github issue #32 - hits returns me the found id, score, type...', () =
102102
'_shards',
103103
]);
104104

105-
const HitsTC = OutputTC.getFieldTC('hits');
105+
const HitsTC = OutputTC.getFieldOTC('hits');
106106
expect(HitsTC).toBeInstanceOf(ObjectTypeComposer);
107107
expect(HitsTC.getFieldNames()).toEqual([
108108
'_index',
@@ -119,7 +119,7 @@ describe('github issue #32 - hits returns me the found id, score, type...', () =
119119
'fields',
120120
]);
121121

122-
const SourceTC = HitsTC.getFieldTC('_source');
122+
const SourceTC = HitsTC.getFieldOTC('_source');
123123
expect(SourceTC.getTypeName()).toBe('SearchActivitiesSearchActivities');
124124
expect(SourceTC).toBeInstanceOf(ObjectTypeComposer);
125125
expect(SourceTC.getFieldNames()).toEqual(['id', 'title', 'description']);

src/elasticDSL/Aggs/__tests__/__snapshots__/Aggs-test.js.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`AGGS args converter Aggs DSL 1`] = `
4-
"\\"\\"\\"
4+
"\\"\\"\\"Provides default value for input field.\\"\\"\\"
5+
directive @default(value: JSON!) on INPUT_FIELD_DEFINITION
6+
7+
\\"\\"\\"
58
The aggregations framework helps provide aggregated data based on a search
69
query. It is based on simple building blocks called aggregations, that can be
710
composed in order to build complex summaries of the data. [Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html)

src/elasticDSL/Commons/FieldNames.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable no-param-reassign */
33

44
import { upperFirst, EnumTypeComposer, type ComposeInputFieldConfigMap } from 'graphql-compose';
5-
import type { GraphQLEnumValueConfigMap } from 'graphql-compose/lib/graphql';
5+
import type { ComposeEnumValueConfigMap } from 'graphql-compose/lib/EnumTypeComposer';
66
import { getTypeName, type CommonOpts, desc } from '../../utils';
77

88
export type ElasticDataType = string;
@@ -162,7 +162,7 @@ function getEnumValues(
162162
fieldMap: any,
163163
types: ElasticDataType[],
164164
addAll: boolean = false
165-
): GraphQLEnumValueConfigMap {
165+
): ComposeEnumValueConfigMap {
166166
const values = {};
167167
if (addAll) {
168168
values._all = {

src/elasticDSL/Query/__tests__/__snapshots__/Query-test.js.snap

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`AGGS args converter Query DSL 1`] = `
4-
"\\"\\"\\"
4+
"\\"\\"\\"Provides default value for input field.\\"\\"\\"
5+
directive @default(value: JSON!) on INPUT_FIELD_DEFINITION
6+
7+
\\"\\"\\"
58
The scripting module enables you to use scripts to evaluate custom expressions. [Documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html)
69
\\"\\"\\"
710
input Elastic_CommonsScript_50 {

src/elasticDSL/SearchBody.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export function getSearchBodyITC<TContext>(
2121
name,
2222
description,
2323
fields: {
24-
query: () => getQueryITC(opts),
25-
aggs: () => getAggsITC(opts),
24+
query: { type: () => getQueryITC(opts) },
25+
aggs: { type: () => getAggsITC(opts) },
2626
size: 'Int',
2727
from: 'Int',
28-
sort: () => [getSortITC(opts)],
28+
sort: { type: () => [getSortITC(opts)] },
2929
_source: 'JSON',
3030
script_fields: 'JSON',
3131
post_filter: () => getQueryITC(opts),

src/resolvers/__tests__/search-test.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ describe('search resolver', () => {
2323
expect(createSearchResolver(opts)).toBeInstanceOf(Resolver);
2424
});
2525

26-
describe('Resolver.resolve', () => {
27-
const SearchResolver = createSearchResolver(opts);
28-
29-
it.skip('should return result', () => {
30-
return SearchResolver.resolve({}).then(res => {
31-
console.log(res); // eslint-disable-line
32-
});
33-
});
34-
});
35-
3626
describe('helper methods', () => {
3727
it('toDottedList()', () => {
3828
expect(Search.toDottedList({ a: { b: true, c: { e: true } }, d: true })).toEqual([

src/resolvers/search.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ export default function createSearchResolver<TSource, TContext>(
4343
type: opts.elasticType,
4444
});
4545

46-
const argsConfigMap = Object.assign({}, searchFC.args, {
46+
const argsConfigMap = {
47+
...searchFC.args,
4748
body: {
48-
type: searchITC.getType(),
49+
type: searchITC,
4950
},
50-
});
51+
};
5152

5253
delete argsConfigMap.index; // index can not be changed, it hardcoded in searchFC
5354
delete argsConfigMap.type; // type can not be changed, it hardcoded in searchFC
@@ -63,17 +64,16 @@ export default function createSearchResolver<TSource, TContext>(
6364
argsConfigMap.limit = 'Int';
6465
argsConfigMap.skip = 'Int';
6566

66-
const bodyITC = schemaComposer.createInputTC(argsConfigMap.body.type);
67-
argsConfigMap.query = bodyITC.getField('query');
68-
argsConfigMap.aggs = bodyITC.getField('aggs');
69-
argsConfigMap.sort = bodyITC.getField('sort');
70-
argsConfigMap.highlight = bodyITC.getField('highlight');
67+
argsConfigMap.query = searchITC.getField('query');
68+
argsConfigMap.aggs = searchITC.getField('aggs');
69+
argsConfigMap.sort = searchITC.getField('sort');
70+
argsConfigMap.highlight = searchITC.getField('highlight');
7171

7272
const topLevelArgs = ['q', 'query', 'sort', 'limit', 'skip', 'aggs', 'highlight', 'opts'];
7373
argsConfigMap.opts = schemaComposer
7474
.createInputTC({
7575
name: `${sourceTC.getTypeName()}Opts`,
76-
fields: Object.assign({}, argsConfigMap),
76+
fields: { ...argsConfigMap },
7777
})
7878
.removeField(topLevelArgs);
7979
Object.keys(argsConfigMap).forEach(argKey => {

src/utils.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,31 @@ export function prepareCommonOpts<TContext>(
3737
return {
3838
schemaComposer,
3939
getOrCreateOTC: (typeName, cfgOrThunk) => {
40-
return schemaComposer.getOrSet(typeName, () =>
41-
schemaComposer.createObjectTC(isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk)
42-
);
40+
return schemaComposer.getOrSet(typeName, () => {
41+
const tc = schemaComposer.createObjectTC(typeName);
42+
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
43+
tc.setFields(cfg.fields);
44+
tc.setDescription(cfg.description);
45+
return tc;
46+
});
4347
},
4448
getOrCreateITC: (typeName, cfgOrThunk) => {
45-
return schemaComposer.getOrSet(typeName, () =>
46-
schemaComposer.createInputTC(isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk)
47-
);
49+
return schemaComposer.getOrSet(typeName, () => {
50+
const tc = schemaComposer.createInputTC(typeName);
51+
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
52+
tc.setFields(cfg.fields);
53+
tc.setDescription(cfg.description);
54+
return tc;
55+
});
4856
},
4957
getOrCreateETC: (typeName, cfgOrThunk) => {
50-
return schemaComposer.getOrSet(typeName, () =>
51-
schemaComposer.createEnumTC(isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk)
52-
);
58+
return schemaComposer.getOrSet(typeName, () => {
59+
const tc = schemaComposer.createEnumTC(typeName);
60+
const cfg = isFunction(cfgOrThunk) ? (cfgOrThunk: any)() : cfgOrThunk;
61+
tc.setFields(cfg.values);
62+
tc.setDescription(cfg.description);
63+
return tc;
64+
});
5365
},
5466
...opts,
5567
};

0 commit comments

Comments
 (0)