Skip to content

Commit

Permalink
feat: Migrate on graphql-compose 2.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nodkz committed Sep 7, 2017
1 parent fea7737 commit f0ec48b
Show file tree
Hide file tree
Showing 17 changed files with 1,002 additions and 386 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ cache:
notifications:
email: true
node_js:
- "8"
- "7"
- "6"
- "5"
- "4"
before_install: yarn global add greenkeeper-lockfile@1
before_script: greenkeeper-lockfile-update
Expand Down
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,39 @@
},
"homepage": "https://github.com/nodkz/graphql-compose-elasticsearch#readme",
"dependencies": {
"babel-runtime": "^6.25.0",
"babel-runtime": "^6.26.0",
"dox": "^0.9.0"
},
"peerDependencies": {
"elasticsearch": ">=12.0.0 || >=13.0.0",
"graphql-compose": ">=1.20.4 || >=2.0.0"
"graphql-compose": ">=2.9.0"
},
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-cli": "^6.26.0",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.3",
"babel-jest": "^21.0.0",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.0",
"cz-conventional-changelog": "^2.0.0",
"elasticsearch": "^13.2.0",
"eslint": "^4.4.1",
"eslint-config-airbnb-base": "^11.3.1",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-flowtype": "^2.35.0",
"elasticsearch": "^13.3.1",
"eslint": "^4.6.1",
"eslint-config-airbnb-base": "^12.0.0",
"eslint-config-prettier": "^2.4.0",
"eslint-plugin-flowtype": "^2.35.1",
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-prettier": "^2.1.2",
"eslint-plugin-prettier": "^2.2.0",
"express": "^4.15.4",
"express-graphql": "^0.6.7",
"flow-bin": "^0.52.0",
"graphql": "^0.10.5",
"graphql-compose": "^2.2.0",
"jest": "^20.0.4",
"npm-run-all": "^4.0.1",
"prettier": "^1.5.3",
"express-graphql": "^0.6.11",
"flow-bin": "^0.54.1",
"graphql": "^0.11.3",
"graphql-compose": "^2.9.0",
"jest": "^21.0.1",
"npm-run-all": "^4.1.1",
"prettier": "^1.6.1",
"rimraf": "^2.5.4",
"semantic-release": "^6.3.2"
"semantic-release": "^7.0.2"
},
"config": {
"commitizen": {
Expand Down
24 changes: 11 additions & 13 deletions src/ElasticApiParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
import dox from 'dox';
import fs from 'fs';
import path from 'path';
import { GraphQLJSON, upperFirst, TypeComposer, graphql } from 'graphql-compose';
import { reorderKeys } from './utils';

import type {
GraphQLArgumentConfig,
GraphQLFieldConfig,
GraphQLFieldConfigMap,
GraphQLFieldConfigArgumentMap,
GraphQLInputType,
} from 'graphql-compose/lib/definition'; // eslint-disable-line

const {
import { GraphQLJSON, upperFirst, TypeComposer } from 'graphql-compose';
import {
GraphQLString,
GraphQLFloat,
GraphQLBoolean,
GraphQLObjectType,
GraphQLEnumType,
GraphQLNonNull,
} = graphql;
} from 'graphql-compose/lib/graphql';
import type {
GraphQLArgumentConfig,
GraphQLFieldConfig,
GraphQLFieldConfigMap,
GraphQLFieldConfigArgumentMap,
GraphQLInputType,
} from 'graphql-compose/lib/graphql';
import { reorderKeys } from './utils';

export type ElasticParamConfigT = {
type: string,
Expand Down
13 changes: 6 additions & 7 deletions src/__tests__/ElasticApiParser-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
// import fs from 'fs';
import dox from 'dox';
import path from 'path';
import { GraphQLJSON, TypeComposer, graphql } from 'graphql-compose';
import ElasticApiParser from '../ElasticApiParser';

const {
import { GraphQLJSON, TypeComposer } from 'graphql-compose';
import {
GraphQLString,
GraphQLFloat,
GraphQLBoolean,
GraphQLObjectType,
GraphQLEnumType,
GraphQLNonNull,
} = graphql;
} from 'graphql-compose/lib/graphql';
import ElasticApiParser from '../ElasticApiParser';

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

Expand Down Expand Up @@ -44,7 +43,7 @@ describe('ElasticApiParser', () => {

describe('findApiVersionFile()', () => {
it('should find proper version in elasticsearch 12.x', () => {
const loadApiListFile = ElasticApiParser.loadApiListFile;
const { loadApiListFile } = ElasticApiParser;
// $FlowFixMe
ElasticApiParser.loadApiListFile = () =>
`
Expand Down Expand Up @@ -82,7 +81,7 @@ describe('ElasticApiParser', () => {
});

it('should find proper version in elasticsearch 13.x', () => {
const loadApiListFile = ElasticApiParser.loadApiListFile;
const { loadApiListFile } = ElasticApiParser;
// $FlowFixMe
ElasticApiParser.loadApiListFile = () =>
`
Expand Down
20 changes: 10 additions & 10 deletions src/__tests__/mappingConverter-test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/* @flow */

import { TypeComposer, GraphQLJSON, graphql, GQC } from 'graphql-compose';
import { TypeComposer, GraphQLJSON, GQC } from 'graphql-compose';
import {
convertToSourceTC,
propertyToSourceGraphQLType,
inputPropertiesToGraphQLTypes,
getSubFields,
} from '../mappingConverter';

const {
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean,
GraphQLList,
GraphQLObjectType,
} = graphql;
graphql,
} from 'graphql-compose/lib/graphql';
import {
convertToSourceTC,
propertyToSourceGraphQLType,
inputPropertiesToGraphQLTypes,
getSubFields,
} from '../mappingConverter';

const mapping = {
properties: {
Expand Down Expand Up @@ -261,7 +261,7 @@ describe('PropertiesConverter', () => {

it('should use Elastic field names from source', async () => {
GQC.rootQuery().addFields({ userES: tc9 });
const result = await graphql.graphql(
const result = await graphql(
GQC.buildSchema(),
`query { userES { _id, lastName, email, _passwordHash } }`,
{
Expand Down
11 changes: 6 additions & 5 deletions src/elasticApiFieldConfig.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* @flow */
/* eslint-disable no-param-reassign */

import { graphql } from 'graphql-compose';
import type { GraphQLFieldConfig } from 'graphql-compose/lib/definition';
import {
GraphQLObjectType,
GraphQLString,
type GraphQLFieldConfig,
} from 'graphql-compose/lib/graphql';
import elasticsearch from 'elasticsearch';
import ElasticApiParser from './ElasticApiParser';

const { GraphQLObjectType, GraphQLString } = graphql;

const DEFAULT_ELASTIC_API_VERSION = '_default';

export function elasticApiFieldConfig(esClientOrOpts: Object): GraphQLFieldConfig<*, *> {
Expand Down Expand Up @@ -47,7 +48,7 @@ function contextElasticClient(elasticConfig: Object): GraphQLFieldConfig<*, *> {
if (!elasticConfig.apiVersion) {
elasticConfig.apiVersion = DEFAULT_ELASTIC_API_VERSION;
}
const apiVersion = elasticConfig.apiVersion;
const { apiVersion } = elasticConfig;
const prefix = `ElasticAPI${apiVersion.replace('.', '')}`;

const apiParser = new ElasticApiParser({
Expand Down
10 changes: 7 additions & 3 deletions src/elasticDSL/Aggs/__tests__/Aggs-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* @flow */

import { TypeMapper, graphql } from 'graphql-compose';
import { TypeMapper } from 'graphql-compose';
import {
printSchema,
GraphQLSchema,
GraphQLObjectType,
GraphQLInt,
} from 'graphql-compose/lib/graphql';
import { getAggsITC, prepareAggsInResolve, convertAggsBlocks, convertAggsRules } from '../Aggs';

const { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } = graphql;

describe('AGGS args converter', () => {
it('Aggs DSL', () => {
const schema = new GraphQLSchema({
Expand Down
7 changes: 3 additions & 4 deletions src/elasticDSL/Commons/FieldNames.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* @flow */
/* eslint-disable no-param-reassign */

import { upperFirst, graphql } from 'graphql-compose';
import { upperFirst } from 'graphql-compose';
import { GraphQLEnumType } from 'graphql-compose/lib/graphql';
import type {
GraphQLEnumValueConfigMap,
GraphQLInputFieldConfigMap,
} from 'graphql-compose/lib/definition';
} from 'graphql-compose/lib/graphql';
import { getTypeName, getOrSetType, desc } from '../../utils';

const { GraphQLEnumType } = graphql;

export type ElasticDataType = string;

export function getStringFields(opts: mixed) {
Expand Down
5 changes: 2 additions & 3 deletions src/elasticDSL/Commons/Geo.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/* @flow */
/* eslint-disable no-unused-vars */

import { InputTypeComposer, graphql } from 'graphql-compose';
import { InputTypeComposer } from 'graphql-compose';
import { GraphQLScalarType, Kind } from 'graphql-compose/lib/graphql';
import { getTypeName, getOrSetType, desc } from '../../utils';

const { GraphQLScalarType, Kind } = graphql;

export const ElasticGeoPointType = new GraphQLScalarType({
name: 'ElasticGeoPointType',
description: desc(
Expand Down
4 changes: 1 addition & 3 deletions src/elasticDSL/Commons/__tests__/FieldNames-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* @flow */

import { graphql } from 'graphql-compose';
import { GraphQLEnumType } from 'graphql-compose/lib/graphql';
import * as FieldNames from '../FieldNames';

const { GraphQLEnumType } = graphql;

const fieldMap = {
_all: {
text1: {},
Expand Down
10 changes: 7 additions & 3 deletions src/elasticDSL/Query/__tests__/Query-test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
/* @flow */

import { TypeMapper, graphql } from 'graphql-compose';
import { TypeMapper } from 'graphql-compose';
import {
printSchema,
GraphQLSchema,
GraphQLObjectType,
GraphQLInt,
} from 'graphql-compose/lib/graphql';
import { getQueryITC } from '../Query';

const { printSchema, GraphQLSchema, GraphQLObjectType, GraphQLInt } = graphql;

describe('AGGS args converter', () => {
it('Query DSL', () => {
const schema = new GraphQLSchema({
Expand Down
4 changes: 1 addition & 3 deletions src/elasticDSL/Sort.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* @flow */

import { graphql } from 'graphql-compose';
import { GraphQLEnumType } from 'graphql-compose/lib/graphql';
import { getTypeName, getOrSetType } from '../utils';
import { getFieldNamesByElasticType } from './Commons/FieldNames';

const { GraphQLEnumType } = graphql;

const sortableTypes = [
'byte',
'short',
Expand Down
12 changes: 5 additions & 7 deletions src/mappingConverter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ import {
GraphQLBuffer,
upperFirst,
isObject,
graphql,
} from 'graphql-compose';
import type { GraphQLScalarType, GraphQLInputType } from 'graphql-compose/lib/definition';

import { ElasticGeoPointType } from './elasticDSL/Commons/Geo';

const {
import {
GraphQLString,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean,
GraphQLList,
GraphQLObjectType,
} = graphql;
} from 'graphql-compose/lib/graphql';
import type { GraphQLScalarType, GraphQLInputType } from 'graphql-compose/lib/graphql';

import { ElasticGeoPointType } from './elasticDSL/Commons/Geo';

export type ElasticMappingT = {
properties: ElasticMappingPropertiesT,
Expand Down
2 changes: 1 addition & 1 deletion src/resolvers/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable no-param-reassign */

import { Resolver, TypeComposer, InputTypeComposer, isObject } from 'graphql-compose';
import type { ResolveParams, ProjectionType } from 'graphql-compose/lib/definition';
import type { ResolveParams, ProjectionType } from 'graphql-compose';
import type { FieldsMapByElasticType } from '../mappingConverter';
import ElasticApiParser from '../ElasticApiParser';
import { getSearchBodyITC, prepareBodyInResolve } from '../elasticDSL/SearchBody';
Expand Down
4 changes: 2 additions & 2 deletions src/resolvers/searchConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ function getPageInfoTC(opts: mixed = {}): TypeComposer {
}

export function base64(i: string): string {
return new Buffer(i, 'ascii').toString('base64');
return Buffer.from(i, 'ascii').toString('base64');
}

export function unbase64(i: string): string {
return new Buffer(i, 'base64').toString('ascii');
return Buffer.from(i, 'base64').toString('ascii');
}

export function cursorToData(cursor: string): mixed {
Expand Down
2 changes: 1 addition & 1 deletion src/typeStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { isFunction } from 'graphql-compose';

class TypeStorage extends Map {
class TypeStorage extends Map<string, any> {
// this `create` hack due TypeError:
// Constructor Map requires 'new' at TypeStorage.Map (native)
static create(array?: any[]): TypeStorage {
Expand Down
Loading

0 comments on commit f0ec48b

Please sign in to comment.