Skip to content

Commit 6d35e47

Browse files
committed
fix: Remove graphql from peer-dependencies. Using it from graphql re-export
1 parent d2299a4 commit 6d35e47

13 files changed

+90
-145
lines changed

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"dox": "^0.9.0"
2626
},
2727
"peerDependencies": {
28-
"graphql": "^0.9.1",
2928
"elasticsearch": ">=12.0.0 || >=13.0.0",
3029
"graphql-compose": ">=1.19.2"
3130
},
@@ -81,7 +80,7 @@
8180
"docker": "npm run docker:v5",
8281
"docker:v2": "node ./scripts/docker/start 2 & wait",
8382
"docker:v5": "node ./scripts/docker/start 5 & wait",
84-
"link": "yarn build && yarn link graphql && yarn link graphql-compose && yarn link",
85-
"unlink": "yarn unlink graphql && yarn unlink graphql-compose && yarn add graphql graphql-compose"
83+
"link": "yarn build && yarn link graphql-compose && yarn link",
84+
"unlink": "yarn unlink graphql-compose && yarn add graphql-compose"
8685
}
8786
}

src/ElasticApiParser.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@
44
import dox from 'dox';
55
import fs from 'fs';
66
import path from 'path';
7-
import {
8-
GraphQLString,
9-
GraphQLFloat,
10-
GraphQLBoolean,
11-
GraphQLObjectType,
12-
GraphQLEnumType,
13-
GraphQLNonNull,
14-
} from 'graphql';
15-
import { GraphQLJSON, upperFirst, TypeComposer } from 'graphql-compose';
7+
import { GraphQLJSON, upperFirst, TypeComposer, graphql } from 'graphql-compose';
168
import { reorderKeys } from './utils';
179

1810
import type {
@@ -24,6 +16,15 @@ import type {
2416
GraphQLInputType,
2517
} from "graphql/type/definition"; // eslint-disable-line
2618

19+
const {
20+
GraphQLString,
21+
GraphQLFloat,
22+
GraphQLBoolean,
23+
GraphQLObjectType,
24+
GraphQLEnumType,
25+
GraphQLNonNull,
26+
} = graphql;
27+
2728
export type ElasticParamConfigT = {
2829
type: string,
2930
name?: string,

src/__tests__/ElasticApiParser-test.js

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
// import fs from 'fs';
44
import dox from 'dox';
55
import path from 'path';
6-
import {
6+
import { GraphQLJSON, TypeComposer, graphql } from 'graphql-compose';
7+
import ElasticApiParser from '../ElasticApiParser';
8+
9+
const {
710
GraphQLString,
811
GraphQLFloat,
912
GraphQLBoolean,
1013
GraphQLObjectType,
1114
GraphQLEnumType,
1215
GraphQLNonNull,
13-
} from 'graphql';
14-
import { GraphQLJSON, TypeComposer } from 'graphql-compose';
15-
16-
import ElasticApiParser from '../ElasticApiParser';
16+
} = graphql;
1717

1818
const apiPartialPath = path.resolve(__dirname, '../__mocks__/apiPartial.js');
1919

@@ -29,9 +29,7 @@ describe('ElasticApiParser', () => {
2929
describe('static methods', () => {
3030
describe('loadApiFile()', () => {
3131
it('should load file with data', () => {
32-
expect(ElasticApiParser.loadApiFile(apiPartialPath)).toContain(
33-
'api.search = ca({'
34-
);
32+
expect(ElasticApiParser.loadApiFile(apiPartialPath)).toContain('api.search = ca({');
3533
});
3634

3735
it('should replace invalid markup', () => {
@@ -126,9 +124,7 @@ describe('ElasticApiParser', () => {
126124

127125
describe('cleanupDescription()', () => {
128126
it('should remove `- ` from start and trim', () => {
129-
expect(ElasticApiParser.cleanupDescription('- Some param ')).toEqual(
130-
'Some param'
131-
);
127+
expect(ElasticApiParser.cleanupDescription('- Some param ')).toEqual('Some param');
132128
});
133129
});
134130

@@ -148,11 +144,9 @@ describe('ElasticApiParser', () => {
148144
});
149145

150146
it("should api['delete'] convert to api.delete", () => {
151-
expect(
152-
ElasticApiParser.cleanUpSource(
153-
`api.indices.prototype['delete'] = ca({`
154-
)
155-
).toEqual(`api.indices.prototype.delete = ca({`);
147+
expect(ElasticApiParser.cleanUpSource(`api.indices.prototype['delete'] = ca({`)).toEqual(
148+
`api.indices.prototype.delete = ca({`
149+
);
156150
});
157151
});
158152

@@ -172,9 +166,7 @@ describe('ElasticApiParser', () => {
172166
`
173167
);
174168
const doxAST = dox.parseComments(source, { raw: true });
175-
expect(
176-
ElasticApiParser.parseParamsDescription(doxAST[0])
177-
).toMatchObject({
169+
expect(ElasticApiParser.parseParamsDescription(doxAST[0])).toMatchObject({
178170
analyzeWildcard: 'Specify whether wildcard and prefix queries should be analyzed (default: false)',
179171
analyzer: 'The analyzer to use for the query string',
180172
from: 'Starting offset (default: 0)',
@@ -258,15 +250,14 @@ describe('ElasticApiParser', () => {
258250

259251
describe('getMethodName()', () => {
260252
it('should return string', () => {
261-
expect(ElasticApiParser.getMethodName('api.updateByQuery')).toEqual(
262-
'updateByQuery'
263-
);
253+
expect(ElasticApiParser.getMethodName('api.updateByQuery')).toEqual('updateByQuery');
264254
});
265255

266256
it('should return array of string', () => {
267-
expect(
268-
ElasticApiParser.getMethodName('api.cat.prototype.allocation')
269-
).toEqual(['cat', 'allocation']);
257+
expect(ElasticApiParser.getMethodName('api.cat.prototype.allocation')).toEqual([
258+
'cat',
259+
'allocation',
260+
]);
270261
});
271262
});
272263

@@ -283,54 +274,35 @@ describe('ElasticApiParser', () => {
283274

284275
it('should return ElasticParsedSourceT', () => {
285276
expect(
286-
ElasticApiParser.parseSource(
287-
ElasticApiParser.loadApiFile(apiPartialPath)
288-
)
277+
ElasticApiParser.parseSource(ElasticApiParser.loadApiFile(apiPartialPath))
289278
).toMatchSnapshot();
290279
});
291280
});
292281
});
293282

294283
describe('paramTypeToGraphQL()', () => {
295284
it('should convert scalar types', () => {
296-
expect(parser.paramTypeToGraphQL({ type: 'string' }, 'f1')).toEqual(
297-
GraphQLString
298-
);
299-
expect(parser.paramTypeToGraphQL({ type: 'boolean' }, 'f1')).toEqual(
300-
GraphQLBoolean
301-
);
302-
expect(parser.paramTypeToGraphQL({ type: 'number' }, 'f1')).toEqual(
303-
GraphQLFloat
304-
);
305-
expect(parser.paramTypeToGraphQL({ type: 'time' }, 'f1')).toEqual(
306-
GraphQLString
307-
);
285+
expect(parser.paramTypeToGraphQL({ type: 'string' }, 'f1')).toEqual(GraphQLString);
286+
expect(parser.paramTypeToGraphQL({ type: 'boolean' }, 'f1')).toEqual(GraphQLBoolean);
287+
expect(parser.paramTypeToGraphQL({ type: 'number' }, 'f1')).toEqual(GraphQLFloat);
288+
expect(parser.paramTypeToGraphQL({ type: 'time' }, 'f1')).toEqual(GraphQLString);
308289
});
309290

310291
it('should `list` convert to GraphQLJSON', () => {
311-
expect(parser.paramTypeToGraphQL({ type: 'list' }, 'f1')).toEqual(
312-
GraphQLJSON
313-
);
292+
expect(parser.paramTypeToGraphQL({ type: 'list' }, 'f1')).toEqual(GraphQLJSON);
314293
});
315294

316295
it('should `enum` convert to GraphQLString (if empty options)', () => {
317-
expect(parser.paramTypeToGraphQL({ type: 'enum' }, 'f1')).toEqual(
318-
GraphQLString
319-
);
296+
expect(parser.paramTypeToGraphQL({ type: 'enum' }, 'f1')).toEqual(GraphQLString);
320297
});
321298

322299
it('should `enum` convert to GraphQLEnumType', () => {
323-
const type = parser.paramTypeToGraphQL(
324-
{ type: 'enum', options: ['AND', 'OR'] },
325-
'f1'
326-
);
300+
const type = parser.paramTypeToGraphQL({ type: 'enum', options: ['AND', 'OR'] }, 'f1');
327301
expect(type).toBeInstanceOf(GraphQLEnumType);
328302
});
329303

330304
it('should as fallback type return GraphQLJSON', () => {
331-
expect(parser.paramTypeToGraphQL({ type: 'crazy' }, 'f1')).toEqual(
332-
GraphQLJSON
333-
);
305+
expect(parser.paramTypeToGraphQL({ type: 'crazy' }, 'f1')).toEqual(GraphQLJSON);
334306
});
335307
});
336308

@@ -405,9 +377,7 @@ describe('ElasticApiParser', () => {
405377

406378
describe('paramToGraphQLArgConfig()', () => {
407379
it('should return object with type property', () => {
408-
expect(
409-
parser.paramToGraphQLArgConfig({ type: 'string' }, 'f1')
410-
).toMatchObject({
380+
expect(parser.paramToGraphQLArgConfig({ type: 'string' }, 'f1')).toMatchObject({
411381
type: GraphQLString,
412382
});
413383
});
@@ -422,9 +392,7 @@ describe('ElasticApiParser', () => {
422392
});
423393

424394
it('should set defaultValue="json" for `format` argument', () => {
425-
expect(
426-
parser.paramToGraphQLArgConfig({ type: 'string' }, 'format')
427-
).toMatchObject({
395+
expect(parser.paramToGraphQLArgConfig({ type: 'string' }, 'format')).toMatchObject({
428396
type: GraphQLString,
429397
defaultValue: 'json',
430398
});
@@ -558,9 +526,7 @@ describe('ElasticApiParser', () => {
558526
elasticApiFilePath: apiPartialPath,
559527
});
560528
expect(partialApiParser.generateFieldConfig('search')).toMatchSnapshot();
561-
expect(
562-
partialApiParser.generateFieldConfig('cat.allocation')
563-
).toMatchSnapshot();
529+
expect(partialApiParser.generateFieldConfig('cat.allocation')).toMatchSnapshot();
564530
});
565531
});
566532

src/__tests__/mappingConverter-test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
/* @flow */
22

3-
import { TypeComposer, GraphQLJSON } from 'graphql-compose';
4-
3+
import { TypeComposer, GraphQLJSON, graphql } from 'graphql-compose';
54
import {
5+
convertToSourceTC,
6+
propertyToSourceGraphQLType,
7+
inputPropertiesToGraphQLTypes,
8+
getSubFields,
9+
} from '../mappingConverter';
10+
11+
const {
612
GraphQLString,
713
GraphQLInt,
814
GraphQLFloat,
915
GraphQLBoolean,
1016
GraphQLList,
1117
GraphQLObjectType,
12-
} from 'graphql';
13-
14-
import {
15-
convertToSourceTC,
16-
propertyToSourceGraphQLType,
17-
inputPropertiesToGraphQLTypes,
18-
getSubFields,
19-
} from '../mappingConverter';
18+
} = graphql;
2019

2120
const mapping = {
2221
properties: {

src/elasticApiFieldConfig.js

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

4-
import { GraphQLObjectType, GraphQLString } from 'graphql';
4+
import { graphql } from 'graphql-compose';
55
import type { GraphQLFieldConfig } from 'graphql/type/definition';
66
import elasticsearch from 'elasticsearch';
77
import ElasticApiParser from './ElasticApiParser';
88

9+
const { GraphQLObjectType, GraphQLString } = graphql;
10+
911
const DEFAULT_ELASTIC_API_VERSION = '_default';
1012

11-
export function elasticApiFieldConfig(
12-
esClientOrOpts: Object
13-
): GraphQLFieldConfig<*, *> {
13+
export function elasticApiFieldConfig(esClientOrOpts: Object): GraphQLFieldConfig<*, *> {
1414
if (!esClientOrOpts || typeof esClientOrOpts !== 'object') {
1515
throw new Error(
1616
'You should provide ElasticClient instance or ElasticClientConfig in first argument.'
@@ -24,11 +24,8 @@ export function elasticApiFieldConfig(
2424
}
2525
}
2626

27-
function instanceElasticClient(
28-
elasticClient: Object
29-
): GraphQLFieldConfig<*, *> {
30-
const apiVersion = elasticClient.transport._config.apiVersion ||
31-
DEFAULT_ELASTIC_API_VERSION;
27+
function instanceElasticClient(elasticClient: Object): GraphQLFieldConfig<*, *> {
28+
const apiVersion = elasticClient.transport._config.apiVersion || DEFAULT_ELASTIC_API_VERSION;
3229
const prefix = `ElasticAPI${apiVersion.replace('.', '')}`;
3330

3431
const apiParser = new ElasticApiParser({
@@ -90,12 +87,7 @@ function isElasticClient(obj) {
9087
return true;
9188
}
9289

93-
if (
94-
obj &&
95-
obj.transport &&
96-
obj.transport._config &&
97-
obj.transport._config.__reused
98-
) {
90+
if (obj && obj.transport && obj.transport._config && obj.transport._config.__reused) {
9991
return true;
10092
}
10193

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* @flow */
22

3-
import { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } from 'graphql';
4-
import { TypeMapper } from 'graphql-compose';
3+
import { TypeMapper, graphql } from 'graphql-compose';
54
import { getAggsITC, prepareAggsInResolve, convertAggsBlocks, convertAggsRules } from '../Aggs';
65

6+
const { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } = graphql;
7+
78
describe('AGGS args converter', () => {
89
it('Aggs DSL', () => {
910
const schema = new GraphQLSchema({

src/elasticDSL/Commons/FieldNames.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
/* @flow */
22
/* eslint-disable no-param-reassign */
33

4-
import { upperFirst } from 'graphql-compose';
5-
import { GraphQLEnumType } from 'graphql';
4+
import { upperFirst, graphql } from 'graphql-compose';
65
import type {
76
GraphQLEnumValueConfigMap,
87
GraphQLInputFieldConfigMap,
98
} from 'graphql/type/definition';
109
import { getTypeName, getOrSetType, desc } from '../../utils';
1110

11+
const { GraphQLEnumType } = graphql;
12+
1213
export type ElasticDataType = string;
1314

1415
export function getStringFields(opts: mixed) {

src/elasticDSL/Commons/Geo.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/* @flow */
22
/* eslint-disable no-unused-vars */
33

4-
import { GraphQLScalarType } from 'graphql';
5-
import { Kind } from 'graphql/language';
6-
import { InputTypeComposer } from 'graphql-compose';
4+
import { InputTypeComposer, graphql } from 'graphql-compose';
75
import { getTypeName, getOrSetType, desc } from '../../utils';
86

7+
const { GraphQLScalarType, Kind } = graphql;
8+
99
export const ElasticGeoPointType = new GraphQLScalarType({
1010
name: 'ElasticGeoPointType',
1111
description: desc(

src/elasticDSL/Commons/__tests__/FieldNames-test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* @flow */
22

3-
import { GraphQLEnumType } from 'graphql';
3+
import { graphql } from 'graphql-compose';
44
import * as FieldNames from '../FieldNames';
55

6+
const { GraphQLEnumType } = graphql;
7+
68
const fieldMap = {
79
_all: {
810
text1: {},

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/* @flow */
22

3-
import { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } from 'graphql';
4-
import { TypeMapper } from 'graphql-compose';
3+
import { TypeMapper, graphql } from 'graphql-compose';
54
import { getQueryITC } from '../Query';
65

6+
const { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } = graphql;
7+
78
describe('AGGS args converter', () => {
89
it('Query DSL', () => {
910
const schema = new GraphQLSchema({

0 commit comments

Comments
 (0)